Wayverb
tuple_like.h
1 #pragma once
2 
3 #include <array>
4 #include <functional>
5 #include <tuple>
6 #include <type_traits>
7 
8 namespace util {
9 
10 template <typename T>
11 using decay_const_ref_t = std::remove_cv_t<std::remove_reference_t<T>>;
12 
14 
15 template <typename T>
17 
18 template <typename T, size_t I>
19 struct tuple_like_size<std::array<T, I>> final {
20  using type = std::tuple_size<std::array<T, I>>;
21 };
22 
23 template <typename... Ts>
24 struct tuple_like_size<std::tuple<Ts...>> final {
25  using type = std::tuple_size<std::tuple<Ts...>>;
26 };
27 
28 template <typename T, size_t I>
29 struct tuple_like_size<T[I]> final {
30  using type = std::integral_constant<size_t, I>;
31 };
32 
33 template <typename T>
34 using tuple_like_size_t = typename tuple_like_size<T>::type;
35 
36 template <typename T>
37 constexpr auto tuple_like_size_v = tuple_like_size_t<T>{};
38 
40 
41 template <size_t I, typename T>
42 constexpr auto tuple_like_getter(T&& t) -> decltype(std::get<I>(t)) {
43  return std::get<I>(t);
44 }
45 
46 template <size_t I, typename T, size_t Ix>
47 constexpr auto& tuple_like_getter(T (&x)[Ix]) {
48  static_assert(I < Ix, "index out of range");
49  return x[I];
50 }
51 
52 template <size_t I, typename T, size_t Ix>
53 constexpr const auto& tuple_like_getter(const T (&x)[Ix]) {
54  static_assert(I < Ix, "index out of range");
55  return x[I];
56 }
57 
58 } // namespace util
Definition: allocator.h:6
Definition: tuple_like.h:16