Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2001-08-25 08:22:19


> > 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

Note that this technique does not follow the traditional application
of 'traits' -- that's why 'traits' was in quotes. Traditional traits
only provide properties of a type; these 'traits' add 'type
methods'. Similar techniques have been done before: in the Standard,
char_traits provides both properties and methods.

        -Steve


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