#ifndef _APPLY_TUPLE_H_ #define _APPLY_TUPLE_H_ #include #include #include #include namespace qtl { namespace detail { #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) template inline constexpr decltype(auto) apply_tuple(F&& f, Tuple&& t) { return std::apply(std::forward(f), std::forward(t)); } #else namespace detail { template struct apply { template static inline auto apply_tuple(F&& f, T&& t, A&&... a) -> decltype(apply::apply_tuple( std::forward(f), std::forward(t), std::get(std::forward(t)), std::forward(a)... )) { return apply::apply_tuple(std::forward(f), std::forward(t), std::get(std::forward(t)), std::forward(a)... ); } }; template<> struct apply<0> { template static inline typename std::result_of::type apply_tuple(F&& f, T&&, A&&... a) { return std::forward(f)(std::forward(a)...); } }; } template inline auto apply_tuple(F&& f, T&& t) -> decltype(detail::apply< std::tuple_size< typename std::decay::type >::value>::apply_tuple(std::forward(f), std::forward(t))) { return detail::apply< std::tuple_size< typename std::decay::type >::value>::apply_tuple(std::forward(f), std::forward(t)); } #endif // C++17 } } #endif //_APPLY_TUPLE_H_