c++ - STDLIB 中容器元素类型的要求是什么?

标签 c++ c++11 containers

我知道的一件事可能不是真的,那就是 T应该是可复制构造的,即T应该有一个可访问的复制构造函数。

但是,是否还有其他要求,例如copy assignable

作为补充,我记得 Effective STLvector<bool>不是标准容器,因为它不符合 T *p=&c[0] 的要求格式良好。

最佳答案

我觉得顺序容器和关联容器的要求是不一样的。例如,以下是 vector (有关更多详细信息,请参见 cppreference.com)。另请注意,它已被新版本的 c++ 更改。

  • T must meet the requirements of CopyAssignable and CopyConstructible. (until C++11)

  • The requirements that are imposed on the elements depend on the actual operations performed on the container. Generally, it is required that element type is a complete type and meets the requirements of Erasable, but many member functions impose stricter requirements. (since C++11) (until C++17)

  • The requirements that are imposed on the elements depend on the actual operations performed on the container. Generally, it is required that element type meets the requirements of Erasable, but many member functions impose stricter requirements. This container (but not its members) can be instantiated with an incomplete element type if the allocator satisfies the allocator completeness requirements. (since C++17)

关于c++ - STDLIB 中容器元素类型的要求是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50617560/

相关文章:

c++ - 将 C++11 async/futures 与 Windows 异步 IO 相结合的最佳 API 是什么?

c++ - 忽略 `gnu-zero-variadic-macro-arguments` 是否安全?

docker - 如何将github上的插件安装到容器上运行的Kibana

html - 如何对齐容器内的一个 div 而另一个对齐到浏览器窗口的右端?

c++ - Visual Studio 2010 中的友元模板类和 Lambda 函数

ruby - docker-compose : connection refused between containers, 但可以从主机访问服务

c++ - 扫描堆栈中的字符时遇到错误

C++ - 无法从 'char []' 转换为 'char[]'

c++ - 不明确的构造函数调用

c++ - 使用通用引用实现前向函数