你想要(is_string_or_int(param_0)) && (is_string_or_int(param_1)) && (is_string_or_int(param_2)) && ...。这可以用 fold 表达式来写:
typename std::enable_if<
(true && ... && (
std::is_same<ParamType, std::string>::value ||
std::is_same<ParamType, int>::value
))
>::type
这仅适用于 C++17 及更高版本。对于 C++11 友好的解决方案,您可以使用 struct 特化来迭代类型:
// true iff Testing is any of Required...
template<typename Testing, typename... Required>
struct one_match : std::false_type {};
template<typename Testing, typename First, typename... Rest>
struct one_match<Testing, First, Rest...> : std::bool_constant<std::is_same<Testing, First>::value || one_match<Testing, Rest...>::value> {};
// true iff all of TestingTypes... are in the tuple RequiredTypesTuple
template<typename RequiredTypesTuple, typename... TestingTypes>
struct all_match;
template<typename... RequiredTypes>
struct all_match<std::tuple<RequiredTypes...>> : std::true_type {};
template<typename... RequiredTypes, typename First, typename... Rest>
struct all_match<std::tuple<RequiredTypes...>, First, Rest...> : std::bool_constant<one_match<First, RequiredTypes...>::value && all_match<std::tuple<RequiredTypes...>, Rest...>::value> {};
template <typename... ParamType, typename enabler =
typename std::enable_if<
all_match<std::tuple<std::string, int>, ParamType...>::value
>::type>
static inline void Log(const ParamType & ... args)
{
}