C++ features by examples
'Requires' clause and expression
Collaboration diagram for 'Requires' clause and expression:

Functions

template<typename T >
requires is_integral_v<T>
constexpr T requires_demo (T a)
 
template<typename T >
requires is_same_v<T, double>
constexpr auto requires_demo (T &&a)
 
template<class T >
requires is_signed_v<T> || (is_unsigned_v<T> && ! is_void_v<void>)
void complex_requirement_demo ()
 
template<class T >
requires requires() { true;}
void requires_expression_demo ()
 Annotated example of requires-expression. More...
 
template<class T >
requires requires(T a) { a / 0; }
constexpr auto what (T a)
 

Detailed Description

Function Documentation

◆ complex_requirement_demo()

template<class T >
requires is_signed_v<T> || (is_unsigned_v<T> && ! is_void_v<void>)
void complex_requirement_demo ( )

Definition at line 184 of file 20.cpp.

184{ }

◆ requires_demo() [1/2]

template<typename T >
requires is_same_v<T, double>
constexpr auto requires_demo ( T &&  a)
constexpr

requires-clause can be after function declaration and supports template overloading

Definition at line 177 of file 20.cpp.

177{ return 2; }

◆ requires_demo() [2/2]

template<typename T >
requires is_integral_v<T>
constexpr T requires_demo ( a)
constexpr

Definition at line 169 of file 20.cpp.

169{ return a + 1; }

◆ requires_expression_demo()

template<class T >
requires requires() { true;}
void requires_expression_demo ( )

Annotated example of requires-expression.

Definition at line 192 of file 20.cpp.

192{ }

◆ what()

template<class T >
requires requires(T a) { a / 0; }
constexpr auto what ( a)
constexpr

Definition at line 194 of file 20.cpp.

194{ a / 0; } auto constexpr what(T a) { return 1; }
constexpr auto what(T a)
Definition: 20.cpp:194