返回信息流RT
这是一条镜像帖。来源:北邮人论坛 / cpp / #99069同步于 2019/6/5
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
MP怎么判断vector<int> 和 vector<xxx> 都是vector?
ricann
2019/6/5镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
```
#include <iostream>
#include <type_traits>
#include <vector>
template <typename> struct is_vector_t : std::false_type {};
template <typename Element, typename Allocator>
struct is_vector_t<std::vector<Element, Allocator>> : std::true_type {};
int main() {
auto is_vector = [](auto& t) {
using T = std::decay_t<decltype(t)>;
if constexpr (is_vector_t<T>::value)
std::cout << "is a vector" << std::endl;
else
std::cout << "is not a vector" << std::endl;
};
std::vector<int> a;
int b;
is_vector(a);
is_vector(b);
return 0;
}
```
兄弟,代码编不过哇
【 在 maweihu 的大作中提到: 】
: ```
: #include <iostream>
: #include <type_traits>
: ...................
厉害了老铁,刚又试了一遍,编过了,哈哈,感谢感谢
【 在 maweihu 的大作中提到: 】
: ```
: #include <iostream>
: #include <type_traits>
: ...................