Let's say I've got a function:
template <typename T>
void foo(const T& arg) {
ASSERT(is_valid<T>::value == true);
// ...
}
Where is_valid check if T is either a string or an integer. I can easily make structures that can do that for me:
template <typename T>
struct is_integer { static const bool value = false; };
template <>
struct is_integer<int> { static const bool value = true; };
template <typename T>
struct is_string { static const bool value = false; };
template <>
struct is_string<std::string> { static const bool value = true; };
And then use both of these structure to check the argument:
template <typename T>
struct is_valid {
static const bool value = is_string<T>::value || is_integer<T>::value;
};
However it seems I miss some string types. Is there a C++ type that target all string types? Is there already a structure or function that can do that for me?
I got:
std::stringchar*char[]
in my is_string structure but it doesn't seem to be enough. I haven't passed const and & (references) as it is not tested that way: from a const T& argument, only T is tested.