V2EX  ›  英汉词典
Enqueued related words: Consteval, Constinit

Constexpr

Definition / 定义

constexpr(C++ 关键字):表示“可在编译期求值”。用于修饰变量、函数或构造函数,要求其结果在满足条件时能在编译阶段计算,从而提高性能、增强常量表达式能力。(在不同语境下还可涉及“常量表达式对象/函数”的约束,但核心含义是“编译期可计算”。)

Pronunciation / 发音

/ˈkɑːnstˌɛkspər/

Examples / 例句

constexpr int x = 10;
constexpr int x = 10;(x 在编译期就是常量 10。)

If the input is known at compile time, this constexpr function can compute the result without runtime overhead.
如果输入在编译期已知,这个 constexpr 函数就能在不增加运行时开销的情况下计算结果。

Etymology / 词源

constexpr 是 C++ 社区对 const(常量)与 expr(expression,表达式)的合成缩写,直观表达“常量表达式/可在编译期计算的表达式”的概念;作为关键字在 C++11 中引入,随后在更新标准中逐步增强其适用范围。

Related Words / 相关词

Literary Works / 文学作品

  • The C++ Programming Language(Bjarne Stroustrup,《C++ 程序设计语言》)
  • *A Tour of C++*(Bjarne Stroustrup,《C++ 语言导学》)
  • *Effective Modern C++*(Scott Meyers,《Effective Modern C++》)
  • C++ Primer(Lippman / Lajoie / Moo,《C++ Primer》)
  • C++ Templates: The Complete Guide(Vandevoorde / Josuttis / Gregor,《C++ 模板:完全指南》)
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1725 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 14ms · UTC 09:55 · PVG 17:55 · LAX 01:55 · JFK 04:55
♥ Do have faith in what you're doing.