Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
apply_tuple.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/meta/apply_tuple.hpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2016-2017 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
11 #ifndef TLX_META_APPLY_TUPLE_HEADER
12 #define TLX_META_APPLY_TUPLE_HEADER
13 
14 #include <utility>
15 
17 
18 namespace tlx {
19 
20 //! \addtogroup tlx_meta
21 //! \{
22 
23 /******************************************************************************/
24 // Tuple Applier: takes a std::tuple<> and applies a variadic template function
25 // to it. Hence, this expands the content of the tuple as the arguments.
26 
27 namespace detail {
28 
29 template <typename Functor, typename Tuple, std::size_t... Is>
30 auto apply_tuple_impl(Functor&& f, Tuple&& t, index_sequence<Is...>) {
31  return std::forward<Functor>(f)(
32  std::get<Is>(std::forward<Tuple>(t)) ...);
33 }
34 
35 } // namespace detail
36 
37 //! Call the functor f with the contents of t as arguments.
38 template <typename Functor, typename Tuple>
39 auto apply_tuple(Functor&& f, Tuple&& t) {
40  using Indices = make_index_sequence<
41  std::tuple_size<typename std::decay<Tuple>::type>::value>;
43  std::forward<Functor>(f), std::forward<Tuple>(t), Indices());
44 }
45 
46 //! \}
47 
48 } // namespace tlx
49 
50 #endif // !TLX_META_APPLY_TUPLE_HEADER
51 
52 /******************************************************************************/
auto apply_tuple_impl(Functor &&f, Tuple &&t, index_sequence< Is...>)
Definition: apply_tuple.hpp:30
int value
Definition: gen_data.py:41
auto apply_tuple(Functor &&f, Tuple &&t)
Call the functor f with the contents of t as arguments.
Definition: apply_tuple.hpp:39