Tak, jest możliwe.
Foo<string,int,thread> f;
f.foo<thread>();
f.foo<int>();
f.foo<string>();
// f.foo<vector<char>>(); // error
http://melpon.org/wandbox/permlink/3YOIWw0bEOYDXFq8
możesz osiągnąć np. dzięki:
template<typename T, typename First, typename... Ts>
struct is_any_of
{
static constexpr bool value = std::is_same<T, First>::value || is_any_of<T, Ts...>::value;
};
template<typename T, typename Last>
struct is_any_of<T, Last>
{
static constexpr bool value = std::is_same<T, Last>::value;
};
template<typename... Ts>
struct Foo
{
template<typename T, typename = typename std::enable_if<is_any_of<T, Ts...>::value, void>::type>
void foo(){
BARK;
}
};
edit: ewentualnie możesz użyć Boost.MPL:
http://melpon.org/wandbox/permlink/pOLhJHcRNgDy4ZGM
template<typename... Ts>
struct Foo
{
template<typename T,
typename = typename std::enable_if<
!std::is_same<
typename boost::mpl::find<boost::mpl::vector<Ts...>, T>::type,
typename boost::mpl::end<boost::mpl::vector<Ts...>>::type
>::value,
void
>::type>
void foo(){
BARK;
}
};