Boost logo

Boost :

From: helmut.zeisel_at_[hidden]
Date: 2001-08-25 09:22:24


--- In boost_at_y..., scleary_at_j... wrote:
> > > int_traits::is_zero(x) -- returns true if x == 0
> > > int_traits::is_positive(x) -- returns true if x >= 0
> > > int_traits::is_odd(x) -- returns true if (x % 2) == 1
> >
> > I do net yet understand completely what you mean.
>
> Just something simple, like:
>
> namespace int_traits {
> template <typename T>
> bool is_zero(const T & x) { return (x == 0); }
> bool is_zero(const unlimited & x) { return x.is_zero(); }
> // same for others
> }
>
> then usage is:
>
> unlimited i;
> int j;
> int_traits::is_zero(i); // equivalent to i.is_zero()
> int_traits::is_zero(j); // equivalent to j == 0
>

OK, usage is in the normal case the same as in my version,
there is just the question which namespace to use.

For a specialiced version for a user defined type,
your version would require function overloading,
my verions would require template (traits) class specialization.

In the current language definition, however,
it is not allowed to overload functions in std namespace,
so it is not clear how this version could ever become
standard,

see e.g.

http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2001/n1296.htm

for details.

This is the reason why my version is more complicated
internally, but AFAIK,
there is no principal problem that could exclude it from
becoming stanard.

From the outside, fortunately, both versions
are almost equivalent.

Helmut


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