dune-common  2.5.0
apply.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_COMMON_STD_APPLY_HH
4 #define DUNE_COMMON_STD_APPLY_HH
5 
6 #if __cpp_lib_apply
7  #include <tuple>
8 #elif __cpp_lib_experimental_apply
9  #include <experimental/tuple>
10 #else
11  #include <cstddef>
12  #include <utility>
13  #include <tuple>
14 #endif
15 
16 
17 
18 namespace Dune
19 {
20 
21  namespace Std
22  {
23 
24 #if __cpp_lib_apply
25 
26  using std::apply;
27 
28 #elif __cpp_lib_experimental_apply
29 
31 
32 #else
33 
34  namespace Impl
35  {
36  template<class F, class ArgTuple, std::size_t... i>
37  decltype(auto) applyHelper(F&& f, ArgTuple&& args, std::index_sequence<i...>)
38  {
39  return f(std::get<i>(args)...);
40  }
41  } // namespace Impl
42 
43 
44 
53  template<class F, class ArgTuple>
54  decltype(auto) apply(F&& f, ArgTuple&& args)
55  {
56  auto indices = std::make_index_sequence<std::tuple_size<std::decay_t<ArgTuple>>::value>();
57  return Impl::applyHelper(std::forward<F>(f), std::forward<ArgTuple>(args), indices);
58  }
59 
60 #endif
61 
62  } // namespace Std
63 } // namespace Dune
64 
65 #endif // #ifndef DUNE_COMMON_STD_APPLY_HH
STL namespace.
decltype(auto) apply(F &&f, ArgTuple &&args)
Apply function with arguments given as tuple.
Definition: apply.hh:54
Dune namespace.
Definition: alignment.hh:10
an implementation of std::integer_sequence as introduced in C++14
Definition: utility.hh:36
decltype(auto) applyHelper(F &&f, ArgTuple &&args, std::index_sequence< i... >)
Definition: apply.hh:37