跳转至

编译时运行函数

标准: C++14, C++20, C++23.

相关的关键字:

  • constexpr: 可以在编译时计算.
  • consteval: 必须在编译时计算.

constexpr

  1. C++14
  2. 支持在函数中使用变量/for循环.
  3. C++20
  4. std::is_constant_evaluated() 可以用于判断当前是在进行编译时计算还是运行时计算.
  5. 支持 std::vector/std::string/std::map.
  6. 支持 new.

评论