Fix in pathSource() and pathTarget() (#250)
authorPeter Kovacs <kpeter@inf.elte.hu>
Mon, 12 Oct 2009 13:41:15 +0200
changeset 54841bdb4d6c8c3
parent 543 32fb28fc9d42
child 549 4ffd9b129fa8
child 551 c6acc34f98dc
child 798 f5f260a63a9b
child 856 c05bb175d3ee
Fix in pathSource() and pathTarget() (#250)
and extend the doc.
lemon/path.h
     1.1 --- a/lemon/path.h	Tue Apr 28 18:45:29 2009 +0100
     1.2 +++ b/lemon/path.h	Mon Oct 12 13:41:15 2009 +0200
     1.3 @@ -1015,18 +1015,20 @@
     1.4  
     1.5    /// \brief The source of a path
     1.6    ///
     1.7 -  /// This function returns the source of the given path.
     1.8 +  /// This function returns the source node of the given path.
     1.9 +  /// If the path is empty, then it returns \c INVALID.
    1.10    template <typename Digraph, typename Path>
    1.11    typename Digraph::Node pathSource(const Digraph& digraph, const Path& path) {
    1.12 -    return digraph.source(path.front());
    1.13 +    return path.empty() ? INVALID : digraph.source(path.front());
    1.14    }
    1.15  
    1.16    /// \brief The target of a path
    1.17    ///
    1.18 -  /// This function returns the target of the given path.
    1.19 +  /// This function returns the target node of the given path.
    1.20 +  /// If the path is empty, then it returns \c INVALID.
    1.21    template <typename Digraph, typename Path>
    1.22    typename Digraph::Node pathTarget(const Digraph& digraph, const Path& path) {
    1.23 -    return digraph.target(path.back());
    1.24 +    return path.empty() ? INVALID : digraph.target(path.back());
    1.25    }
    1.26  
    1.27    /// \brief Class which helps to iterate through the nodes of a path