Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

C++ concept simple requirements

/*
A simple requirement is an arbitrary expression statement that does not 
start with the keyword requires. It asserts that the expression is valid. 
The expression is an unevaluated operand; only language correctness is checked.
*/

template<typename T>
concept Addable = requires (T a, T b)
{
    a + b; // "the expression a+b is a valid expression that will compile"
};
 
template<class T, class U = T>
concept Swappable = requires(T&& t, U&& u)
{
    swap(std::forward<T>(t), std::forward<U>(u));
    swap(std::forward<U>(u), std::forward<T>(t));
};

/*
A requirement that starts with the keyword requires is always interpreted
as a nested requirement. Thus a simple requirement cannot start with an 
unparenthesized requires-expression.
*/
Source by en.cppreference.com #
 
PREVIOUS NEXT
Tagged: #concept #simple #requirements
ADD COMMENT
Topic
Name
3+1 =