C ++ 20 constexpr容器将如何工作? [英] How will C++20 constexpr containers work?
本文介绍了C ++ 20 constexpr容器将如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为 constexpr std :: string
和 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
将起作用。 - 所有分配都将被跟踪,并且必须在编译完成之前将其释放。这意味着您可以在编译时进行操作,但是不能将
string
和vector
变量初始化为在运行时使用。 (个人而言,我认为很有可能在将来的标准版本中取消此限制-但这只是我的意见。)
- 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
andvector
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屋!
查看全文