Wayverb
map.h
1 #pragma once
2 
3 #include "utilities/is_tuple.h"
4 #include "utilities/tuple_like.h"
5 
6 namespace util {
7 
8 // arrays
9 
10 template <typename Func, typename T, size_t... Ix>
11 constexpr auto map(Func&& func,
12  T&& t,
13  std::index_sequence<Ix...>,
14  std::enable_if_t<!is_tuple_v<std::decay_t<T>>, int> = 0) {
15  using value_type = decltype(func(tuple_like_getter<0>(t)));
16  return std::array<value_type, sizeof...(Ix)>{
17  {func(tuple_like_getter<Ix>(t))...}};
18 }
19 
20 template <typename Func, typename T, size_t... Ix>
21 constexpr auto map(Func&& func,
22  T&& t,
23  std::index_sequence<Ix...>,
24  std::enable_if_t<is_tuple_v<std::decay_t<T>>, int> = 0) {
25  return std::make_tuple(func(tuple_like_getter<Ix>(t))...);
26 }
27 
28 // master dispatching function ///////////////////////////////////////////////
29 
30 template <typename Func, typename T>
31 constexpr auto map(Func&& func, T&& t) {
32  return map(std::forward<Func>(func),
33  std::forward<T>(t),
34  std::make_index_sequence<
35  tuple_like_size_v<decay_const_ref_t<T>>>{});
36 }
37 
38 } // namespace util
Definition: allocator.h:6