#include <type_traits>
#include <array>
#include <vector>

template<class T>
struct is_vector_type : std::false_type{}; 

template<class T>
struct is_vector_type<std::vector<T>> : std::true_type{};

template<class T>
void func(T t) 
{
    static_assert(std::is_same_v<T, std::vector<typename T::value_type>>, "is_same_v");
}

template<class T>
void func2(T t)
{
    static_assert(is_vector_type<T>::value, "is_vector_type");
}

int main()
{
    std::vector<int> v;
    std::array<int, 10> arr;
    func(v);
    func(arr);
    func2(v);
    func2(arr);
}

还有其他好的方式吗?

0

Publication author

offline 2年

lengyuewuxin

0
Comments: 0Publics: 25Registration: 15-07-2018
Authorization
*
*
Registration
*
*
*
Password generation