-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_from_tuple.h
75 lines (60 loc) · 2.22 KB
/
make_from_tuple.h
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
72
73
74
75
/* make_from_tuple.h -*-C++-*-
*
* Copyright (C) 2016 Pablo Halpern <phalpern@halpernwightsoftware.com>
* Distributed under the Boost Software License - Version 1.0
*/
#ifndef INCLUDED_MAKE_FROM_TUPLE_DOT_H
#define INCLUDED_MAKE_FROM_TUPLE_DOT_H
#include <utility>
#include <tuple>
#include <cstdlib>
namespace std {
inline namespace Cpp17 {
template <class...> struct void_t_imp { typedef void type; };
template <class... T> using void_t = typename void_t_imp<T...>::type;
namespace internal {
template <class F, class Tuple, size_t... I>
constexpr decltype(auto) apply_impl(F&& f, Tuple&& t, index_sequence<I...>) {
// TBD: This should be a call to `invoke()`
return std::forward<F>(f)(std::get<I>(std::forward<Tuple>(t))...);
}
template <class T, class Tuple, size_t... Indexes>
T make_from_tuple_imp(Tuple&& t, index_sequence<Indexes...>)
{
return T(get<Indexes>(forward<Tuple>(t))...);
}
#if 0
template <class T, class Tuple, size_t... Indexes>
T* uninitialized_construct_from_tuple_imp(T* p, Tuple&& t,
index_sequence<Indexes...>)
{
return ::new((void*) p) T(get<Indexes>(std::forward<Tuple>(t))...);
}
#endif
} // close namespace namespace Cpp20::internal
template <class F, class Tuple>
constexpr decltype(auto) apply(F&& f, Tuple&& t) {
return internal::apply_impl(std::forward<F>(f), std::forward<Tuple>(t),
make_index_sequence<tuple_size<decay_t<Tuple>>::value>{});
}
template <class T, class Tuple>
T make_from_tuple(Tuple&& args_tuple)
{
using namespace internal;
using Indices = make_index_sequence<tuple_size<decay_t<Tuple>>::value>;
return make_from_tuple_imp<T>(forward<Tuple>(args_tuple), Indices{});
}
#if 0
template <class T, class Tuple>
T* uninitialized_construct_from_tuple(T* p, Tuple&& args_tuple)
{
using namespace internal;
using Indices = make_index_sequence<tuple_size<decay_t<Tuple>>::value>;
return uninitialized_construct_from_tuple_imp<T>(p,
forward<Tuple>(args_tuple),
Indices{});
}
#endif
} // close namespace Cpp17
} // close namespace std
#endif // ! defined(INCLUDED_MAKE_FROM_TUPLE_DOT_H)