Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2001-08-24 14:19:40

> > Having said that, I must also say that I personally think conversion
> > functions are evil; they always allow users to hurt themselves.
Providing a
> > conversion to bool and hiding the other conversions will probably make
> > such as this ambiguous (it will if your "BigInt" has an implicit
> > from int's):
> > BigInt a;
> > int b;
> > a + b; // operator+(a, BigInt(b)) or bool(a) + b ?
> Fortunately this is no problem.
> Thanks to operator.hpp (again)
> I have an explicit overload for operator+(const BigInt&, int)
> and all other related operators.

That would work on a bounded set of types. But how would it react to
__int64? Or __int128 on next year's compilers?


> So the only alternative is b.is_zero().
> Actually I have already such a member function.
> The problem, however, is that you cannot write
> a generic algorithm using b.is_zero() that also works
> for built-in types,
> see boost::gcd in rational.hpp for an example.
> One solution might be to provide
> a template<typename T> boost::is_zero(const T& t)
> which uses traits to actually
> implement as t==0 or t.is_zero() depending on T.
> BTW, for testing my unlimited integer classes
> I wrote already a seminumerical.hpp
> (contained in the big_int archive)
> which contains functions like boost::pow, boost::factorial,
> and boost::binomial,
> this might be a proper place for such a boost::is_zero.
> Would there be some need for seminumerical functions?
> Would this solution be better than
> an implicit conversion to bool for unlimited integer?

I think it's a better solution. I also think there's a place for
numeric/integer traits which would support generic numeric/integer


Boost list run by bdawes at, gregod at, cpdaniel at, john at