tlx
fold_left_tuple.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/meta/fold_left_tuple.hpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2018 Hung Tran <hung@ae.cs.uni-frankfurt.de>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
11 #ifndef TLX_META_FOLD_LEFT_TUPLE_HEADER
12 #define TLX_META_FOLD_LEFT_TUPLE_HEADER
13 
14 #include <tlx/meta/fold_left.hpp>
16 #include <tuple>
17 
18 namespace tlx {
19 
20 //! \addtogroup tlx_meta
21 //! \{
22 
23 /******************************************************************************/
24 // Variadic Template Expander: Implements fold_left() on the components of a
25 // tuple.
26 
27 namespace meta_detail {
28 
29 //! helper for fold_left_tuple: forwards tuple entries
30 template <typename Reduce, typename Initial, typename Tuple, std::size_t... Is>
31 auto fold_left_tuple_impl(Reduce&& r, Initial&& init, Tuple&& t,
33  return fold_left(
34  std::forward<Reduce>(r), std::forward<Initial>(init),
35  std::get<Is>(std::forward<Tuple>(t)) ...);
36 }
37 
38 } // namespace meta_detail
39 
40 //! Implements fold_left() -- ((a * b) * c) -- with a binary Reduce operation
41 //! and initial value on a tuple.
42 template <typename Reduce, typename Initial, typename Tuple>
43 auto fold_left_tuple(Reduce&& r, Initial&& init, Tuple&& t) {
44  using Indices = make_index_sequence<
45  std::tuple_size<typename std::decay<Tuple>::type>::value>;
47  std::forward<Reduce>(r), std::forward<Initial>(init),
48  std::forward<Tuple>(t), Indices());
49 }
50 
51 //! \}
52 
53 } // namespace tlx
54 
55 #endif // !TLX_META_FOLD_LEFT_TUPLE_HEADER
56 
57 /******************************************************************************/
auto fold_left_tuple(Reduce &&r, Initial &&init, Tuple &&t)
Implements fold_left() – ((a * b) * c) – with a binary Reduce operation and initial value on a tupl...
auto fold_left(Reduce &&r, Initial &&init, Args &&...args)
Implements fold_left() – ((a * b) * c) – with a binary Reduce operation and initial value...
Definition: fold_left.hpp:51
auto fold_left_tuple_impl(Reduce &&r, Initial &&init, Tuple &&t, index_sequence< Is... >)
helper for fold_left_tuple: forwards tuple entries