Boost logo

Boost :

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


(Yes, I'm replying to myself as I forgot something. Sorry :)

Daniel Frey wrote:
>
> I think it depends on the compiler. Compared to the canonical
>
> number operator++( int )
> { number tmp( *this ); ++( *this ); return tmp; }

This should of course be:

const number operator++( int ) { ... }

to prevent i++++; to be legal. Maybe we should even change the define to
prevent this kind of problem like this:

> #ifdef BOOST_COMPILER_LIKES_POSTFIX_INCREMENT_OPTIMIZATION
>
> template< class T > struct postfix_incrementer : public T
> {
> postfix_incrementer( T& rhs ) : T( rhs )
> {
> ++rhs;
> }
> };
>
> template< class T > T postfix_increment( T& rhs )
> {
> return postfix_incrementer< T >( rhs );
> }
>

#define BOOST_POSTFIX_INCREMENT( T ) \
const T operator++( int ) \
{ return postfix_increment( *this ); }

>
> #else // BOOST_COMPILER_LIKES_POSTFIX_INCREMENT_OPTIMIZATION
>

#define BOOST_POSTFIX_INCREMENT( T ) \
const T operator++( int ) \
{ T tmp( *this ); ++( *this ); return tmp; }
>
> #endif // BOOST_COMPILER_LIKES_POSTFIX_INCREMENT_OPTIMIZATION
>
> Now implement operator++( int ) like this:
>
> number operator++( int )
> { BOOST_RETURN_POSTFIX_INCREMENT( number ); }

We needn't "implement" it any more, we just "add" it by a single line to
our class:

BOOST_POSTFIX_INCREMENT( number )

and that's it. I also took this approach for other operators, but this
new optimization technique needs to be merged. Iif I find some time,
I'll check it in in a few days...

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: http://www.aixigo.de

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk