I would like to code a bijection between int
and C++ trivial type such as double
or float
.
The bijection is known at compile time.
I would like to use it like this (caps denotes a macro):
INIT(42,float)
INIT(-17,double)
#include <type_traits>
int main() {
const int a = TYPE_TO_INT(float);
static_assert(a==42);
INT_TO_TYPE(-17) pi;
static_assert(std::is_same<double,decltype(pi)>::value);
return 0;
}