Wiki »
C++模板¶
- 判断类型
查看...查看...
std::string Test(const T t) { if constexpr (std::is_class<std::decay_t<T>>::value) // 区分是类类型还是指针类型 { if constexpr (std::is_same<std::decay_t<T>, std::vector<typename std::decay_t<T>::value_type>>::value) // 如果是vector<>类型 { if(t.empty()) { return ""; } } } if constexpr (std::is_same<T, CTestStruct*>::value) // CTestStruct结构体指针 { } else if constexpr (std::is_same<T, std::vector<CTestStruct> &>::value) // vector<CTestStruct>引用 { for(auto item : t) // 遍历vector { } } return ""; }