How will C++20 constexpr containers work?

后端 未结 1 1885
萌比男神i
萌比男神i 2021-01-05 13:37

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

1条回答
  •  梦毁少年i
    2021-01-05 14:27

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

    0 讨论(0)
提交回复
热议问题