19 #ifndef INCLUDED_TypeKeyed_h_GUID_49539B71_1F6F_4A84_B681_4FD65F87A2A8
20 #define INCLUDED_TypeKeyed_h_GUID_49539B71_1F6F_4A84_B681_4FD65F87A2A8
32 #include <type_traits>
39 namespace typekeyed_detail {
43 template <
typename Derived,
typename Key>
51 using type =
typename Derived::key_types;
56 template <
typename Derived>
61 template <
typename Derived,
typename Key>
66 template <
typename Derived,
typename Key>
71 template <
typename Derived,
typename Key>
76 template <
typename Derived,
typename Key>
77 using ref_type_at_key =
78 std::add_lvalue_reference<value_type_at_key<Derived, Key>>;
82 template <
typename Derived,
typename Key>
83 using rref_type_at_key =
84 std::add_rvalue_reference<value_type_at_key<Derived, Key>>;
88 template <
typename Derived,
typename Key>
89 using cref_type_at_key = std::add_lvalue_reference<
103 static_assert(valid_key<Derived, Key>::value,
104 "Key type not found in the list!");
105 using reference =
typename ref_type_at_key<Derived, Key>::type;
106 using rvalue_reference =
107 typename rref_type_at_key<Derived, Key>::type;
108 using const_reference =
109 typename cref_type_at_key<Derived, Key>::type;
110 using Index = index<Derived, Key>;
112 static const_reference
114 static rvalue_reference
119 template <
typename Key,
typename Derived>
120 typename ref_type_at_key<Derived, Key>::type
124 template <
typename Key,
typename Derived>
125 typename rref_type_at_key<Derived, Key>::type
129 template <
typename Key,
typename Derived>
130 typename cref_type_at_key<Derived, Key>::type
140 using DerivedType = Derived;
144 template <
typename Key>
145 typename typekeyed_detail::ref_type_at_key<Derived, Key>::type
146 get(Key
const * =
nullptr) {
147 return typekeyed_detail::get<Key>(*this);
152 template <
typename Key>
153 typename typekeyed_detail::cref_type_at_key<Derived, Key>::type
154 get(Key
const * =
nullptr)
const {
155 return typekeyed_detail::cget<Key>(*this);
160 DerivedType &derived() {
return *
static_cast<DerivedType *
>(
this); }
163 DerivedType
const &derived()
const {
164 return *
static_cast<DerivedType
const *
>(
this);
168 DerivedType
const &const_derived()
const {
169 return *
static_cast<DerivedType
const *
>(
this);
173 template <
typename,
typename>
174 friend struct typekeyed_detail::ValueAccessor;
177 namespace typekeyed_detail {
178 template <
typename Derived,
typename Key>
179 inline typename ref_type_at_key<Derived, Key>::type
180 ValueAccessor<Derived, Key>::get_reference(TypeKeyedBase<Derived> &c) {
181 return std::get<Index::value>(c.derived().nested_container());
183 template <
typename Derived,
typename Key>
184 inline typename cref_type_at_key<Derived, Key>::type
185 ValueAccessor<Derived, Key>::get_const_reference(
186 TypeKeyedBase<Derived>
const &c) {
187 return std::get<Index::value>(c.derived().nested_container());
189 template <
typename Derived,
typename Key>
190 inline typename rref_type_at_key<Derived, Key>::type
191 ValueAccessor<Derived, Key>::get_rvalue_reference(
192 TypeKeyedBase<Derived> &&c) {
193 return std::forward<rvalue_reference>(
194 std::get<Index::value>(c.derived().nested_container()));
198 template <
typename Key,
typename Derived>
199 inline typename ref_type_at_key<Derived, Key>::type
201 static_assert(valid_key<Derived, Key>::value,
202 "Key type not found in the list!");
207 template <
typename Key,
typename Derived>
208 inline typename rref_type_at_key<Derived, Key>::type
210 static_assert(valid_key<Derived, Key>::value,
211 "Key type not found in the list!");
212 return std::forward<rref_type_at_key<Derived, Key>>(
219 template <
typename Key,
typename Derived>
220 inline typename cref_type_at_key<Derived, Key>::type
222 static_assert(valid_key<Derived, Key>::value,
223 "Key type not found in the list!");
233 template <
typename Key,
typename Derived>
234 inline typename typekeyed_detail::ref_type_at_key<Derived, Key>::type
236 return typekeyed_detail::get<Key>(c);
243 template <
typename Key,
typename Derived>
244 inline typename typekeyed_detail::rref_type_at_key<Derived, Key>::type
246 return std::forward<typekeyed_detail::rref_type_at_key<Derived, Key>>(
247 typekeyed_detail::rget<Key>(c));
256 template <
typename Key,
typename Derived>
257 inline typename typekeyed_detail::cref_type_at_key<Derived, Key>::type
259 return typekeyed_detail::cget<Key>(c);
263 #endif // INCLUDED_TypeKeyed_h_GUID_49539B71_1F6F_4A84_B681_4FD65F87A2A8
apply_list< quote< or_ >, transform< Haystack, detail::is_< Needle >>> contains
Determines if type Needle is in the list Haystack - is an alias for a type that inherits std::true_ty...
The main namespace for all C++ elements of the framework, internal and external.
rref_type_at_key< Derived, Key >::type rget(TypeKeyedBase< Derived > &&c)
cref_type_at_key< Derived, Key >::type cget(TypeKeyedBase< Derived > const &c)
typekeyed_detail::rref_type_at_key< Derived, Key >::type rget(TypeKeyedBase< Derived > &&c)
t_< detail::find_first_impl< Needle, 0, List >> find_first
Returns the zero-based index of the first instance of Needle in List. Will fail to compile if not fou...
typename T::type t_
A convenience alias template to extract the nested type within the supplied T.
typekeyed_detail::cref_type_at_key< Derived, Key >::type cget(TypeKeyedBase< Derived > const &c)