Search code examples
c++c++11pointersexceptionallocator

C++ - could construction of a non-trivial pointer supplied by an allocator type throw an exception?


This question is not limited to the built-in C++11 pointer types (shared_ptr etc) but includes any custom pointer type that could be potentially defined in C++ and included as part of a standards-compliant allocator.

Could the construction of a non-trivial pointer, such as that supplied by a custom allocator (std::allocator_traits<Alloc>::pointer) throw an exception and if so, why?


Solution

  • [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...

    Emphasis mine