gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 01:37:01 28 4
gpt4 key购买 nike

我知道的一件事可能不是真的,那就是 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com