mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
concepts.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <concepts>
4#include <functional>
5#include <memory>
7#include <type_traits>
8
9
10namespace m {
11
13template<typename T>
14concept boolean = std::same_as<T, bool>;
15
18template<typename T>
19concept character = std::same_as<T, char>;
20
22template<typename T>
23concept integral = (std::integral<T> and not boolean<T>);
24
26template<typename T>
27concept signed_integral = integral<T> and std::is_signed_v<T>;
28
30template<typename T>
31concept unsigned_integral = integral<T> and not std::is_signed_v<T>;
32
34template<typename T>
35concept arithmetic = integral<T> or std::floating_point<T>;
36
38template<typename T>
39concept pointer = std::is_pointer_v<T>;
40
42template<typename T>
44
46template<typename T>
48 (primitive<std::remove_pointer_t<T>> or std::is_void_v<std::remove_pointer_t<T>>));
49
51template<typename T>
52concept decayable = not std::same_as<T, std::decay_t<T>>;
53
55template<typename T, typename U>
56concept same_signedness = (arithmetic<T> and arithmetic<U> and std::is_signed_v<T> == std::is_signed_v<U>) or
58
60template<typename T, typename U>
62 std::floating_point<T> == std::floating_point<U>;
63
64
68template<typename T, typename U>
70
72template<typename T>
73struct common_type<T, T>
74{ using type = T; };
75
78template<typename T, typename U>
80struct common_type<T, U>
81{
82 using type = std::conditional_t<sizeof(T) >= sizeof(U), T, U>;
83};
84
87template<typename T, typename U>
89struct common_type<T, U>
90{
91 using type = std::conditional_t<std::is_floating_point_v<T>, T, U>;
92};
93
95template<typename T, typename U>
97
99template<typename T, typename U>
100concept have_common_type = requires { typename common_type_t<T, U>; };
101
102
104template<typename T>
105concept is_unique_ptr = std::same_as<std::decay_t<T>, std::unique_ptr<typename T::element_type>>;
106
108template<typename T>
109concept is_unsharable_shared_ptr = std::same_as<std::decay_t<T>, unsharable_shared_ptr<typename T::element_type>>;
110
112template<typename T>
113concept is_reference_wrapper = std::same_as<std::decay_t<T>, std::reference_wrapper<typename T::type>>;
114
115
116template<template<typename...> class Template, typename... Args>
117concept is_template_instantiable = requires { typename Template<Args...>; };
118
119
120namespace detail {
121
122template<typename T, template<typename...> class Template>
123struct is_specialization : std::false_type {};
124
125template<template<typename...> class Template, typename... Args>
126struct is_specialization<Template<Args...>, Template> : std::true_type {};
127
128}
129
132template<typename T, template <typename...> class Template>
133concept is_specialization = detail::is_specialization<std::remove_cvref_t<T>, Template>::value;
134
135
137template<typename... Ts>
138struct param_pack_t : std::tuple<Ts...> {};
139
140namespace detail {
141
143template<typename T>
144struct is_param_pack : std::false_type {};
145
147template<typename... Ts>
148struct is_param_pack<param_pack_t<Ts...>> : std::true_type {};
149
151template<typename T>
153
155template<typename T>
156struct as_tuple;
157
159template<typename... Ts>
161{
162 using type = std::tuple<Ts...>;
163};
164
166template<typename T>
168
169}
170
172template<typename T>
173concept param_pack = detail::is_param_pack_v<T>;
174
176template<param_pack P>
177constexpr std::size_t param_pack_size_v = std::tuple_size_v<detail::as_tuple_t<P>>;
178
180template<std::size_t I, param_pack P>
181using param_pack_element_t = std::tuple_element_t<I, detail::as_tuple_t<P>>;
182
183namespace detail {
184
186template<param_pack P, typename T>
188{
189 template<std::size_t... Is>
190 requires (sizeof...(Is) == param_pack_size_v<P>) and (std::same_as<param_pack_element_t<Is, P>, T> and ...)
191 typed_param_pack_helper(std::index_sequence<Is...>) { }
192};
193
194}
195
197template<typename P, typename T>
198concept typed_param_pack = requires {
199 detail::typed_param_pack_helper<P, T>(std::make_index_sequence<param_pack_size_v<P>>{});
200};
201
203template<typename P>
205
207template<typename Stream, typename T>
208concept streamable = requires (Stream &out, const T &t) {
209 { out << t } -> std::same_as<Stream&>;
210};
211
213template<typename Callback, typename T>
214concept is_invocable = requires (Callback &&callback, T value) {
215 std::invoke(std::forward<Callback>(callback), value);
216};
217
218}
Check whether.
Definition: concepts.hpp:35
Check whether.
Definition: concepts.hpp:14
Check whether.
Definition: concepts.hpp:19
Check whether.
Definition: concepts.hpp:52
Check whether types.
Definition: concepts.hpp:61
Check whether.
Definition: concepts.hpp:100
Check whether.
Definition: concepts.hpp:23
Check whether.
Definition: concepts.hpp:214
Check whether.
Definition: concepts.hpp:113
Check whether.
Definition: concepts.hpp:133
Check whether.
Definition: concepts.hpp:105
Check whether.
Definition: concepts.hpp:173
Check whether.
Definition: concepts.hpp:47
Check whether.
Definition: concepts.hpp:39
Check whether.
Definition: concepts.hpp:43
Check whether types.
Definition: concepts.hpp:56
Check whether.
Definition: concepts.hpp:27
Check whether.
Definition: concepts.hpp:204
Check whether.
Definition: concepts.hpp:208
Check whether.
Definition: concepts.hpp:198
Check whether.
Definition: concepts.hpp:31
constexpr bool is_param_pack_v
Convenience alias for is_param_pack<T>::value.
Definition: concepts.hpp:152
typename as_tuple< T >::type as_tuple_t
Convenience alias for as_tuple<T>::type.
Definition: concepts.hpp:167
‍mutable namespace
Definition: Backend.hpp:10
T(x)
std::tuple_element_t< I, detail::as_tuple_t< P > > param_pack_element_t
Returns the.
Definition: concepts.hpp:181
and
Definition: enum_ops.hpp:12
typename common_type< T, U >::type common_type_t
Convenience alias for common_type<T, U>::type.
Definition: concepts.hpp:96
and arithmetic< U > and same_signedness< T, U > U
Definition: concepts.hpp:90
constexpr std::size_t param_pack_size_v
Returns the size of a parameter pack type.
Definition: concepts.hpp:177
std::conditional_t< sizeof(T) >=sizeof(U), T, U > type
Definition: concepts.hpp:82
Computes the common type of.
Definition: concepts.hpp:69
Static cast of.
Definition: concepts.hpp:156
Checks whether.
Definition: concepts.hpp:144
Helper struct to check whether parameter pack type.
Definition: concepts.hpp:188
and(std::same_as< param_pack_element_t< Is, P >, T > and ...) typed_param_pack_helper(std
Definition: concepts.hpp:190
Helper struct for parameter packs.
Definition: concepts.hpp:138