英文:
constexpr in Node handle
问题
我想要询问关于标准为 Node-handle 类型指定的特定内容的澄清。我阅读了 cppreference 上的信息,其中指定了 Node-handle 的默认构造函数必须声明为 constexpr,但对于任何其他构造函数、析构函数或成员函数,都没有提到这一点。
你能告诉我选择这样做的原因吗?
英文:
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.
Could you tell me what is the reason for this choice?
答案1
得分: 1
在C++17中,动态内存分配无法在编译时发生。由非空node_handle
引用的节点是动态内存分配的结果。因此,在编译时无法使它们成为constexpr
。
这一情况延续到C++20,因为关联容器与constexpr
分配支持不兼容。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论