问题
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
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.)
来源:https://stackoverflow.com/questions/57163315/how-will-c20-constexpr-containers-work