# Ticket #250: 250-new-dbf9eee91ed2.patch

File 250-new-dbf9eee91ed2.patch, 2.8 KB (added by Peter Kovacs, 15 months ago)
• ## lemon/path.h

# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1518907472 -3600
#      Sat Feb 17 23:44:32 2018 +0100
# Node ID dbf9eee91ed21dd350637aaac416cc8d930f6101
# Parent  ba6afb21b6fd147e765de15c3b197f40cd608afb
Add operator[] to Path structures (#250)

diff --git a/lemon/path.h b/lemon/path.h
 a return ArcIt(*this, n); } /// \brief The n-th arc. /// /// Gives back the n-th arc. This operator is just an alias for \ref nth(), /// it runs in O(1) time. /// \pre \c n is in the range [0..length() - 1]. const Arc& operator[](int n) const { return nth(n); } /// \brief The first arc of the path const Arc& front() const { return head.empty() ? tail.front() : head.back(); return ArcIt(*this, n); } /// \brief The n-th arc. /// /// Gives back the n-th arc. This operator is just an alias for \ref nth(), /// it runs in O(1) time. /// \pre \c n is in the range [0..length() - 1]. const Arc& operator[](int n) const { return data[n]; } /// \brief The first arc of the path. const Arc& front() const { return data.front(); return ArcIt(*this, n); } /// \brief The n-th arc. /// /// Gives back the n-th arc. This operator is just an alias for \ref nth(), /// it runs in O(1) time. /// \pre \c n is in the range [0..length() - 1]. const Arc& operator[](int n) const { return arcs[n]; } /// \brief The length of the path. int length() const { return len; }
• ## test/path_test.cc

diff --git a/test/path_test.cc b/test/path_test.cc
 a checkBackAndFrontInsertablePath >(); checkBackInsertablePath >(); checkSubscriptOperator >(); checkSubscriptOperator >(); checkSubscriptOperator >(); checkListPathSplitAndSplice(); } check(checkPath(cgr, cp), "Wrong checkPath()"); } template void checkSubscriptOperator() { SimplePath p0; p0.addBack(a1); p0.addBack(a3); p0.addBack(a2); P p = p0; check(!p.empty(), "Wrong empty()"); check(p.length() == 3, "Wrong length"); check(p.front() == a1, "Wrong front()"); check(p.back() == a2, "Wrong back()"); check(p.nth(0) == a1, "Wrong nth()"); check(p.nth(1) == a3, "Wrong nth()"); check(p.nth(2) == a2, "Wrong nth()"); check(p[0] == a1, "Wrong operator[]"); check(p[1] == a3, "Wrong operator[]"); check(p[2] == a2, "Wrong operator[]"); } void checkListPathSplitAndSplice() { // Build a path with spliceFront() and spliceBack()