Namespaces
Variants
Views
Actions

Difference between revisions of "Template:cpp/language/condition"

From cppreference.com
m (Condition: as if...)
m (Condition: fix again...)
 
Line 4: Line 4:
 
* If it can be syntactically resolved as a {{rlp|structured binding}} declaration, it is interpreted as a structured binding declaration.
 
* If it can be syntactically resolved as a {{rlp|structured binding}} declaration, it is interpreted as a structured binding declaration.
 
}}
 
}}
* If it can be syntactically resolved as an expression, it is treated as an expression. Otherwise, it is treated as if a declaration{{rev inl|since=c++26| that is not a structured binding declaration}}.
+
* If it can be syntactically resolved as an expression, it is treated as an expression. Otherwise, it is treated as a declaration{{rev inl|since=c++26| that is not a structured binding declaration}}.
  
 
When control reaches condition, the condition will yield a value, which is used to {{{usage|}}}.
 
When control reaches condition, the condition will yield a value, which is used to {{{usage|}}}.

Latest revision as of 17:03, 1 November 2024

Contents

[edit] Condition

A condition can either be an expression or a simple declaration.

  • If it can be syntactically resolved as a structured binding declaration, it is interpreted as a structured binding declaration.
(since C++26)
  • If it can be syntactically resolved as an expression, it is treated as an expression. Otherwise, it is treated as a declaration that is not a structured binding declaration(since C++26).

When control reaches condition, the condition will yield a value, which is used to .

[edit] Expression

If condition is an expression, the value it yields is the the value of the expression.

[edit] Declaration

If condition is a simple declaration, the value it yields is the value of the decision variable (see below).

[edit] Non-structured binding declaration

The declaration has the following restrictions:

  • Syntactically conforms to the following form:
  • type-specifier-seq declarator = assignment-expression
(until C++11)
  • attribute-specifier-seq(optional) decl-specifier-seq declarator brace-or-equal-initializer
(since C++11)

The decision varaiable of the declaration is the declared variable.

Structured binding declaration

The declaration has the following restrictions:

The decision variable of the declaration is the invented variable e introduced by the declaration.

(since C++26)