Namespaces
Variants
Views
Actions

Template:cpp/error if

From cppreference.com

If {{{1}}}, the program is ill-formed

[edit] [{{purge}}] Template documentation

These are templates that are used to describe the constraints, mandated requirements and preconditions of standard library functions.

{{cpp/enable if|constraint |plural=yes or no (optional)}} - creates one or more constraints. Specify the “plural” parameter as “yes” to apply the constraint to multiple overloads.

Usage Result
{{cpp/enable if|{{tt|T}} is not {{c/core|void}}}}. This overload participates in overload resolution only if T is not void.
{{cpp/enable if|plural=yes|all following conditions are satisfied}}:
* {{tt|T}} is not {{c/core|void}}.
* {{tt|T}} is not an array type.
These overloads participate in overload resolution only if all following conditions are satisfied:
  • T is not void.
  • T is not an array type.


{{cpp/error if|mandated requirement (negated) }} - creates one or more mandated requirements.

Usage Result
{{cpp/error if|{{tt|T}} is not {{named req|CopyConstructible}}}}. If T is not CopyConstructible, the program is ill-formed.
{{cpp/error if|any of the following conditions is satisfied}}:
* {{tt|T}} is not {{named req|MoveConstructible}}.
* {{tt|U}} is not {{named req|MoveConstructible}}.
If any of the following conditions is satisfied, the program is ill-formed:


{{cpp/ub if|precondition (negated) }} - creates one or more preconditions.

Usage Result
{{cpp/ub if|{{c|num < 0}} is {{c|true}}}}. If num < 0 is true, the behavior is undefined.
{{cpp/ub if|any of the following conditions is satisfied}}:
* {{c|num < 0}} is {{c|true}}.
* {{c|pos < 0}} is {{c|true}}.
If any of the following conditions is satisfied, the behavior is undefined:
  • num < 0 is true.
  • pos < 0 is true.


{{cpp/hardened ub if|hardened precondition (negated) |since=hardening version (optional)}} - creates one or more hardened preconditions. If the precondition is hardened from a specified version, it can be specified by the “since” parameter.

Usage Result
{{cpp/hardened ub if|{{c|num < 0}} is {{c|true}}}} If num < 0 is true:
  • If the implementation is hardened, a contract violation occurs. Moreover, if the contract-violation handler returns under “observe” evaluation semantic, the behavior is undefined.
  • If the implementation is not hardened, the behavior is undefined.
{{cpp/hardened ub if|since=c++26|{{c|pos < 0}} is {{c|true}}}}

If pos < 0 is true, the behavior is undefined.

(until C++26)

If pos < 0 is true:

  • If the implementation is hardened, a contract violation occurs. Moreover, if the contract-violation handler returns under “observe” evaluation semantic, the behavior is undefined.
  • If the implementation is not hardened, the behavior is undefined.
(since C++26)