check type of element in stl container - c++(检查stl容器中元素的类型 - C++)
本文介绍了检查stl容器中元素的类型 - C++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取 STL 容器所包含的元素的类型?
how can i get the type of the elements that are held by a STL container?
推荐答案
对于一般容器,它将是 X::value_type
.对于关联容器,它将是 X::mapped_type
(X::value_type
对应于 pair
).符合 C++ 标准第 23 章.
For containers in general it will be X::value_type
. For associative containers it will be X::mapped_type
(X::value_type
corresponds to pair<const Key,T>
). It is according to Chapter 23 of C++ Standard.
要检查类型是否相等,您可以使用 boost::is_same
.从 C++11 开始 — std::is_same
一个>.
To check that types are equal you could use boost::is_same
. And since C++11 — std::is_same
.
这篇关于检查stl容器中元素的类型 - C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:检查stl容器中元素的类型 - C++


基础教程推荐
猜你喜欢
- C++多态 1970-01-01
- 用指数格式表示浮点数 1970-01-01
- 向量<unique_ptr<A>>使用初始化列表 2022-10-23
- 对 STL 容器的安全并行只读访问 2022-10-25
- 总计将在节日礼物上花多少钱 1970-01-01
- C语言3个整数的数组 1970-01-01
- C++:为什么结构类需要一个虚拟方法才能成为多态? 2022-10-19
- 迭代std :: bitset中真实位的有效方法? 2022-10-18
- C语言数组 1970-01-01
- 明确指定任何或所有枚举数的整数值 1970-01-01