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
70template <class T>
71struct IsStdTuple : std::false_type {};
72
73template <class... T>
74struct IsStdTuple<std::tuple<T...>> : std::true_type {};
75// clang-format on
76
77} // namespace vctr::detail
78
79namespace vctr::is
80{
81
83template <class T>
84concept triviallyCopyable = std::is_trivially_copyable_v<T>;
85
87template <class T>
88concept nonConst = ! std::is_const_v<T>;
89
91template <class T>
92concept pointer = std::is_pointer_v<std::remove_cvref_t<T>>;
93
95template <class T>
96concept noPointer = ! std::is_pointer_v<std::remove_cvref_t<T>>;
97
99template <class T>
100concept uniquePtr = detail::IsStdUniquePtr<T>::value;
101
103template <class T>
104concept stdTuple = detail::IsStdTuple<T>::value;
105
106template <class T, class... TupleTypes>
107concept stdTupleWithTypes = std::same_as<T, std::tuple<TupleTypes...>>;
108
113template <class C>
114concept constant = requires (const void* ptr) { ptr = &C::value; };
115
120template <class C, class T>
121concept constantWithType = std::same_as<T, std::remove_cvref_t<decltype (C::value)>>;
122
124template <class T>
128
130template <class T, class ValueType>
134
135} // namespace vctr::is
136
137namespace vctr::are
138{
139
141template <class T, class... U>
142concept same = (std::same_as<T, U> || ...);
143
144} // namespace vctr::are
Constrains a pack of elements to be the same type.
Definition: GenericConcepts.h:142
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:121
Constrains the type to be a class that defines a static const value field.
Definition: GenericConcepts.h:114
Constrains a type to be no pointer of a reference to a pointer.
Definition: GenericConcepts.h:96
Constrains a type to be non const.
Definition: GenericConcepts.h:88
Constrains a type to be a pointer of a reference to a pointer.
Definition: GenericConcepts.h:92
Constrains the type to be a range, this is a class with a getStart, getLength and getEnd member funct...
Definition: GenericConcepts.h:131
Constrains the type to be a range, this is a class with a getStart, getLength and getEnd member funct...
Definition: GenericConcepts.h:125
Constrains a type to represent a real valued number.
Definition: NumericTypeConcepts.h:75
Definition: GenericConcepts.h:107
Constrains the type to be any instance of std::tuple.
Definition: GenericConcepts.h:104
Constrains a type to be trivially copyable.
Definition: GenericConcepts.h:84
Constrains the type to be any instance of std::unique_ptr.
Definition: GenericConcepts.h:100