tlx
vmap_foreach_tuple.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/meta/vmap_foreach_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_VMAP_FOREACH_TUPLE_HEADER
12 #define TLX_META_VMAP_FOREACH_TUPLE_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 namespace meta_detail {
29 
30 //! helper for vmap_foreach_tuple: forwards tuple entries
31 template <typename Functor, typename Tuple, std::size_t... Is>
33  Functor&& f, Tuple&& t, index_sequence<Is...>) {
34  return vmap_foreach(std::forward<Functor>(f),
35  std::get<Is>(std::forward<Tuple>(t)) ...);
36 }
37 
38 } // namespace meta_detail
39 
40 //! Call a generic functor (like a generic lambda) for each variadic template
41 //! argument and collect the result in a std::tuple<>.
42 template <typename Functor, typename Tuple>
43 auto vmap_foreach_tuple(Functor&& f, Tuple&& t) {
44  using Indices = make_index_sequence<
45  std::tuple_size<typename std::decay<Tuple>::type>::value>;
47  std::forward<Functor>(f), std::forward<Tuple>(t), Indices());
48 }
49 
50 //! \}
51 
52 } // namespace tlx
53 
54 #endif // !TLX_META_VMAP_FOREACH_TUPLE_HEADER
55 
56 /******************************************************************************/
auto vmap_foreach_tuple(Functor &&f, Tuple &&t)
Call a generic functor (like a generic lambda) for each variadic template argument and collect the re...
auto vmap_foreach(Functor &&f, Args &&...args)
Call a generic functor (like a generic lambda) for each variadic template argument.
auto vmap_foreach_tuple_impl(Functor &&f, Tuple &&t, index_sequence< Is... >)
helper for vmap_foreach_tuple: forwards tuple entries