sandbox
Loading...
Searching...
No Matches
concepts.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_UTILITY_CONCEPTS_HPP_
3#define LIBSBX_UTILITY_CONCEPTS_HPP_
4
5#include <type_traits>
6
7namespace sbx::utility {
8
9template<typename Type>
10struct is_always_false : std::false_type { };
11
12template<typename Type>
13inline constexpr auto is_always_false_v = is_always_false<Type>::value;
14
15template<typename Type>
16concept always_false = is_always_false_v<Type>;
17
18template<typename Type, typename... TypeList>
19struct is_one_of : std::false_type { };
20
21template<typename Type, typename... TypeList>
22struct is_one_of<Type, Type, TypeList...> : std::true_type { };
23
24template<typename Type, typename Head, typename... Rest>
25struct is_one_of<Type, Head, Rest...> : is_one_of<Type, Rest...> { };
26
27template<typename Type, typename... TypeList>
28inline constexpr auto is_one_of_v = is_one_of<Type, TypeList...>::value;
29
30template<typename Type, typename... TypeList>
31concept one_of = is_one_of_v<Type, TypeList...>;
32
33template<typename Type, typename... TypeList>
34concept none_of = !is_one_of_v<Type, TypeList...>;
35
36template<typename T, typename... Rest>
37struct are_all_unique : std::bool_constant<!(std::is_same_v<T, Rest> || ...) && are_all_unique<Rest...>::value>{};
38
39template<typename T>
40struct are_all_unique<T> : std::true_type { };
41
42template<typename... TypeList>
43inline constexpr auto are_all_unique_v = are_all_unique<TypeList...>::value;
44
45template<typename... TypeList>
46concept all_unique = are_all_unique_v<TypeList...>;
47
48template<typename Type, typename... TypeList>
49struct is_convertible_to_one_of : std::false_type{ };
50
51template<typename Type, typename... TypeList>
52struct is_convertible_to_one_of<Type, Type, TypeList...> : std::true_type { };
53
54template<typename Type, typename Head, typename... Rest>
55struct is_convertible_to_one_of<Type, Head, Rest...> : std::conditional_t<std::is_convertible_v<Type, Head>, std::true_type, is_convertible_to_one_of<Type, Rest...>> { };
56
57template<typename Type, typename... TypeList>
58inline constexpr auto is_convertible_to_one_of_v = is_convertible_to_one_of<Type, TypeList...>::value;
59
60template<typename Type, typename... TypeList>
61concept convertible_to_one_of = is_convertible_to_one_of_v<Type, TypeList...>;
62
63
64template<typename Type, typename Base>
65concept implements = !std::is_abstract_v<Type> && std::has_virtual_destructor_v<Base> && std::is_base_of_v<Base, Type>;
66
67template<typename Type>
68struct is_complete : std::bool_constant<(sizeof(Type) != 0 && !std::is_void_v<Type>)> { };
69
70template<typename Type>
71inline constexpr auto is_complete_v = is_complete<Type>::value;
72
73template<typename Type>
74concept complete = is_complete_v<Type>;
75
76template<typename To, typename From>
78 using type = std::remove_const_t<To>;
79}; // struct constness_as
80
81template<typename To, typename From>
82struct constness_as<To, const From> {
83 using type = const To;
84}; // struct constness_as
85
86template<typename To, typename From>
87using constness_as_t = typename constness_as<To, From>::type;
88
89} // namespace sbx::utility
90
91#endif // LIBSBX_UTILITY_CONCEPTS_HPP_
Definition: concepts.hpp:37
Definition: concepts.hpp:77
Definition: concepts.hpp:10
Definition: concepts.hpp:68
Definition: concepts.hpp:49
Definition: concepts.hpp:19