aboutsummaryrefslogtreecommitdiffstats
path: root/tests/query/highlights/cpp/concepts.cpp
blob: 09d975c98e4802417cad6e19c6d7ee7e52da5a99 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
template <class T, class U>
concept Derived = std::is_base_of<U, T>::value;
//  ^ @keyword
//       ^ @type.definition

template<typename T>
concept Hashable = requires(T a) {
//                   ^ @keyword
//                            ^ @variable.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; }