Boost logo

Boost :

From: Matt Austern (austern_at_[hidden])
Date: 2001-01-12 13:41:20

Jeremy Siek wrote:

> As for the one() and zero() functions, you'll see below I didn't use a
> traits function, but instead used a free function that takes an argument
> of the number type (the argument isn't really used, it just carries the
> type).

I'd be cautious about that, for two reasons.

First, in some cases you're not interested in "one" and "zero", but in
whether something is an identity element. You're using "zero" in
AbelianGroupConcept, but that's not very reasonable. The set of nonzero
real numbers under multiplication is a perfectly good abelian group, but
the identity element is 1. Finding an identity element for a group
requires a number type and an operation type. (Names like "one" and
"zero" make more sense when you're talking about rings than when you're
talking about groups.)

Second, as a technical issue: in one of the SGI extensions, we did
something like this for the power() function. We used a free function
called identity_element, which took as an argument the multiplication
function. This turned out to cause endless pain when we were trying
to use it with nested types, nested multiplication functions, and so
on. When Hans was trying to use this for rope "exponentiation", he
had to worry about some of the more obscure corners of overload resolution
rules. He never did quite get it to work as he had originally planned.


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