
Andy Little wrote:
"Tobias Schwinger" <tschwinger@neoscientists.org> wrote
Andy Little wrote:
"Tobias Schwinger" <tschwinger@neoscientists.org> wrote
- there is no way to pass constants as a type template argument.
( IOW use a function ..? )
No. A class somehow like this:
template<typename T> struct name;
template<> struct name<TYPE> { operator TYPE() const { return ... }; TYPE operator() () const { return ... }; };
FWIW I had alook at this approach yesterday. see "test.cpp" attached. I think it could be made to work. In unary contexts it requires explicit conversion, but I guess there is no way around that. Of course you need an object.. boost::math::pi pi ; or a temporary.. boost::math::pi() ;. However I guess this means you can use either pi or pi() syntax ... :-)
Is it asked too much to let the user just specify the type ? Every variable declaration requires a type so why make things more complicated for constants ? C++ is a strictly typed language and I really can't see the point in emulating loose typedness for constants (especially since you can "declare" a pi constant by instantiating an object, e.g: "pi<float> PIf;"). Regards, Tobias