Boost logo

Boost :

From: jsiek_at_[hidden]
Date: 1999-12-03 19:09:03

That solves a different problem than the one I was think of :)
I'll elaborate.

Suppose you're writing a generic algorithm, and need to call one
of the STL operations that takes an initial value, like accumulate.
Right now I would write something like this:

accumulate(start, finish, times<T>(), T(1));

But this only works if there is a conversion from int to T. For a user
defined type it would be lame to add a constructor from int just for
this purpose (and it conflict with other uses for that constructor,
like if T is a vector of some sort). It would be better to do
something like this:

accumulate(start, finish, times<T>(), number_traits<T>::one());

The other important number, of course is zero.

So I was just wondering if someone had already created such a
number_traits class.

I suppose there are other algebraic properties that would also
be nice to have access to.

I just took a quick look in Barton and Nackman... in their algebraic
structure chapter they had "setToOne()" and "setToZero()" function.

Howard Hinnant writes:
> Not sure if this is exactly what you're looking for, but I'm currently
> using this in my work:
> template <typename Size, Size sz>
> struct number
> {
> operator Size() const {return sz;}
> };
> I'm using it as the default argument for a template parameter. The
> client template sometimes needs a type like size_t that can take on
> different values, and other times the client just needs a constant. The
> struct number is good for those times only a constant is needed because
> it is zero-sized.
> You'll have to tell me whether this little animal solves your problem or
> not.
> -Howard
> jsiek_at_[hidden] wrote on 12/3/99 6:45 PM
> >Just wondering if anyone has thought of doing a traits class
> >for getting the appropriate value for zero and one given
> >some number type.
> >
> >Cheers,
> >
> >Jeremy
> >
> >------------------------------------------------------------------------
> >et the most popular downloads on the Web. They¼re new!
> >They¼re hot! Theyíre FREE! Utilities, drivers, games.
> >Itís all here.
> >
> >
> >
> > Home:
> > - Simplifying group communications
> >
> >
> ------------------------------------------------------------------------
> CNET Gamecenter
> Get tips and cheats
> -- Check out your group's private Chat room
> --

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