MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
indexed_tuple.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <tuple>
6 #include <type_traits>
7 
8 namespace mbgl {
9 
10 template <class T, class... Ts>
11 struct TypeIndex;
12 
13 template <class T, class... Ts>
14 struct TypeIndex<T, T, Ts...> : std::integral_constant<std::size_t, 0> {};
15 
16 template <class T, class U, class... Ts>
17 struct TypeIndex<T, U, Ts...> : std::integral_constant<std::size_t, 1 + TypeIndex<T, Ts...>::value> {};
18 
19 template <class...> class IndexedTuple;
20 
25 template <class... Is, class... Ts>
26 class IndexedTuple<TypeList<Is...>, TypeList<Ts...>> : public std::tuple<Ts...> {
27 public:
28  static_assert(sizeof...(Is) == sizeof...(Ts), "IndexedTuple size mismatch");
29 
30  template <class I>
31  auto& get() {
32  return std::get<TypeIndex<I, Is...>::value>(*this);
33  }
34 
35  template <class I>
36  const auto& get() const {
37  return std::get<TypeIndex<I, Is...>::value>(*this);
38  }
39 
40  template <class... Us>
41  IndexedTuple(Us&&... other) : std::tuple<Ts...>(std::forward<Us>(other)...) {};
42 
43  template <class... Js, class... Us>
44  IndexedTuple<TypeList<Is..., Js...>, TypeList<Ts..., Us...>>
46  return IndexedTuple<TypeList<Is..., Js...>, TypeList<Ts..., Us...>> {
47  get<Is>()...,
48  other.template get<Js>()...
49  };
50  }
51 
52  // Help out MSVC++
54  return static_cast<const std::tuple<Ts...>&>(*this) == static_cast<const std::tuple<Ts...>&>(other);
55  }
56 
58  return !(*this == other);
59  }
60 };
61 
62 template <class, class T>
63 using ExpandToType = T;
64 
65 } // namespace mbgl
bool operator==(const IndexedTuple< TypeList< Is... >, TypeList< Ts... >> &other) const
IndexedTuple< TypeList< Is..., Js... >, TypeList< Ts..., Us... > > concat(const IndexedTuple< TypeList< Js... >, TypeList< Us... >> &other) const
bool operator!=(const IndexedTuple< TypeList< Is... >, TypeList< Ts... >> &other) const
std::unique_ptr< Expression > get(const char *value)
Definition: actor.hpp:15
T ExpandToType
Definition: tile_id.hpp:256