2022-04-14 12:01:23 +08:00
|
|
|
|
|
|
|
template <class T, class U>
|
|
|
|
concept Derived = std::is_base_of<U, T>::value;
|
|
|
|
// ^ keyword
|
2023-06-18 14:17:38 +08:00
|
|
|
// ^ type.definition
|
2022-04-14 12:01:23 +08:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
concept Hashable = requires(T a) {
|
|
|
|
// ^ keyword
|
|
|
|
// ^ parameter
|
|
|
|
// ^ type
|
|
|
|
{ std::hash<T>{}(a) } -> std::convertible_to<std::size_t>;
|
|
|
|
typename CommonType<T, U>; // CommonType<T, U> is valid and names a type
|
|
|
|
{ CommonType<T, U>{std::forward<T>(t)} };
|
|
|
|
{ CommonType<T, U>{std::forward<U>(u)} };
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
requires requires (T x) { x + x; } // ad-hoc constraint, note keyword used twice
|
|
|
|
// ^ keyword
|
|
|
|
T add(T a, T b) { return a + b; }
|