Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2002-06-11 04:04:29

Richard Peters wrote:
> Then you can replace the postfix increment operator with
> number operator++(int)
> { return postfix_increment(*this); }
> The only thing is that I do not clearly see if there's still the copying
> advantage...
> Is this useful for the utility library?

I think it depends on the compiler. Compared to the canonical

number operator++( int )
{ number tmp( *this ); ++( *this ); return tmp; }

you may get a performance advantage for compiler without the "named
return value optimization". But this is basically a problem of the
compiler and I would like to see some evidence that there are compilers
that do benefit from this. For compilers without good optimizers, it may
even lead to slower code as it is more complicated. A possible solution
might be a #define:


template< class T > struct postfix_incrementer : public T
   postfix_incrementer( T& rhs ) : T( rhs )

template< class T > T postfix_increment( T& rhs )
   return postfix_incrementer< T >( rhs );

#define BOOST_RETURN_POSTFIX_INCREMENT( T ) return postfix_increment(
*this )


#define BOOST_RETURN_POSTFIX_INCREMENT( T ) T tmp( *this ); ++( *this );
return tmp


Now implement operator++( int ) like this:

number operator++( int )

All we need to find out is: which compilers should

Regards, Daniel

Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web:

Boost list run by bdawes at, gregod at, cpdaniel at, john at