- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个问题在这里已经有了答案:
What is `constinit` in C++20?
(1 个回答)
去年关闭。
constexpr int f() { return 0; }
int g() { return 0; }
constexpr auto c1 = f(); // OK
constinit auto c2 = f(); // OK
constexpr auto d1 = g(); // ill-formed
constinit auto d2 = g(); // ill-formed
int main() {}
constinit
之间的任何区别。和
constexpr
.
constinit
之间的真正区别是什么?和 constexpr
?
constinit
in C++20?没有明确说明
constinit
之间的区别和
constexpr
.
最佳答案
一个 constinit
变量是常量初始化的,但它不能用于常量表达式,甚至不能自动常量。您的 main
可以合法地包含这一行
c2 = 2;
关于c++ - "constinit"和 "constexpr"之间的真正区别是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62444495/
一般说静态对象的析构函数是以与构造函数相反的顺序调用的。据我了解,constinit 对象是在编译时初始化的,因此它们的析构函数应该在“普通”静态对象的析构函数之后调用。 该程序 struct A {
C++20 介绍 constinit以避免静态初始化顺序失败。 可以constinit 放弃对 nifty counter idiom 的需要吗? (例如,用于 std::cout 的初始化)? 最佳
这个问题在这里已经有了答案: What is `constinit` in C++20? (1 个回答) 去年关闭。 constexpr int f() { return 0; } int g() {
看这个小例子: constinit int a = 0; constexpr int b = a; clang 无法编译它 ( godbolt ): 2:15: error: constexpr va
constinit 是一个新的 keyword和 specifier在 P1143 中提出的 C++20 中. 标准中提供了以下示例: const char * g() { return "dynam
我在网上找到的大多数例子都更喜欢 constexpr 的“西方风格” (C++11), consteval ,和constinit (C++20): consteval auto sqr(int n)
我是一名优秀的程序员,十分优秀!