Boost logo

Boost :

Subject: Re: [boost] Numeric constants
From: Joel Falcou (joel.falcou_at_[hidden])
Date: 2009-01-31 05:45:54

John Maddock a écrit :
> Well.... this is one of those "complex" solutions that was suggested
> last time this was discussed that I've been trying to avoid ;-)
I was unable to retrieve the "original" thread about the numeric
consatnt so I can't find the roots of the discussion but I guessed it
was problematic.

> Off the top of my head, the main problems I see are:
> * What is the result of 2 * pi? How about 2 * pi * r where r is a real?
What I did was assigning to each constant a conversion policy. 2*pi is
prolly a double by default, while 2*pi*r is the greatest common real
type between double and type of r.
> * If you mistakenly call a function passing a constant as argument,
> for example foo(2.0, pi), then if foo is a template you will likely
> get an inscutable failure very deep inside foo's body (or worse some
> other function that foo calls).
Yes that's the main problem of this solution I think. In my case, the
consatnts are alwasy used with "constant" aware function so the problem
doesn't appear.
> * In order to avoid ODR violations I presume the constants have to be
> defined in an anonymous namespace? Does this cause code bloat simply
> by #including the constants header?
I don't get how ODR if violated in this case.
> Now I suspect that all of these issues are probably solvable to some
> degree, it's a question of whether it's worth the hassle, and/or
> whether the resulting code is likely to turn into a problem to maintain.
Yes, as said above I *thought* it was discussed somewhere but wasn't
able to retrieve the actual discussion.
So everything perfectly fine now that thigns ahve been cleared out ;)

Joel Falcou - Assistant Professor
PARALL Team - LRI - Universite Paris Sud XI
Tel : (+33)1 69 15 66 35

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