VCTR
Loading...
Searching...
No Matches
GenericConcepts.h
1/*
2 ==============================================================================
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 Copyright 2022- by sonible GmbH.
6
7 This file is part of VCTR - Versatile Container Templates Reconceptualized.
8
9 VCTR is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License version 3
11 only, as published by the Free Software Foundation.
12
13 VCTR is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License version 3 for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 version 3 along with VCTR. If not, see <https://www.gnu.org/licenses/>.
20 ==============================================================================
21*/
22
23namespace vctr::has
24{
25
27template <class Lhs, class Rhs = Lhs>
28concept operatorPlusEquals = requires (Lhs l, Rhs r) { l += r; };
29
31template <class T>
32concept init = requires (T& t, void* ptr, size_t s) { t.init (ptr, s); };
33
35template <class T>
36concept getStart = requires (const T& t) { { t.getStart() } -> is::realNumber; };
37
39template <class T>
40concept getLength = requires (const T& t) { { t.getLength() } -> is::realNumber; };
41
43template <class T>
44concept getEnd = requires (const T& t) { { t.getEnd() } -> is::realNumber; };
45
47template <class T, class ValueType>
48concept getStartWithValueType = requires (const T& t) { { t.getStart() } -> std::same_as<ValueType>; };
49
51template <class T, class ValueType>
52concept getLengthWithValueType = requires (const T& t) { { t.getLength() } -> std::same_as<ValueType>; };
53
55template <class T, class ValueType>
56concept getEndWithValueType = requires (const T& t) { { t.getEnd() } -> std::same_as<ValueType>; };
57
58}
59
60namespace vctr::detail
61{
62
63// clang-format off
64template <class T>
65struct IsStdUniquePtr : std::false_type {};
66
67template <class T, class D>
68struct IsStdUniquePtr<std::unique_ptr<T, D>> : std::true_type {};
69// clang-format on
70
71} // namespace vctr::detail
72
73namespace vctr::is
74{
75
77template <class T>
78concept triviallyCopyable = std::is_trivially_copyable_v<T>;
79
81template <class T>
82concept nonConst = ! std::is_const_v<T>;
83
85template <class T>
86concept pointer = std::is_pointer_v<std::remove_cvref_t<T>>;
87
89template <class T>
90concept noPointer = ! std::is_pointer_v<std::remove_cvref_t<T>>;
91
93template <class T>
94concept uniquePtr = detail::IsStdUniquePtr<T>::value;
95
97template <class T>
98concept lvalueReference = std::is_lvalue_reference_v<T>;
99
101template <class T>
102concept stdPair = requires (T& t) { [] <class A, class B> (std::pair<A, B>&) {} (t); };
103
105template <class T>
106concept stdTuple = requires (T& t) { [] <class... Ts> (std::tuple<Ts...>&) {} (t); };
107
108template <class T, class... TupleTypes>
109concept stdTupleWithTypes = std::same_as<T, std::tuple<TupleTypes...>>;
110
115template <class C>
116concept constant = requires (const void* ptr) { ptr = &C::value; };
117
122template <class C, class T>
123concept constantWithType = std::same_as<T, std::remove_cvref_t<decltype (C::value)>>;
124
126template <class T>
130
132template <class T, class ValueType>
136
137} // namespace vctr::is
138
139namespace vctr::are
140{
141
143template <class T, class... U>
144concept same = (std::same_as<T, U> || ...);
145
146} // namespace vctr::are
Constrains a pack of elements to be the same type.
Definition: GenericConcepts.h:144
Constrains the type to have a member function function getEnd() const which returns ValueType.
Definition: GenericConcepts.h:56
Constrains the type to have a member function function getEnd() const which returns a real number.
Definition: GenericConcepts.h:44
Constrains the type to have a member function function getLength() const which returns ValueType.
Definition: GenericConcepts.h:52
Constrains the type to have a member function function getLength() const which returns a real number.
Definition: GenericConcepts.h:40
Constrains the type to have a member function function getStart() const which returns ValueType.
Definition: GenericConcepts.h:48
Constrains the type to have a member function function getStart() const which returns a real number.
Definition: GenericConcepts.h:36
Constrains the type to have a member function init that takes a void pointer and a size_t.
Definition: GenericConcepts.h:32
Constrains the type to define an operator +=.
Definition: GenericConcepts.h:28
Constrains the type to be a class that defines a static const value field of a certain type.
Definition: GenericConcepts.h:123
Constrains the type to be a class that defines a static const value field.
Definition: GenericConcepts.h:116
Constrains a type to be an lvalue reference.
Definition: GenericConcepts.h:98
Constrains a type to be no pointer of a reference to a pointer.
Definition: GenericConcepts.h:90
Constrains a type to be non const.
Definition: GenericConcepts.h:82
Constrains a type to be a pointer or a reference to a pointer.
Definition: GenericConcepts.h:86
Constrains the type to be a range, this is a class with a getStart, getLength and getEnd member funct...
Definition: GenericConcepts.h:133
Constrains the type to be a range, this is a class with a getStart, getLength and getEnd member funct...
Definition: GenericConcepts.h:127
Constrains a type to represent a real valued number.
Definition: NumericTypeConcepts.h:79
Constrains the type to be any instance of std::pair.
Definition: GenericConcepts.h:102
Definition: GenericConcepts.h:109
Constrains the type to be any instance of std::tuple.
Definition: GenericConcepts.h:106
Constrains a type to be trivially copyable.
Definition: GenericConcepts.h:78
Constrains the type to be any instance of std::unique_ptr.
Definition: GenericConcepts.h:94