Boost logo

Boost :

From: Mark Rodgers (mark.rodgers_at_[hidden])
Date: 2001-04-25 14:49:13

From: "Ed Brey" <brey_at_[hidden]>
> Usage would typically be:
> typedef boost::math::constants<float> c;
> a = c::pi() * r * r;

As an aside, wouldn't it be nice if we could have template namespaces? Then
you could write

   using boost::math::constants<float>::pi;
   a = pi() * r * r;

and we also be able to reopen the boost::math::constants<T> namespace to
add more members in other header files if desired.

Anyway, back to the real world. I've been out of things for a while. Was
following option discussed, and if so what is wrong with it?

#include <iostream>

namespace boost { namespace math { namespace constants {
  template<typename T> T pi();

  template<> float pi<float>() {return 3.14F;}
  template<> double pi<double>() {return 3.14;}
  template<> long double pi<long double>() {return 3.14L;}
} } }

using boost::math::constants::pi;
a = pi<float>() * r * r;

In some ways, I do prefer it. The typedef sticks in my craw.


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