C++20 constexpr 容器将如何工作? [英] How will C++20 constexpr containers work?

查看:43
本文介绍了C++20 constexpr 容器将如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为 constexpr std::字符串constexpr std::vector 已被 C++20 接受,这些将如何使用?链接的论文在细节上非常短.我们是否需要指定特殊的 constexpr 分配器,使编译时字符串/向量与其正常等效项不兼容?

As constexpr std::string and constexpr std::vector have been accepted into C++20, how will these be used? The linked papers are very short on details. Do we need to specify special constexpr allocators, making compile-time strings/vectors incompatible with their normal equivalents?

推荐答案

这两篇论文严重依赖P0784,其中讨论了编译时分配的工作方式.

Those two papers depend heavily on P0784, which discusses how allocations at compile-time will work.

不完整的答案:

  • 只有 std::allocator 可以工作.
  • 所有分配都会被跟踪,并且必须在编译完成之前解除分配.这意味着您可以在编译时进行操作,但不能初始化 stringvector 变量以在运行时使用.(就我个人而言,我认为这个限制很有可能会在标准的未来版本中取消 - 但这只是我的看法.)
  • Only std::allocator will work.
  • All allocations are tracked, and must be deallocated before compilation is complete. This means that you can do manipulations at compile-time, but you can't initialize string and vector variables to be used at run-time. (Personally, I think there's a good chance that this restriction will be lifted in a future version of the standard - but that's just my opinion.)

这篇关于C++20 constexpr 容器将如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆