HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
concepts.hpp
1// Copyright Take Vos 2020-2021.
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 <type_traits>
9#include <string>
10#include <concepts>
11#include <limits>
12
13namespace tt {
14
15template<typename T>
17
18template<typename T>
19concept numeric = is_numeric_v<T>;
20
21template<typename T>
22concept numeric_integral = is_numeric_integral_v<T>;
23
24template<typename T>
25concept numeric_signed_integral = is_numeric_signed_integral_v<T>;
26
27template<typename T>
28concept numeric_unsigned_integral = is_numeric_unsigned_integral_v<T>;
29
30template<typename T>
31concept arithmetic = std::is_arithmetic_v<T>;
32
33template<typename T>
34concept pointer = std::is_pointer_v<T>;
35
36template<typename T>
37concept reference = std::is_reference_v<T>;
38
39template<typename T, typename O>
40concept same = std::is_same_v<T, O>;
41
42template<typename T>
43concept lvalue_reference = std::is_lvalue_reference_v<T>;
44
45template<typename T>
46concept rvalue_reference = std::is_rvalue_reference_v<T>;
47
48template<typename BaseType, typename DerivedType>
49concept base_of = std::is_base_of_v<BaseType, DerivedType>;
50
51template<typename BaseType, typename DerivedType>
52concept decayed_base_of = is_decayed_base_of_v<BaseType, DerivedType>;
53
54template<typename DerivedType, typename BaseType>
55concept derived_from = tt::is_derived_from_v<DerivedType, BaseType>;
56
57template<typename DerivedType, typename BaseType>
58concept decayed_derived_from = tt::is_decayed_derived_from_v<DerivedType, BaseType>;
59
60template<typename BaseType, typename DerivedType>
61concept strict_base_of = base_of<BaseType, DerivedType> && !std::same_as<BaseType, DerivedType>;
62
63template<typename BaseType, typename DerivedType>
64concept strict_derived_from = derived_from<BaseType, DerivedType> && !std::same_as<BaseType, DerivedType>;
65
66template<typename T>
67concept to_stringable = requires(T v)
68{
69 {
70 to_string(v)
71 } -> std::convertible_to<std::string>;
72};
73
74template<typename T>
75concept from_stringable = requires()
76{
77 {
78 from_string<T>(std::string_view{})
79 } -> std::convertible_to<T>;
80};
81
82template<typename From, typename To>
83concept static_castableable = requires(From v)
84{
85 {
86 static_cast<To>(v)
87 } -> std::convertible_to<To>;
88};
89
90template<typename T>
91concept sizeable = requires(T v)
92{
93 {
94 size(v)
95 } -> std::convertible_to<size_t>;
96};
97
102template<typename T>
103concept scoped_enum = std::is_enum_v<T>;
104
105} // namespace tt
Definition concepts.hpp:16
Definition concepts.hpp:19
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
Definition concepts.hpp:46
Definition concepts.hpp:49
Definition concepts.hpp:52
Definition concepts.hpp:55
Definition concepts.hpp:58
Definition concepts.hpp:61
Definition concepts.hpp:64
Definition concepts.hpp:67
Definition concepts.hpp:75
Definition concepts.hpp:83
Definition concepts.hpp:91
Concept for std::is_scoped_enum_v<T>.
Definition concepts.hpp:103