Prev: const is an overrated concept that is a source of extra typing and maintenan
Next: performance of map in MSVC 10b2
From: itaj sherman on 7 Apr 2010 01:50 Is there some standard/boost equivalent to a function like: template< typename T > T successor( T r ) { return( ++r ); } That can be used when the return value of operator++() is needed but not the side effect (notice non reference parameter). I always feel the need when using iterators and need to peek the following element, or using reverse iterators template< typename Container > void foo( Container const& r ) { for( Container::reverse_iterator aI( r.rbegin() ); aI != r.rend(); + +aI ) { // use successor(aI).base() or Container::iterator const bI( successor(aI).base() ); // use bI... } } -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Jeff Flinn on 7 Apr 2010 05:58 itaj sherman wrote: > Is there some standard/boost equivalent to a function like: > > template< typename T > > T successor( T r ) > { > return( ++r ); > } > > That can be used when the return value of operator++() is needed but > not the side effect (notice non reference parameter). See boost next/prior at: http://www.boost.org/doc/libs/1_39_0/libs/utility/utility.htm#functions_next_prior Jeff -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Daniel Krügler on 7 Apr 2010 05:58 On 7 Apr., 18:50, itaj sherman <itajsher...(a)gmail.com> wrote: > Is there some standard/boost equivalent to a function like: > > template< typename T > > T successor( T r ) > { > return( ++r ); > } > > That can be used when the return value of operator++() is needed but > not the side effect (notice non reference parameter). > > I always feel the need when using iterators and need to peek the > following element, or using reverse iterators > > template< typename Container > > void foo( Container const& r ) > { > for( Container::reverse_iterator aI( r.rbegin() ); aI != r.rend(); + > +aI ) > { > // use successor(aI).base() or > Container::iterator const bI( successor(aI).base() ); > // use bI... > } > } What you are looking for, is std::next which will be part of the C++0x library. Additionally, it's counterpart std::prev will also be provided. HTH & Greetings from Bremen, Daniel Kr�gler -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Francis Glassborow on 7 Apr 2010 05:57 itaj sherman wrote: > Is there some standard/boost equivalent to a function like: > > template< typename T > > T successor( T r ) > { > return( ++r ); why not return r+1; > } > > That can be used when the return value of operator++() is needed but > not the side effect (notice non reference parameter). > -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Daniel Krügler on 7 Apr 2010 07:52 On 7 Apr., 22:57, Francis Glassborow <francis.glassbo...(a)btinternet.com> wrote: > itaj sherman wrote: > > Is there some standard/boost equivalent to a function like: > > > template< typename T > > > T successor( T r ) > > { > > return( ++r ); > > why not > return r+1; > It looks to me as if the OP intends to potentially support non-random access iterators as well. The indicated general container function template foo would then work for e.g. std::list or std::set as well. Greetings from Bremen, Daniel Kr�gler -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Next
|
Last
Pages: 1 2 3 4 Prev: const is an overrated concept that is a source of extra typing and maintenan Next: performance of map in MSVC 10b2 |