[英]Is constexpr if with initializer guaranteed by the standard? 'constexpr(constexpr auto x = f(); x) { }'
如果初始化語法和'constexpr if'中有以下內容,我找不到有關新C ++ 17的任何信息:
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
只是“ if
with constexpr
”或者它不能保證並且必須明確添加到標准中?
帶有初始化程序提議的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語句中聲明的名稱與條件中聲明的名稱在同一聲明區域中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.