-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtuple.h
26 lines (20 loc) · 826 Bytes
/
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
#include <tuple> //todo:tuple
#include <utility> //cannot do:index_sequence
#include "functional/invoke.h"
#include "type_traits/remove_reference.h"
#include "utility/forward.h"
namespace my {
// apply
template <class Callable, class Tuple, size_t... Index>
constexpr decltype(auto) Apply_impl(Callable&& obj, Tuple&& tuple,
std::index_sequence<Index...>) {
return invoke(forward<Callable>(obj),
std::get<Index>(forward<Tuple>(tuple))...);
}
template <class Callable, class Tuple>
constexpr decltype(auto) apply(Callable&& obj, Tuple&& tuple) {
return Apply_impl(forward<Callable>(obj), forward<Tuple>(tuple),
std::make_index_sequence<
std::tuple_size_v<remove_reference_t<Tuple>>>{});
}
} // namespace my