Re: [boost] Postfix Increment Operator
by Daniel Frey other posts by this author
Jun 11 2002 9:54AM messages near this date
Re: [boost] Postfix Increment Operator
|
Re: [boost] Postfix Increment Operator
(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@[...].de, web: http://www.aixigo.de
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
Powell, Gary
=?iso-8859-1?Q?Terje_Sletteb=F8?=
Daniel Frey
Daniel Frey
David Abrahams
Richard Peters
David Abrahams
Lars Gullik =?iso-8859-1?q?Bj=F8nnes?=
Brad King
Brad King
|