Boost logo

Boost :

From: Powell, Gary (powellg_at_[hidden])
Date: 2003-06-10 13:39:58


This could be further optimized by adding the rules

   T operator*( T val, one_t ){ return( val ); }
   T operator*( T val, minus_one_t ){ return( -val ); }
   T operator+( T val, zero_t ){ return( val ); }

-----

Of course you could do the others as well.

   T operator/( T val, one_t ){ return( val ); }
   T operator/( T val, minus_one_t ){ return( -val ); }
   T operator-( T val, zero_t ){ return( val ); }
   zero_t operator*( T val, zero_t ){ return( zero_t ); }
   T operator/( T val, zero_t ) { throw divide_by_zero; }

The nice thing is that if you are copying a formula into some code you don't have to do the optimizations by hand.

  -Gary-


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