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 { inline namespace v1 {
19
20template<typename T>
22
23template<typename T>
25
26template<typename T>
28
29template<typename T>
31
32template<typename T>
33concept arithmetic = std::is_arithmetic_v<T>;
34
35template<typename T>
36concept lvalue_reference = std::is_lvalue_reference_v<T>;
37
38template<typename T>
39concept rvalue_reference = std::is_rvalue_reference_v<T>;
40
41template<typename T>
42concept trivially_copyable = std::is_trivially_copyable_v<T>;
43
48template<typename Context, typename Expected>
49concept different_from = not std::same_as<Context, Expected>;
50
55template<typename Context, typename Expected>
56concept incompatible_with = not std::convertible_to<Context, Expected>;
57
58template<typename BaseType, typename DerivedType>
59concept base_of = std::is_base_of_v<BaseType, DerivedType>;
60
61template<typename BaseType, typename DerivedType>
63
64template<typename Context, typename Expected>
66
67template<typename DerivedType, typename BaseType>
69
70template<typename BaseType, typename DerivedType>
71concept strict_base_of = base_of<BaseType, DerivedType> && !std::same_as<BaseType, DerivedType>;
72
73template<typename BaseType, typename DerivedType>
74concept strict_derived_from = derived_from<BaseType, DerivedType> && !std::same_as<BaseType, DerivedType>;
75
76template<typename T>
77concept pre_incrementable = requires(T a) {
78 {
79 ++a
80 };
81};
82
83template<typename T>
84concept pre_decrementable = requires(T a) {
85 {
86 --a
87 };
88};
89
90template<typename T>
91concept to_stringable = requires(T v) {
92 {
93 to_string(v)
94 } -> std::convertible_to<std::string>;
95};
96
97template<typename T>
98concept from_stringable = requires() {
99 {
100 from_string<T>(std::string_view{})
101 } -> std::convertible_to<T>;
102};
103
104template<typename From, typename To>
105concept static_castableable = requires(From v) {
106 {
107 static_cast<To>(v)
108 } -> std::convertible_to<To>;
109};
110
111template<typename T>
112concept sizeable = requires(T v) {
113 {
114 size(v)
115 } -> std::convertible_to<std::size_t>;
116};
117
118template<typename T>
119concept scalar = std::is_scalar_v<T>;
120
125template<typename T>
126concept scoped_enum = std::is_enum_v<T>;
127
128template<typename Context, typename... Expected>
129concept same_as_any = (std::same_as<Context, Expected> or...);
130
135template<typename Context, typename Expected, typename... OtherExpected>
136concept forward_of = is_forward_of_v<Context, Expected, OtherExpected...>;
137
142template<typename Context>
144
147template<typename T>
148concept nullable = requires (T &a) { a = nullptr; };
149
154template<typename T>
155concept dereferenceable = std::is_pointer_v<T> or requires (T &a)
156{
157 a.operator*();
158 a.operator->();
159};
160
163template<typename T>
165
166}} // namespace hi::v1
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
Definition concepts.hpp:21
Definition concepts.hpp:24
Definition concepts.hpp:27
Definition concepts.hpp:30
Definition concepts.hpp:33
Definition concepts.hpp:36
Definition concepts.hpp:39
Definition concepts.hpp:42
Different from.
Definition concepts.hpp:49
Incompatible with another type.
Definition concepts.hpp:56
Definition concepts.hpp:59
Definition concepts.hpp:62
Definition concepts.hpp:65
Definition concepts.hpp:68
Definition concepts.hpp:71
Definition concepts.hpp:74
Definition concepts.hpp:77
Definition concepts.hpp:84
Definition concepts.hpp:91
Definition concepts.hpp:98
Definition concepts.hpp:105
Definition concepts.hpp:112
Definition concepts.hpp:119
Concept for std::is_scoped_enum_v<T>.
Definition concepts.hpp:126
Definition concepts.hpp:129
True if T is a forwarded type of Forward.
Definition concepts.hpp:136
An array of this type will implicitly create objects within that array.
Definition concepts.hpp:143
True if T can be assigned with a nullptr.
Definition concepts.hpp:148
True if T is dereferenceable.
Definition concepts.hpp:155
True if T is both nullable and dereferenceable.
Definition concepts.hpp:164