c++c++17nodesconstexpr

constexpr in Node handle


I would want to ask for clarification about a specific that the standard indicates for the Node-handle type. I read cppreference information, where it is specified that Node-handle's default constructor must be declared constexpr, but this specific is not present for any other constructor, destructor or member function.

Which is the reason for this choice?


Solution

  • In C++17, dynamic memory allocation cannot happen at compile-time. The nodes referenced by a non-empty node_handle are the result of dynamic memory allocation. Ergo, they could never work at compile-time, so making them constexpr is not possible.

    This persists into C++20 because the associative containers are not compatible with constexpr allocation support.