I need C ++ - a template that, given the type and object of this type, can make a decision based on whether the type is an integer or not, having access to the actual objects. I tried this
template <typename T, T &N>
struct C {
enum { Value = 0 };
};
template <int &N>
struct C<int, N> {
enum { Value = N };
};
but that will not work. Is there a way to achieve something like this?
Edit
What I was trying to achieve was something like this that would happen at compile time:
if (type is int) {
return IntWrapper<int_value>
else {
return type
}
In fact, you can pass pointers or object references in an instance of a template, for example:
struct X {
static const int Value = 5;
};
template <X *x>
struct C {
static const int Value = (*x).Value;
};
X x;
std::cout << C<&x>::Value << std::endl;
but, apparently, all this means initializing the template by type inference x, and xyou also need to declare it globally. Not to use what I'm trying to do, which, in my opinion, is impossible at the end of compilation.