IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
utility.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <tuple>
6
7namespace ice
8{
9
10 // Const utlities (deducing-this helpers)
11 template<typename OwnerT, typename ValueT>
13 {
14 using type = ValueT;
15 };
16
17 template<typename OwnerT, typename ValueT>
18 struct const_correct<OwnerT const, ValueT>
19 {
20 using type = ValueT const;
21 };
22
23 template<typename OwnerT, typename ValueT>
25
26 // Tuple utilities
27
28 using std::tuple;
29
30 template<typename... Tuples>
32
33 template<typename... Tuples>
34 using tuples_merged_t = typename ice::tuples_merged<Tuples...>::type;
35
36
37 template<typename... Types>
38 struct tuples_merged<std::tuple<Types...>>
39 {
40 using type = std::tuple<Types...>;
41 };
42
43 template<typename... FirstTypes, typename... SecondTypes, typename... Tail>
44 struct tuples_merged<std::tuple<FirstTypes...>, std::tuple<SecondTypes...>, Tail...>
45 {
46 using type = tuples_merged_t<std::tuple<FirstTypes..., SecondTypes...>, Tail...>;
47 };
48
49
50 template <typename T, typename... Ts>
51 struct unique_tuple : std::type_identity<T> {};
52
53 template <typename... Ts, typename U, typename... Us>
54 struct unique_tuple<std::tuple<Ts...>, U, Us...>
55 : std::conditional_t<(std::is_same_v<U, Ts> || ...)
56 , ice::unique_tuple<std::tuple<Ts...>, Us...>
57 , ice::unique_tuple<std::tuple<Ts..., U>, Us...>> {};
58
59 template <typename... Ts>
61
62 template <typename T>
64
65 template <typename... Ts>
66 struct make_unique_tuple_helper<std::tuple<Ts...>>
67 {
69 };
70
71 template<typename T>
73
74
75 // common functions
76
77 namespace concepts
78 {
79 template<typename Fn, typename T, typename O>
80 concept ComparisonFunction = requires(T&& a, O&& b) {
81 { std::forward<Fn>(std::declval<Fn>())(std::forward<T>(a), std::forward<O>(b)) } -> std::convertible_to<bool>;
82 };
83 }
84
85 template<typename Left, typename Right = Left>
86 constexpr auto equal(Left&& left, Right&& right) noexcept -> bool
87 {
88 return std::forward<Left>(left) == std::forward<Left>(right);
89 }
90
91 template<typename Left, typename Right = Left>
92 constexpr auto less(Left const& left, Right const& right) noexcept -> bool
93 {
94 return left < right;
95 }
96
97 // others
98
99 template <typename Field, typename Class>
100 constexpr auto offset_of(Field Class::* member) noexcept -> ice::uptr
101 {
102 return reinterpret_cast<ice::uptr>(
103 &(((Class*)0)->*member)
104 );
105 }
106
107 namespace concepts
108 {
109
110 template<typename T>
111 concept EnumOrIntegral = std::is_enum_v<T>
112 or (std::is_arithmetic_v<T> && not std::is_floating_point_v<T>);
113
114 } // namespace concepts
115
116} // namespace ice
Definition utility.hxx:80
Definition utility.hxx:111
Definition container_concepts.hxx:12
SPDX-License-Identifier: MIT.
Definition array.hxx:12
typename ice::unique_tuple< std::tuple<>, Ts... >::type unique_tuple_t
Definition utility.hxx:60
constexpr auto equal(Left &&left, Right &&right) noexcept -> bool
Definition utility.hxx:86
std::uintptr_t uptr
Definition types.hxx:29
constexpr auto less(Left const &left, Right const &right) noexcept -> bool
Definition utility.hxx:92
typename ice::const_correct< OwnerT, ValueT >::type const_correct_t
Definition utility.hxx:24
typename make_unique_tuple_helper< T >::type make_unique_tuple
Definition utility.hxx:72
typename ice::tuples_merged< Tuples... >::type tuples_merged_t
Definition utility.hxx:34
constexpr auto offset_of(Field Class::*member) noexcept -> ice::uptr
Definition utility.hxx:100
Represents time interval of seconds.
Definition clock_types.hxx:21
ValueT const type
Definition utility.hxx:20
Definition utility.hxx:13
ValueT type
Definition utility.hxx:14
typename ice::unique_tuple< std::tuple<>, Ts... >::type type
Definition utility.hxx:68
Definition utility.hxx:63
tuples_merged_t< std::tuple< FirstTypes..., SecondTypes... >, Tail... > type
Definition utility.hxx:46
std::tuple< Types... > type
Definition utility.hxx:40
Definition utility.hxx:31
Definition utility.hxx:51