Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
pair.hpp
Go to the documentation of this file.
1
6#pragma once
7
8namespace flecs {
9
10namespace _ {
11 struct pair_base { };
12} // namespace _
13
14
35template <typename First, typename Second>
37 using type = conditional_t<!is_empty<First>::value || is_empty<Second>::value, First, Second>;
38 using first = First;
39 using second = Second;
45 pair(type& v) : ref_(v) { }
46
52 pair(const type& v) : ref_(const_cast<type&>(v)) { }
53
55 operator type&() {
56 return ref_;
57 }
58
60 operator const type&() const {
61 return ref_;
62 }
63
66 return &ref_;
67 }
68
70 const type* operator->() const {
71 return &ref_;
72 }
73
76 return ref_;
77 }
78
80 const type& operator*() const {
81 return ref_;
82 }
83
84private:
85 type& ref_;
86};
87
89template <typename First, typename Second, if_t<is_empty<First>::value> = 0>
91
93template <typename T>
94using raw_type_t = remove_pointer_t<remove_reference_t<T>>;
95
97template <typename T>
98struct is_pair {
99 static constexpr bool value = is_base_of_v<_::pair_base, raw_type_t<T>>;
100};
101
103template <typename T>
104inline constexpr bool is_pair_v = is_pair<T>::value;
105
107template <typename P>
109
111template <typename P>
113
115template <typename P>
117
119template <typename T, typename U = int>
121
122template <typename T>
123struct actual_type<T, if_not_t< is_pair<T>::value >> {
124 using type = T;
125};
126
127template <typename T>
128struct actual_type<T, if_t< is_pair<T>::value >> {
129 using type = pair_type_t<T>;
130};
131
132template <typename T>
133using actual_type_t = typename actual_type<T>::type;
134
135
137template<typename T>
138struct base_type {
139 using type = decay_t< actual_type_t<T> >;
140};
141
143template <typename T>
144using base_type_t = typename base_type<T>::type;
145
146
148template<typename T>
150 using type = remove_pointer_t< remove_reference_t< actual_type_t<T> > >;
151};
152
154template <typename T>
155using base_arg_type_t = typename base_arg_type<T>::type;
156
157
159template <typename T>
160struct is_actual {
161 static constexpr bool value = is_same_v<T, actual_type_t<T>>;
162};
163
165template <typename T>
166inline constexpr bool is_actual_v = is_actual<T>::value;
167
170} // namespace flecs
constexpr bool is_pair_v
Convenience variable template to check if a type is a pair.
Definition pair.hpp:104
transcribe_cvp_t< remove_reference_t< P >, typename raw_type_t< P >::type > pair_type_t
Get the pair::type type from a pair while preserving cv qualifiers and pointer type.
Definition pair.hpp:116
constexpr bool is_actual_v
Convenience variable template to check if a type is its own actual type.
Definition pair.hpp:166
transcribe_cv_t< remove_reference_t< P >, typename raw_type_t< P >::second > pair_second_t
Get pair::second from a pair while preserving cv qualifiers.
Definition pair.hpp:112
remove_pointer_t< remove_reference_t< T > > raw_type_t
Get the raw type by removing pointer and reference qualifiers.
Definition pair.hpp:94
typename base_type< T >::type base_type_t
Convenience alias for base_type.
Definition pair.hpp:144
typename base_arg_type< T >::type base_arg_type_t
Convenience alias for base_arg_type.
Definition pair.hpp:155
transcribe_cv_t< remove_reference_t< P >, typename raw_type_t< P >::first > pair_first_t
Get pair::first from a pair while preserving cv qualifiers.
Definition pair.hpp:108
Get the actual type from a regular type or pair.
Definition pair.hpp:120
Get the type without * and & (retains const, which is useful for function args).
Definition pair.hpp:149
Get the type without const, *, and &.
Definition pair.hpp:138
Test if a type is the same as its actual type.
Definition pair.hpp:160
Test if a type is a pair.
Definition pair.hpp:98
Type that represents a pair.
Definition pair.hpp:36
Second second
The second element type of the pair.
Definition pair.hpp:39
type & operator*()
Dereference operator for mutable access.
Definition pair.hpp:75
pair(const type &v)
Construct pair from a const reference to the storage type.
Definition pair.hpp:52
pair(type &v)
Construct pair from a mutable reference to the storage type.
Definition pair.hpp:45
type * operator->()
Arrow operator for mutable access.
Definition pair.hpp:65
conditional_t<!is_empty< First >::value||is_empty< Second >::value, First, Second > type
The storage type of the pair.
Definition pair.hpp:37
const type & operator*() const
Dereference operator for const access.
Definition pair.hpp:80
First first
The first element type of the pair.
Definition pair.hpp:38
const type * operator->() const
Arrow operator for const access.
Definition pair.hpp:70
Type class.
Definition type.hpp:21
enable_if_t< false==V, int > if_not_t
Convenience enable_if alias for negated conditions.
Definition utils.hpp:172
enable_if_t< V, int > if_t
Convenience enable_if alias using int as default type.
Definition utils.hpp:168
transcribe_cv_t< Src, transcribe_pointer_t< Src, Dst > > transcribe_cvp_t
Apply const, volatile, and pointer from source type to destination type.
Definition utils.hpp:156
transcribe_const_t< Src, transcribe_volatile_t< Src, Dst > > transcribe_cv_t
Apply const and volatile from source type to destination type.
Definition utils.hpp:148