Flecs: include/flecs/addons/cpp/pair.hpp Source File
Description: A fast entity component system (ECS) for C & C++

| 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
5
6#pragma once
7
8namespace flecs {
9
10namespace _ {
11 struct pair_base { };
12} // namespace _
13
14
22
35template <typename First, typename Second>
36 struct pair : _::pair_base {
37 using type = conditional_t<!is_empty<First>::value || is_empty<Second>::value, First, Second>;
38 using first = First;
39 using second = Second;
40
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
65 type* operator->() {
66 return &ref_;
67 }
68
70 const type* operator->() const {
71 return &ref_;
72 }
73
75 type& operator*() {
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>
90 using pair_object = pair<First, Second>;
91
93template <typename T>
94 using raw_type_t = remove_pointer_t<remove_reference_t<T>>;
95
97template <typename T>
98 struct is_pair {
99 static constexpr bool value = is_base_of_v<_::pair_base, raw_type_t<T>>;
100};
101
103template <typename T>
104 inline constexpr bool is_pair_v = is_pair<T>::value;
105
107template <typename P>
108 using pair_first_t = transcribe_cv_t<remove_reference_t<P>, typename raw_type_t<P>::first>;
109
111template <typename P>
112 using pair_second_t = transcribe_cv_t<remove_reference_t<P>, typename raw_type_t<P>::second>;
113
115template <typename P>
116 using pair_type_t = transcribe_cvp_t<remove_reference_t<P>, typename raw_type_t<P>::type>;
117
119template <typename T, typename U = int>
120 struct actual_type;
121
122template <typename T>
123 struct actual_type<T, if_not_t< is_pair<T>::value >> {
124 using type = T;
125};
126
127template <typename T>
128 struct 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>
138 struct base_type {
139 using type = decay_t< actual_type_t<T> >;
140};
141
143template <typename T>
144 using base_type_t = typename base_type<T>::type;
145
146
148template<typename T>
149 struct base_arg_type {
150 using type = remove_pointer_t< remove_reference_t< actual_type_t<T> > >;
151};
152
154template <typename T>
155 using base_arg_type_t = typename base_arg_type<T>::type;
156
157
159template <typename T>
160 struct is_actual {
161 static constexpr bool value = is_same_v<T, actual_type_t<T>>;
162};
163
165template <typename T>
166 inline constexpr bool is_actual_v = is_actual<T>::value;
167
169
170} // namespace flecs
flecs::pair_object
pair< First, Second > pair_object
Alias for pair when First is empty (tag).
Definition pair.hpp:90
flecs::is_pair_v
constexpr bool is_pair_v
Convenience variable template to check if a type is a pair.
Definition pair.hpp:104
flecs::pair_type_t
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
flecs::is_actual_v
constexpr bool is_actual_v
Convenience variable template to check if a type is its own actual type.
Definition pair.hpp:166
flecs::pair_second_t
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
flecs::raw_type_t
remove_pointer_t< remove_reference_t< T > > raw_type_t
Get the raw type by removing pointer and reference qualifiers.
Definition pair.hpp:94
flecs::base_type_t
typename base_type< T >::type base_type_t
Convenience alias for base_type.
Definition pair.hpp:144
flecs::base_arg_type_t
typename base_arg_type< T >::type base_arg_type_t
Convenience alias for base_arg_type.
Definition pair.hpp:155
flecs::pair_first_t
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
flecs::_
Int to enum.
Definition component.hpp:18
flecs::_::pair_base
Definition pair.hpp:11
flecs::actual_type
Get the actual type from a regular type or pair.
Definition pair.hpp:120
flecs::base_arg_type
Get the type without * and & (retains const, which is useful for function args).
Definition pair.hpp:149
flecs::base_type
Get the type without const, *, and &.
Definition pair.hpp:138
flecs::is_actual
Test if a type is the same as its actual type.
Definition pair.hpp:160
flecs::is_pair
Test if a type is a pair.
Definition pair.hpp:98
flecs::pair
Type that represents a pair.
Definition pair.hpp:36
flecs::pair::second
Second second
The second element type of the pair.
Definition pair.hpp:39
flecs::pair::operator*
type & operator*()
Dereference operator for mutable access.
Definition pair.hpp:75
flecs::pair::pair
pair(const type &v)
Construct pair from a const reference to the storage type.
Definition pair.hpp:52
flecs::pair::pair
pair(type &v)
Construct pair from a mutable reference to the storage type.
Definition pair.hpp:45
flecs::pair::operator->
type * operator->()
Arrow operator for mutable access.
Definition pair.hpp:65
flecs::pair::type
conditional_t<!is_empty< First >::value||is_empty< Second >::value, First, Second > type
The storage type of the pair.
Definition pair.hpp:37
flecs::pair::operator*
const type & operator*() const
Dereference operator for const access.
Definition pair.hpp:80
flecs::pair::first
First first
The first element type of the pair.
Definition pair.hpp:38
flecs::pair::operator->
const type * operator->() const
Arrow operator for const access.
Definition pair.hpp:70
flecs::type
Type class.
Definition type.hpp:21
flecs::if_not_t
enable_if_t< false==V, int > if_not_t
Convenience enable_if alias for negated conditions.
Definition utils.hpp:172
flecs::if_t
enable_if_t< V, int > if_t
Convenience enable_if alias using int as default type.
Definition utils.hpp:168
flecs::transcribe_cvp_t
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
flecs::transcribe_cv_t
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