Namespaces
Variants
Views
Actions

Template:cpp/language/condition

From cppreference.com

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)