Flecs v3.2
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} // _
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;
40
41 pair(type& v) : ref_(v) { }
42
43 // This allows the class to be used as a temporary object
44 pair(const type& v) : ref_(const_cast<type&>(v)) { }
45
46 operator type&() {
47 return ref_;
48 }
49
50 operator const type&() const {
51 return ref_;
52 }
53
54 type* operator->() {
55 return &ref_;
56 }
57
58 const type* operator->() const {
59 return &ref_;
60 }
61
62 type& operator*() {
63 return ref_;
64 }
65
66 const type& operator*() const {
67 return ref_;
68 }
69
70private:
71 type& ref_;
72};
73
74template <typename First, typename Second, if_t<is_empty<First>::value> = 0>
76
77template <typename T>
78using raw_type_t = remove_pointer_t<remove_reference_t<T>>;
79
81template <typename T>
82struct is_pair {
83 static constexpr bool value = is_base_of<_::pair_base, raw_type_t<T> >::value;
84};
85
87template <typename P>
88using pair_first_t = transcribe_cv_t<remove_reference_t<P>, typename raw_type_t<P>::first>;
89
91template <typename P>
92using pair_second_t = transcribe_cv_t<remove_reference_t<P>, typename raw_type_t<P>::second>;
93
95template <typename P>
96using pair_type_t = transcribe_cvp_t<remove_reference_t<P>, typename raw_type_t<P>::type>;
97
99template <typename T, typename U = int>
101
102template <typename T>
103struct actual_type<T, if_not_t< is_pair<T>::value >> {
104 using type = T;
105};
106
107template <typename T>
108struct actual_type<T, if_t< is_pair<T>::value >> {
109 using type = pair_type_t<T>;
110};
111
112template <typename T>
113using actual_type_t = typename actual_type<T>::type;
114
115
116// Get type without const, *, &
117template<typename T>
118struct base_type {
119 using type = decay_t< actual_type_t<T> >;
120};
121
122template <typename T>
123using base_type_t = typename base_type<T>::type;
124
125
126// Get type without *, & (retains const which is useful for function args)
127template<typename T>
129 using type = remove_pointer_t< remove_reference_t< actual_type_t<T> > >;
130};
131
132template <typename T>
133using base_arg_type_t = typename base_arg_type<T>::type;
134
135
136// Test if type is the same as its actual type
137template <typename T>
138struct is_actual {
139 static constexpr bool value =
140 std::is_same<T, actual_type_t<T> >::value && !is_enum<T>::value;
141};
142
143} // flecs
transcribe_cvp_t< remove_reference_t< P >, typename raw_type_t< P >::type > pair_type_t
Get pair::type type from pair while preserving cv qualifiers and pointer type.
Definition pair.hpp:96
transcribe_cv_t< remove_reference_t< P >, typename raw_type_t< P >::second > pair_second_t
Get pair::second from pair while preserving cv qualifiers.
Definition pair.hpp:92
transcribe_cv_t< remove_reference_t< P >, typename raw_type_t< P >::first > pair_first_t
Get pair::first from pair while preserving cv qualifiers.
Definition pair.hpp:88
Get actual type from a regular type or pair.
Definition pair.hpp:100
Test if type is a pair.
Definition pair.hpp:82
Type that represents a pair.
Definition pair.hpp:36