如果标准保证使用初始值设定项,constexpr 是否? 'constexpr(constexpr auto x = f(); x) { }'
Is constexpr if with initializer guaranteed by the standard? 'constexpr(constexpr auto x = f(); x) { }'
如果初始值设定项语法,我找不到任何关于新C++17的信息和中的"constexpr if"
http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0128r1.html
不过,Clang HEAD支持该语法。。。
constexpr auto f() { return true; }
int main() {
if constexpr(constexpr auto x = f(); x) { }
}
在线代码在这里->http://melpon.org/wandbox/permlink/dj3a9ChvjhlNc8nr
带有初始化器的constexpr if
是否由标准保证,因为constexpr if
只是一个"带有constexpr
的if
",或者它没有保证,必须显式添加到标准中?
带有初始值设定项提案的Selection语句提到了if constexpr
,并表示"if constexpr
的功能与该提案中的扩展if
语句同样有效"。
关于N4606[stmt.if]p3中带有初始值设定项的if
语句的规范明确允许使用if constexpr
。
以下是N4606[stmt.if]p3所说的:
形式的if语句
if constexpr[opt] ( init-statement condition ) statement
相当于
{ init-statement if constexpr[opt] ( condition ) statement }
以及形式的if语句
if constexpr[opt] ( init-statement condition ) statement else statement
相当于
{ init-statement if constexpr[opt] ( condition ) statement else statement }
除了init语句中声明的名称与条件中声明的那些名称位于同一声明性区域之外。
相关文章:
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 使用CMake检测支持的C++标准
- 如何理解C++标准N3337中的expr.const.cast子句8
- 多成员Constexpr结构初始化
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- 条件constexpr函数
- 编译标准库类型
- constexpr 函数中的非文字(通过 std::is_constant_evaluated)
- C++ constexpr:在编译时计算标准数组
- constexpr 标准函子的正确用法是什么?
- 为什么C++标准库不提供 cmath 函数的 constexpr 版本?
- C 标准:DO命名空间constexpr变量具有内部链接
- 在C++11标准中,它在哪里指定了在翻译过程中何时可以计算constexpr函数
- C++11:模板专用化的 constexpr 成员的标准参考需要额外声明
- 在 constexpr 中使用的非常量:标准怎么说
- C++标准是否明确禁止通过 constexpr 成员函数指针调用默认参数?
- C++14 标准库的哪些部分可能是,哪些部分将被制作成 constexpr
- 在编译时测试endianes:根据标准,这个constexpr函数是否正确
- [dcl.]c++标准中的Constexpr]p5
- 如果标准保证使用初始值设定项,constexpr 是否? 'constexpr(constexpr auto x = f(); x) { }'