tlx
call_foreach_tuple_with_index.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/meta/call_foreach_tuple_with_index.hpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2016-2017 Timo Bingmann <tb@panthema.net>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
11 #ifndef TLX_META_CALL_FOREACH_TUPLE_WITH_INDEX_HEADER
12 #define TLX_META_CALL_FOREACH_TUPLE_WITH_INDEX_HEADER
13 
14 #include <tuple>
15 
18 
19 namespace tlx {
20 
21 //! \addtogroup tlx_meta
22 //! \{
23 
24 /******************************************************************************/
25 // Variadic Template Expander: run a generic templated functor (like a generic
26 // lambda) for each component of a std::tuple.
27 //
28 // Called with func(StaticIndex<> index, Argument arg).
29 
30 namespace meta_detail {
31 
32 //! helper for call_foreach_tuple_with_index
33 template <typename Functor, typename Tuple, std::size_t... Is>
35  Functor&& f, Tuple&& t, index_sequence<Is...>) {
37  std::forward<Functor>(f), std::get<Is>(std::forward<Tuple>(t)) ...);
38 }
39 
40 } // namespace meta_detail
41 
42 //! Call a generic functor (like a generic lambda) to each components of a tuple
43 //! together with its zero-based index.
44 template <typename Functor, typename Tuple>
45 void call_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_CALL_FOREACH_TUPLE_WITH_INDEX_HEADER
57 
58 /******************************************************************************/
void call_foreach_tuple_with_index(Functor &&f, Tuple &&t)
Call a generic functor (like a generic lambda) to each components of a tuple together with its zero-b...
void call_foreach_tuple_with_index_impl(Functor &&f, Tuple &&t, index_sequence< Is... >)
helper for call_foreach_tuple_with_index
void call_foreach_with_index(Functor &&f, Args &&...args)
Call a generic functor (like a generic lambda) for each variadic template argument together with its ...