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 <tuple>
15 #include <utility>
16 
18 
19 namespace tlx {
20 
21 //! \addtogroup tlx_meta
22 //! \{
23 
24 /******************************************************************************/
25 // Tuple Applier: takes a std::tuple<> and applies a variadic template function
26 // to it. Hence, this expands the content of the tuple as the arguments.
27 
28 namespace meta_detail {
29 
30 template <typename Functor, typename Tuple, std::size_t... Is>
31 auto apply_tuple_impl(Functor&& f, Tuple&& t, index_sequence<Is...>) {
32  return std::forward<Functor>(f)(
33  std::get<Is>(std::forward<Tuple>(t)) ...);
34 }
35 
36 } // namespace meta_detail
37 
38 //! Call the functor f with the contents of t as arguments.
39 template <typename Functor, typename Tuple>
40 auto apply_tuple(Functor&& f, Tuple&& t) {
41  using Indices = make_index_sequence<
42  std::tuple_size<typename std::decay<Tuple>::type>::value>;
44  std::forward<Functor>(f), std::forward<Tuple>(t), Indices());
45 }
46 
47 //! \}
48 
49 } // namespace tlx
50 
51 #endif // !TLX_META_APPLY_TUPLE_HEADER
52 
53 /******************************************************************************/
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:40
auto apply_tuple_impl(Functor &&f, Tuple &&t, index_sequence< Is...>)
Definition: apply_tuple.hpp:31