How will C++20 constexpr containers work?

混江龙づ霸主 提交于 2020-12-25 04:10:28

问题


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?


回答1:


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

Incomplete answer:

  • 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.)


来源:https://stackoverflow.com/questions/57163315/how-will-c20-constexpr-containers-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!