VCCC  2024.05
VisualCamp Common C++ library
make_from_tuple.hpp
Go to the documentation of this file.
1 //
2 // Created by yonggyulee on 2023/10/27.
3 //
4 
5 #ifndef VCCC_TUPLE_MAKE_FROM_TUPLE_HPP
6 #define VCCC_TUPLE_MAKE_FROM_TUPLE_HPP
7 
8 #include <cstddef>
9 #include <type_traits>
10 #include <utility>
11 
12 namespace vccc {
13 
16 
17 namespace internal {
18 
19 template<typename T, typename Tuple, std::size_t... I>
20 constexpr T make_from_tuple_impl(Tuple&& t, std::index_sequence<I...>) {
21  return T(std::get<I>(std::forward<Tuple>(t))...);
22 }
23 
24 template<typename T, typename Tuple, typename I>
25 struct is_constructible_from_tuple_impl;
26 
27 template<typename T, typename Tuple, std::size_t... I>
28 struct is_constructible_from_tuple_impl<T, Tuple, std::index_sequence<I...>>
29  : std::is_constructible<T, decltype(std::get<I>(std::declval<Tuple>()))...> {};
30 
31 template<typename T, typename Tuple>
32 struct is_constructible_from_tuple
33  : is_constructible_from_tuple_impl<T,
34  Tuple,
35  std::make_index_sequence<
36  std::tuple_size<std::remove_reference_t<Tuple>>::value>> {};
37 
38 } // namespace internal
39 
40 // TODO(Tony): Constraint on Tuple? (C++23)
41 
79 constexpr T make_from_tuple(Tuple&& t) {
80  return internal::make_from_tuple_impl<T>(
81  std::forward<Tuple>(t),
82  std::make_index_sequence<std::tuple_size<std::remove_reference_t<Tuple>>::value>{});
83 }
84 
86 
87 } // namespace vccc
88 
89 #endif // VCCC_TUPLE_MAKE_FROM_TUPLE_HPP
constexpr T make_from_tuple(Tuple &&t)
construct an object with a tuple of arguments
Definition: make_from_tuple.hpp:79
Definition: matrix.hpp:495
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35