c++ - 为什么在 C++20 中将 std::vector::push_back 声明为 constexpr?

标签 c++ stdvector c++20 constexpr

根据 cppref , 在 C++20 中,std::vector::push_back声明如下:

constexpr void push_back(const T& value);
我无法想象 push_back 的场景应该是 constexpr .
背后的原理是什么?

最佳答案

Is there any rationale behind?


这是提案的摘要。没有单独的理由部分:

P1004R2 Making std::vector constexpr

Abstract

std::vector is not currently constexpr friendly. With the loosening of requirements on constexpr in [P0784R1] and related papers, we can now make std::vector constexpr, and we should in order to support the constexpr reflection effort (and other evident use cases).

关于c++ - 为什么在 C++20 中将 std::vector::push_back 声明为 constexpr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68094329/

相关文章:

c++ - 为什么我的低级 Windows 键 Hook 停止工作?

c++ - 是否可以为派生类创建构造函数?

c++ - std::vector Erase - 它会自动取消分配吗?

c++ - 将 uint8 的 vector 转换为字符串

c++ - 模板中类型别名的继承

c++ - clang 能代替 Exuberant Ctags 吗?

c++ - 我必须在声明后清除 C++ vector 吗?

c++ - 为什么 std::isnan 不是 constexpr?

c++ - 如果无法编译未使用的函数,则模板类使用 C++17 编译,但不使用 C++20

c++ - 函数的类型是否受其参数声明子句中是否存在函数参数包的影响?