Dune Core Modules (2.5.0)

apply.hh
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
18namespace 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
30 using std::experimental::apply;
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
Dune namespace.
Definition: alignment.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)