On Thu, Feb 21, 2013 at 4:18 PM, Daniel Krügler <daniel.krueg...@gmail.com> wrote: > 2013/2/21 Benjamin De Kosnik <b...@redhat.com>: >> >>> > How about the attached file as a start for <ext/math>. I used the >>> > constexpr approach (instead of function calls) and replicated the >>> > constants that are available in <math.h> in Unix. >> >> then this should really be >> >> ext/cmath >> >>> >>> 1) In this case I miss the corresponding variable definitions, because >>> you violate the ODR, when you have something like the following: >>> >>> #include <iostream> >>> >>> template<class T> >>> void print(const T& t) { std::cout << t; } >>> >>> int main() { >>> print(__math_constants<double>::__pi); >>> } >> >> Not seeing it. > > An implementation is not required to diagnose it. You will notice a > linker error with Clang for example and this is conforming, because > __math_constants<double>::__pi is ODR-used. > >> Say for: >> >> #include <iostream> >> >> // A class for math constants. >> template<typename _RealType> >> struct __math_constants >> { >> // Constant @f$ \pi @f$. >> static constexpr _RealType __pie = >> 3.1415926535897932384626433832795029L; }; >> >> template<class T> >> void print(const T& t) { std::cout << t; } >> >> int main() >> { >> print(__math_constants<double>::__pie); >> return 0; >> } >> >> I'm not getting any definition, even at -O0. >> >> Any chance you could expand on your thinking here Daniel? > > No ;-) > > - Daniel
There will be a proposal for 'constexpr variable template' in the Bristol mailing. It should take care of these issues. -- Gaby