HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
concepts.hpp
1// Copyright Take Vos 2020-2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "type_traits.hpp"
8#include "../macros.hpp"
9#include <type_traits>
10#include <string>
11#include <concepts>
12#include <limits>
13#include <coroutine>
14#include <chrono>
15
16hi_export_module(hikogui.utility.concepts);
17
18hi_export namespace hi {
19inline namespace v1 {
20
21template<typename T>
22concept numeric = is_numeric_v<T>;
23
24template<typename T>
25concept numeric_integral = is_numeric_integral_v<T>;
26
27template<typename T>
28concept numeric_signed_integral = is_numeric_signed_integral_v<T>;
29
30template<typename T>
31concept numeric_unsigned_integral = is_numeric_unsigned_integral_v<T>;
32
33template<typename T>
34concept arithmetic = std::is_arithmetic_v<T>;
35
36template<typename T>
37concept lvalue_reference = std::is_lvalue_reference_v<T>;
38
39template<typename T>
40concept rvalue_reference = std::is_rvalue_reference_v<T>;
41
42template<typename T>
43concept trivially_copyable = std::is_trivially_copyable_v<T>;
44
49template<typename Context, typename Expected>
50concept different_from = not std::same_as<Context, Expected>;
51
56template<typename Context, typename Expected>
57concept incompatible_with = not std::convertible_to<Context, Expected>;
58
59template<typename BaseType, typename DerivedType>
60concept base_of = std::is_base_of_v<BaseType, DerivedType>;
61
62template<typename BaseType, typename DerivedType>
63concept decayed_base_of = is_decayed_base_of_v<BaseType, DerivedType>;
64
65template<typename Context, typename Expected>
66concept derived_from = hi::is_derived_from_v<Context, Expected>;
67
68template<typename DerivedType, typename BaseType>
69concept decayed_derived_from = hi::is_decayed_derived_from_v<DerivedType, BaseType>;
70
71template<typename BaseType, typename DerivedType>
72concept strict_base_of = base_of<BaseType, DerivedType> && !std::same_as<BaseType, DerivedType>;
73
74template<typename BaseType, typename DerivedType>
75concept strict_derived_from = derived_from<BaseType, DerivedType> && !std::same_as<BaseType, DerivedType>;
76
77template<typename T>
78concept pre_incrementable = requires(T a) {
79 {
80 ++a
81 };
82};
83
84template<typename T>
85concept pre_decrementable = requires(T a) {
86 {
87 --a
88 };
89};
90
91template<typename T>
92concept to_stringable = requires(T v) {
93 {
94 to_string(v)
95 } -> std::convertible_to<std::string>;
96};
97
98template<typename T>
99concept from_stringable = requires() {
100 {
101 from_string<T>(std::string_view{})
102 } -> std::convertible_to<T>;
103};
104
105template<typename From, typename To>
106concept static_castableable = requires(From v) {
107 {
108 static_cast<To>(v)
109 } -> std::convertible_to<To>;
110};
111
112template<typename T>
113concept sizeable = requires(T v) {
114 {
115 size(v)
116 } -> std::convertible_to<std::size_t>;
117};
118
119template<typename T>
120concept scalar = std::is_scalar_v<T>;
121
126template<typename T>
127concept scoped_enum = std::is_enum_v<T>;
128
129template<typename Context, typename... Expected>
130concept same_as_any = (std::same_as<Context, Expected> or ...);
131
136template<typename Context, typename Expected, typename... OtherExpected>
137concept forward_of = is_forward_of_v<Context, Expected, OtherExpected...>;
138
143template<typename Context>
144concept byte_like = is_byte_like_v<Context>;
145
148template<typename T>
149concept nullable = requires(T& a) { a = nullptr; };
150
155template<typename T>
156concept dereferenceable = std::is_pointer_v<T> or requires(T& a) {
157 a.operator*();
158 a.operator->();
159};
160
163template<typename T>
165
166} // namespace v1
167} // namespace hi::v1
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition concepts.hpp:22
Definition concepts.hpp:25
Definition concepts.hpp:28
Definition concepts.hpp:31
Definition concepts.hpp:34
Definition concepts.hpp:37
Definition concepts.hpp:40
Definition concepts.hpp:43
Different from.
Definition concepts.hpp:50
Incompatible with another type.
Definition concepts.hpp:57
Definition concepts.hpp:60
Definition concepts.hpp:63
Definition concepts.hpp:66
Definition concepts.hpp:69
Definition concepts.hpp:72
Definition concepts.hpp:75
Definition concepts.hpp:78
Definition concepts.hpp:85
Definition concepts.hpp:92
Definition concepts.hpp:99
Definition concepts.hpp:106
Definition concepts.hpp:113
Definition concepts.hpp:120
Concept for std::is_scoped_enum_v<T>.
Definition concepts.hpp:127
Definition concepts.hpp:130
True if T is a forwarded type of Forward.
Definition concepts.hpp:137
An array of this type will implicitly create objects within that array.
Definition concepts.hpp:144
True if T can be assigned with a nullptr.
Definition concepts.hpp:149
True if T is dereferenceable.
Definition concepts.hpp:156
True if T is both nullable and dereferenceable.
Definition concepts.hpp:164