STL 容器元素是否明确要求 (noexcept) 可破坏?
Are STL container elements explicitly required to be (noexcept) destructible?
C++11(和 C++14)STL 容器有 noexcept
个析构函数和 clear()
个成员函数。
这意味着元素也应该有 noexcept
析构函数,或者至少存储在容器中的实际元素在被销毁时不应该抛出任何异常——或者更准确地说,相应的 allocator_traits<Allocator>::destroy
调用不应抛出。
这是否在标准的任何地方指定为要求(明确或由另一个明确要求暗示)?如果不是,为什么?
我知道 is_nothrow_constructible
需要 noexcept
析构函数,但 is_constructible
本身不需要,而且容器要求是根据概念而不是类型特征模板指定的。
17.6.4.8/1 In certain cases (replacement functions, handler functions, operations on types used to instantiate standard
library template components), the C++ standard library depends on components supplied by a C++ program.
If these components do not meet their requirements, the Standard places no requirements on the
implementation.
17.6.4.8/2 In particular, the effects are undefined in the following cases:
...
- if any replacement function or handler function or destructor operation exits via an exception, unless specifically allowed in the
applicable Required behavior: paragraph.
C++11(和 C++14)STL 容器有 noexcept
个析构函数和 clear()
个成员函数。
这意味着元素也应该有 noexcept
析构函数,或者至少存储在容器中的实际元素在被销毁时不应该抛出任何异常——或者更准确地说,相应的 allocator_traits<Allocator>::destroy
调用不应抛出。
这是否在标准的任何地方指定为要求(明确或由另一个明确要求暗示)?如果不是,为什么?
我知道 is_nothrow_constructible
需要 noexcept
析构函数,但 is_constructible
本身不需要,而且容器要求是根据概念而不是类型特征模板指定的。
17.6.4.8/1 In certain cases (replacement functions, handler functions, operations on types used to instantiate standard library template components), the C++ standard library depends on components supplied by a C++ program. If these components do not meet their requirements, the Standard places no requirements on the implementation.
17.6.4.8/2 In particular, the effects are undefined in the following cases:
...
- if any replacement function or handler function or destructor operation exits via an exception, unless specifically allowed in the applicable Required behavior: paragraph.