相关疑难解决方法(0)

静态constexpr变量有意义吗?

如果我有一个函数(比方说,一个大阵列)内的变量,它是有意义的声明它既staticconstexprconstexpr保证数组是在编译时创建的,那么它会static没用吗?

void f() {
    static constexpr int x [] = {
        // a few thousand elements
    };
    // do something with the array
}
Run Code Online (Sandbox Code Playgroud)

static在生成的代码或语义方面,实际上是在做什么吗?

c++ static constexpr c++11

172
推荐指数
3
解决办法
7万
查看次数

我们可以在constexpr函数中省略const局部变量吗?

例如:

constexpr int g() { return 30; }    

constexpr int f()
{
    // Can we omit const?
    const int x = g();
    const int y = 10;

    return x + y;
}
Run Code Online (Sandbox Code Playgroud)

没有必要constexpr函数中声明局部变量const

局部变量的constexpr函数不等于没有const局部变量的函数吗?const

换句话说,constexpr函数是否强加(暗示)const它的局部变量?

c++ const constexpr c++11 c++14

19
推荐指数
2
解决办法
2354
查看次数

标签 统计

c++ ×2

c++11 ×2

constexpr ×2

c++14 ×1

const ×1

static ×1