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
12namespace tt {
13
14template<typename T>
15concept arithmetic = std::is_arithmetic_v<T>;
16
17template<typename T>
18concept pointer = std::is_pointer_v<T>;
19
20template<typename T>
21concept reference = std::is_reference_v<T>;
22
23template<typename T, typename O>
24concept same = std::is_same_v<T, O>;
25
26template<typename T>
27concept lvalue_reference = std::is_lvalue_reference_v<T>;
28
29template<typename T>
30concept rvalue_reference = std::is_rvalue_reference_v<T>;
31
32template<typename BaseType, typename DerivedType>
33concept base_of = std::is_base_of_v<BaseType, DerivedType>;
34
35template<typename BaseType, typename DerivedType>
36concept decayed_base_of = is_decayed_base_of_v<BaseType, DerivedType>;
37
38template<typename DerivedType, typename BaseType>
39concept derived_from = tt::is_derived_from_v<DerivedType, BaseType>;
40
41template<typename DerivedType, typename BaseType>
42concept decayed_derived_from = tt::is_decayed_derived_from_v<DerivedType, BaseType>;
43
44template<typename BaseType, typename DerivedType>
45concept strict_base_of = base_of<BaseType, DerivedType> && !std::same_as<BaseType, DerivedType>;
46
47template<typename BaseType, typename DerivedType>
48concept strict_derived_from = derived_from<BaseType, DerivedType> && !std::same_as<BaseType, DerivedType>;
49
50template<typename T>
51concept to_stringable = requires(T v)
52{
53 {
54 to_string(v)
55 }
56 ->std::convertible_to<std::string>;
57};
58
59template<typename T>
60concept from_stringable = requires()
61{
62 {
63 from_string<T>(std::string_view{})
64 }
65 ->std::convertible_to<T>;
66};
67
68template<typename From, typename To>
69concept static_castableable = requires(From v)
70{
71 {
72 static_cast<To>(v)
73 }
74 ->std::convertible_to<To>;
75};
76
77template<typename T>
78concept sizeable = requires(T v)
79{
80 {
81 size(v)
82 }
83 ->std::convertible_to<size_t>;
84};
85
86template<typename T>
87concept atomical = tt::may_be_atomic_v<T>;
88
89} // namespace tt
Definition concepts.hpp:15
Definition concepts.hpp:18
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
Definition concepts.hpp:45
Definition concepts.hpp:48
Definition concepts.hpp:51
Definition concepts.hpp:60
Definition concepts.hpp:69
Definition concepts.hpp:78
Definition concepts.hpp:87