How can I check if a template parameter type is integral?
I know that I can use std::is_integral<>
in C++11 to do this. There's even a question here for that.
How to check that template's parameter type is integral?
I also know that Boost provides this feature. I'm interested in how to "manually" make this check.
There's no specific problem I'm trying to solve. This is an abstract question about C++.
Manually speaking you have to first define a template class that defines whether something is true of false at compile time:
After that you start defining the trait class with the default cases and some redirecting cases:
Then the core of it will come through manually instantiating the template specialisation for integral types.
That's one way to do it anyway. You could have a macro that would automatically generate these to make it easier. However the basic idea remains the same, they just check if a specific type is part of the group you're asking for and it's done through some sort of look-up. This way (explicit template instantiation) is probably the easiest way to do it.