00001
00002
00003 #ifndef DUNE_COMMON_STD_APPLY_HH
00004 #define DUNE_COMMON_STD_APPLY_HH
00005
00006 #if __cpp_lib_apply
00007 #include <tuple>
00008 #elif __cpp_lib_experimental_apply
00009 #include <experimental/tuple>
00010 #else
00011 #include <cstddef>
00012 #include <utility>
00013 #include <tuple>
00014 #endif
00015
00016
00017
00018 namespace Dune
00019 {
00020
00021 namespace Std
00022 {
00023
00024 #if __cpp_lib_apply
00025
00026 using std::apply;
00027
00028 #elif __cpp_lib_experimental_apply
00029
00030 using std::experimental::apply;
00031
00032 #else
00033
00034 namespace Impl
00035 {
00036 template<class F, class ArgTuple, std::size_t... i>
00037 decltype(auto) applyHelper(F&& f, ArgTuple&& args, std::index_sequence<i...>)
00038 {
00039 return f(std::get<i>(args)...);
00040 }
00041 }
00042
00043
00044
00053 template<class F, class ArgTuple>
00054 decltype(auto) apply(F&& f, ArgTuple&& args)
00055 {
00056 auto indices = std::make_index_sequence<std::tuple_size<std::decay_t<ArgTuple>>::value>();
00057 return Impl::applyHelper(std::forward<F>(f), std::forward<ArgTuple>(args), indices);
00058 }
00059
00060 #endif
00061
00062 }
00063 }
00064
00065 #endif // #ifndef DUNE_COMMON_STD_APPLY_HH