From: Pete Becker on
Francis Glassborow 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;
>

Because that requires a random access iterator.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: James Lothian on
Francis Glassborow 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;
>
Presumably, T might not be a random-access iterator type.

James

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: peter koch larsen on
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;
>
> > }
>
> > That can be used when the return value of operator++() is needed but
> > not the side effect (notice non reference parameter).

Because T might not support that operator (e.g. T is
std::list::iterator).

/Peter


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Thomas J. Gritzan on
Am 07.04.2010 22:57, schrieb Francis Glassborow:
> 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;

Won't work for example with std::list<>::iterator.

>> }
>>
>> That can be used when the return value of operator++() is needed but
>> not the side effect (notice non reference parameter).
>>
>

--
Thomas

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Herb Sutter on
>> > Is there some standard/boost equivalent to a function like:

>> > template< typename T >
>> > T successor( T r )
>> > {
>> > return( ++r );

While others may be inclined to give boring and pedestrian answers
like "boost::next(r)", I'm just bleary enough from being in all-day
meetings to suggest that the current standard spelling for "successor"
is already "++T"... :-) (Just add "(r)" after each. See?)

I'm not being serious, I like next(r) and type deduction as much as
the next guy.

Herb


---
Herb Sutter (herbsutter.wordpress.com) (www.gotw.ca)

Convener, SC22/WG21 (C++) (www.gotw.ca/iso)
Architect, Visual C++ (www.gotw.ca/microsoft)

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]