在 Node 处理中的 constexpr

huangapple go评论77阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年3月3日 21:29:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75627702.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定