I'm trying to practice in traits and SFINAE and try to write something like is_container
for a vector:
template <typename... Ts>
struct is_container :std::false_type {};
template <typename... Ts>
struct is_container< std::vector<Ts...> >:std::true_type {};
template < typename T>
inline constexpr auto is_container_v = is_container<T>::value;
And actually such a function:
template<typename T, typename std::enable_if_t<is_container_v<T>, int > = 0>
auto foo(T&& first, T&& second) {
//do smth...
}
But such a call does not see the function:
std::vector<int> test_vec1(4,0);
std::vector<int> test_vec2(5,3);
foo(test_vec1, test_vec2);
I can't see where the error is.I think that the vector should have 2 parameters:
template<class T, class Alloc>
struct is_container<std::vector<T, Alloc>>
But shouldn't the variadic template work? or a mistake in another?I will be happy to help