C++20 的 std::vector 是如何赋值 constexpr 的?

How is C++20's std::vector assign constexpr?

鉴于向量的当前内容和大小可以在运行时随机确定,并且所有内容都必须在调用 assign 时被销毁,C++20 的 assign member function 怎么可能是 constexp ie。编译时?

找到我的答案here。引用一下,

Being a constexpr function does not mean that the function is executed at compile time. It says, that the function has the potential to run at compile time. A constexpr function can also run a runtime. It's often a question of the compiler and the optimisation level if a constexpr functions runs at compile time or runtime.

因此,与必须在编译时确定的 constexpr 变量不同,给定 constexpr 函数的一次调用可能 运行 在编译时,具体取决于调用的情况(例如 constexpr std::vector)和另一个在 运行 时间(例如 non-constexpr std::vector)。