Thrill  0.1
vmap_foreach_tuple_with_index.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/meta/vmap_foreach_tuple_with_index.hpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2018 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
11 #ifndef TLX_META_VMAP_FOREACH_TUPLE_WITH_INDEX_HEADER
12 #define TLX_META_VMAP_FOREACH_TUPLE_WITH_INDEX_HEADER
13 
16 #include <tuple>
17 
18 namespace tlx {
19 
20 //! \addtogroup tlx_meta
21 //! \{
22 
23 /******************************************************************************/
24 // Variadic Template Expander: run a generic templated functor (like a generic
25 // lambda) for each component of a tuple, and collect the returned values in a
26 // generic std::tuple.
27 //
28 // Called with func(StaticIndex<> index, Argument arg).
29 
30 namespace meta_detail {
31 
32 //! helper for vmap_foreach_tuple_with_index: forwards tuple entries
33 template <typename Functor, typename Tuple, std::size_t... Is>
35  Functor&& f, Tuple&& t, index_sequence<Is...>) {
36  return vmap_foreach_with_index(std::forward<Functor>(f),
37  std::get<Is>(std::forward<Tuple>(t)) ...);
38 }
39 
40 } // namespace meta_detail
41 
42 //! Call a generic functor (like a generic lambda) for each variadic template
43 //! argument and collect the result in a std::tuple<>.
44 template <typename Functor, typename Tuple>
45 auto vmap_foreach_tuple_with_index(Functor&& f, Tuple&& t) {
46  using Indices = make_index_sequence<
47  std::tuple_size<typename std::decay<Tuple>::type>::value>;
49  std::forward<Functor>(f), std::forward<Tuple>(t), Indices());
50 }
51 
52 //! \}
53 
54 } // namespace tlx
55 
56 #endif // !TLX_META_VMAP_FOREACH_TUPLE_WITH_INDEX_HEADER
57 
58 /******************************************************************************/
auto vmap_foreach_tuple_with_index_impl(Functor &&f, Tuple &&t, index_sequence< Is... >)
helper for vmap_foreach_tuple_with_index: forwards tuple entries
auto vmap_foreach_with_index(Functor &&f, Args &&... args)
auto vmap_foreach_tuple_with_index(Functor &&f, Tuple &&t)
int value
Definition: gen_data.py:41