$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Michael Marcin (mmarcin_at_[hidden])
Date: 2006-11-11 13:04:54
Hello,
I have a fixed point math class and I want to enable some optimized operator 
overloads.
for instance:
fixed& fixed::operator /= ( const fixed &rhs );
fixed& fixed::operator /= ( int n );
it seems however to me that what I really want is an overload like:
template< typename T >
fixed& operator /= ( typename 
boost::enable_if<boost::is_integral<T>,T>::type n );
However I can't seem to get that function considered for overload resolution 
instead it goes through the following constructor and calls the /= that 
takes a const fixed &.
template< typename T >
fixed::fixed( T n, typename boost::enable_if< boost::is_integral<T> >::type* 
= 0 );
Speaking of which I don't understand why the following doesn't work in place 
of the previous constructor.
template< typename T >
fixed::fixed( typename boost::enable_if< boost::is_integral<T>,T>::type n );
Finally I'm using this class to replace a lot of hardcoded / macro logic and 
often as an optimization the code uses binary shifts to represent power of 2 
multiply/divides.  Going forward these divides need to work with both fixed 
and floating point types so f >> 1 needs to change to f / 2.  Is it possible 
to create an overload for the / and * operators that determine if the 
operand is an integral constant and is a power of 2 and use a binary shift 
internally?
Thanks,
Michael Marcin