Wayverb
foldl.h
1 #pragma once
2 
3 #include "utilities/tuple_like.h"
4 
5 namespace util {
6 
7 template <typename Callback, typename T>
8 constexpr auto foldl_params(Callback&&, T&& t) -> decltype(std::forward<T>(t)) {
9  return std::forward<T>(t);
10 }
11 
12 template <typename Callback, typename Acc, typename T, typename... Ts>
13 constexpr auto foldl_params(Callback&& callback, Acc&& acc, T&& t, Ts&&... ts) {
14  return foldl_params(std::forward<Callback>(callback),
15  callback(std::forward<Acc>(acc), std::forward<T>(t)),
16  std::forward<Ts>(ts)...);
17 }
18 
19 template <typename Callback, typename T, size_t... Ix>
20 constexpr auto foldl(Callback&& callback,
21  const T& t,
22  std::index_sequence<Ix...>) {
23  return foldl_params(std::forward<Callback>(callback),
24  tuple_like_getter<Ix>(t)...);
25 }
26 
27 template <typename Callback, typename T>
28 constexpr auto foldl(Callback&& callback, const T& t) {
29  return foldl(std::forward<Callback>(callback),
30  t,
31  std::make_index_sequence<tuple_like_size_v<T>>{});
32 }
33 
34 template <typename Callback, typename Init, typename T, size_t... Ix>
35 constexpr auto foldl(Callback&& callback,
36  const Init& init,
37  const T& t,
38  std::index_sequence<Ix...>) {
39  return foldl_params(std::forward<Callback>(callback),
40  init,
41  tuple_like_getter<Ix>(t)...);
42 }
43 
44 template <typename Callback, typename Init, typename T>
45 constexpr auto foldl(Callback&& callback, const Init& init, const T& t) {
46  return foldl(std::forward<Callback>(callback),
47  init,
48  t,
49  std::make_index_sequence<tuple_like_size_v<T>>{});
50 }
51 
52 } // namespace util
Definition: allocator.h:6