As before I try to "emule" float template parameters based on its IEEE754 wrinting thanks to reinterpret_cast. I am using MSVC 2005 compiler (it doesn't support c++11).
Here is the code :
#include <iostream>
#ifdef _MSC_VER
typedef unsigned __int32 uint32_t;
#else
# include <stdint.h>
#endif
template <uint32_t T>
union Other
{
static const uint32_t i = T;
static const float x;
};
template <uint32_t T>
const float Other<T>::x = reinterpret_cast<const float&>(Other<T>::i);
union Test
{
static const float x;
static const uint32_t i;
};
const float Test::x = 3.141592f;
const uint32_t Test::i = reinterpret_cast<const uint32_t&>(Test::x);
int main()
{
std::cout << Other<0x40490fdb>::x << std::endl; //works
std::cout << Other<Test::i>::x << std::endl; //doesn't compile
return 0;
}
As you can see I can't get ieee754 writing of a float at compile time. Does it compiles with another compiler ? If not why ? Is it possible to achieve this conversion at compile time without c++11 ?