Boost logo

Boost :

From: Erdei, András (ccg_at_[hidden])
Date: 2000-10-10 15:33:34


[i've been only reading this group for two days,
so this might be silly -- forgive/flame me]

I've followed the link in a recent post

> http://www.boost.org/libs/utility/operators.htm
>
and found operator++ implemented as

// incrementable and decrementable contributed by Jeremy Siek

  friend T operator++(T& x, int)
  {
    incrementable_type tmp(x);
    ++x;
    return tmp;
  }

a more efficient implemetation can be (stripped off
the template stuff):

  class proxy
    {
    public :
      operator T const & ( void ) { return real ; }
      ~proxy() { if ( ! std::uncaught_exception() ) ++real ; } ;
    private :
      friend proxy operator++( T & , int ) ;
      proxy( T & real ) : real( real ) {} ;
      T & real ;
    } ;

  proxy
operator++( T & t , int )
  {
    return proxy( t ) ;
  }

I've tried to search eGroups to see if this was already
discussed and for some reason rejected, but failed to
find it if there was a discussion on this.

Has this implementation been considered?

  TIA
  Andras


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