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. http://clickhere.egroups.com/click/1610
> >
> >
> >
> >eGroups.com Home: http://www.egroups.com/group/boost/
> >http://www.egroups.com - Simplifying group communications
> >
> >
>
> ------------------------------------------------------------------------
> CNET Gamecenter
> Get tips and cheats
> http://clickhere.egroups.com/click/1862
>
> -- Check out your group's private Chat room
> -- http://www.egroups.com/ChatPage?listName=boost&m=1
>
>
>


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