|
Boost : |
From: Daryle Walker (darylew_at_[hidden])
Date: 2005-07-17 00:32:55
I'm writing a class template where the template parameter is a type that
should represent real numbers. It started choking when using
boost::rational when I needed Boolean conversion, e.g.
template < typename T >
void my_class<T>::my_func()
{
if ( this->s_ )
//...
}
Looking at boost::rational, I noticed that it does NOT have a Boolean
conversion operator (i.e. an unspecified numeric/pointer type). Before
anyone says that's proper, realize that boost::rational DOES have "operator
not()" defined! This is a surprise to the typical C++ programmer. Either
both should be defined, or neither. I think that boost::rational should add
a Boolean conversion. (It's a quick fix, and it is critical, so it should
be done for this release.)
Incidentally, maybe we should define another helper template for
<boost/operators.hpp>. If a type supports default construction and equality
via "operator ==()", then a Boolean conversion and "operator not()" will be
added. (It's up to the user to make sure the type is numeric and the
default value is equivalent to zero.)
-- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk