C++ - 分配器类型提供的非平凡指针的构造是否会抛出异常?
C++ - could construction of a non-trivial pointer supplied by an allocator type throw an exception?
此问题不仅限于内置的 C++11 指针类型(shared_ptr 等),还包括可能在 C++ 中定义并作为标准的一部分包含的任何自定义指针类型-兼容的分配器。
非平凡指针的构造,例如自定义分配器 (std::allocator_traits::pointer) 提供的指针,是否会抛出异常?如果是,为什么?
[allocator.requirements]/4 An allocator type X
shall satisfy the requirements of CopyConstructible
(17.6.3.1). The X::pointer
,
X::const_pointer
, X::void_pointer
, and X::const_void_pointer
types shall satisfy the requirements of NullablePointer
(17.6.3.3). No constructor, comparison operator, copy operation, move operation, or swap operation on these types shall exit via an exception...
强调我的
此问题不仅限于内置的 C++11 指针类型(shared_ptr 等),还包括可能在 C++ 中定义并作为标准的一部分包含的任何自定义指针类型-兼容的分配器。
非平凡指针的构造,例如自定义分配器 (std::allocator_traits
[allocator.requirements]/4 An allocator type
X
shall satisfy the requirements ofCopyConstructible
(17.6.3.1). TheX::pointer
,X::const_pointer
,X::void_pointer
, andX::const_void_pointer
types shall satisfy the requirements ofNullablePointer
(17.6.3.3). No constructor, comparison operator, copy operation, move operation, or swap operation on these types shall exit via an exception...
强调我的