znone
2021-03-02 9891c1bb38c47b05ba3c40b80ad17d1a206e4e5c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef _APPLY_TUPLE_H_
#define _APPLY_TUPLE_H_
 
#include <stddef.h>
#include <tuple>
#include <type_traits>
#include <utility>
 
namespace qtl
{
 
namespace detail
{
 
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
 
template <class F, class Tuple>
inline constexpr decltype(auto) apply_tuple(F&& f, Tuple&& t)
{
    return std::apply(std::forward<F>(f), std::forward<Tuple>(t));
}
 
#else
 
namespace detail
{
    template<size_t N>
    struct apply 
    {
        template<typename F, typename T, typename... A>
        static inline auto apply_tuple(F&& f, T&& t, A&&... a)
            -> decltype(apply<N-1>::apply_tuple(
            std::forward<F>(f), std::forward<T>(t),
            std::get<N-1>(std::forward<T>(t)), std::forward<A>(a)...
            ))
        {
            return apply<N-1>::apply_tuple(std::forward<F>(f), std::forward<T>(t),
                std::get<N-1>(std::forward<T>(t)), std::forward<A>(a)...
                );
        }
    };
 
    template<>
    struct apply<0> 
    {
        template<typename F, typename T, typename... A>
        static inline typename std::result_of<F(A...)>::type apply_tuple(F&& f, T&&, A&&... a)
        {
            return std::forward<F>(f)(std::forward<A>(a)...);
        }
    };
}
 
template<typename F, typename T>
inline auto apply_tuple(F&& f, T&& t)
    -> decltype(detail::apply< std::tuple_size<
        typename std::decay<T>::type
    >::value>::apply_tuple(std::forward<F>(f), std::forward<T>(t)))
{
    return detail::apply< std::tuple_size<
        typename std::decay<T>::type
    >::value>::apply_tuple(std::forward<F>(f), std::forward<T>(t));
}
 
#endif // C++17
 
}
 
}
 
#endif //_APPLY_TUPLE_H_