Does this mean you want to determine if
st
is one of bool, string, int? It is relatively easy to create a metafunction based off of std::is_same:
1 2 3 4 5 6 7 8 9 10 11
|
// Pre-c++17
template <typename T, typename U, typename... Rest>
struct is_any_of: std::integral_constant<bool, is_any_of<T, U>::value ||
is_any_of<T, Rest...>::value> {};
template <typename T, typename U>
struct is_any_of<T, U>: std::integral_constant<bool, std::is_same<T, U>::value> {};
// Post C++17
template <typename T, typename...Rest>
static constexpr bool is_any_of_2()
{ return (std::is_same<T, Rest>::value || ...); }
|
If you simply want different definitions of st() for different types
st
, create function overloads for
ConT()
:
1 2 3
|
template <typename st>
st ConT(st x) { ... };
int ConT(int x) { ... };
|
Demo:
http://coliru.stacked-crooked.com/a/ad8dbdcead80bbfe
Last edited on