highlights(cpp): add support for concepts

Requires https://github.com/tree-sitter/tree-sitter-cpp/pull/138
This commit is contained in:
Stephan Seitz 2021-11-28 18:05:18 +01:00
parent 4cf688ee68
commit db01c82b08
3 changed files with 28 additions and 2 deletions

View file

@ -0,0 +1,22 @@
template <class T, class U>
concept Derived = std::is_base_of<U, T>::value;
// ^ keyword
// ^ type
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; }