VCCC  2024.05
VisualCamp Common C++ library
tuple_transform.hpp
Go to the documentation of this file.
1 //
2 // Created by YongGyu Lee on 2/20/24.
3 //
4 
5 #ifndef VCCC_TUPLE_TUPLE_TRANSFORM_HPP
6 #define VCCC_TUPLE_TUPLE_TRANSFORM_HPP
7 
8 #include <tuple>
9 #include <utility>
10 
15 
16 namespace vccc {
17 namespace detail {
18 
19 template<typename Tuple, typename F, std::size_t... I>
20 constexpr auto tuple_transform_impl(Tuple&& t, F&& f, std::index_sequence<I...>)
21  noexcept(conjunction<
22  bool_constant<noexcept(vccc::invoke(std::forward<F>(f), std::get<I>(std::forward<Tuple>(t))))>...
23  >::value)
24 {
25  return std::tuple<decltype(vccc::invoke(std::forward<F>(f), std::get<I>(std::forward<Tuple>(t))))...>(
26  vccc::invoke(std::forward<F>(f), std::get<I>(std::forward<Tuple>(t)))...);
27 }
28 
29 } // namespace detail
30 
33 
35 template<typename Tuple, typename F>
36 constexpr auto tuple_transform(Tuple&& t, F&& f)
37  noexcept(noexcept(
38  detail::tuple_transform_impl(
39  std::forward<Tuple>(t),
40  std::forward<F>(f),
41  std::make_index_sequence<std::tuple_size<remove_cvref_t<Tuple>>::value>{}
42  )
43  ))
44 {
45  return detail::tuple_transform_impl(
46  std::forward<Tuple>(t), std::forward<F>(f),
47  std::make_index_sequence<std::tuple_size<remove_cvref_t<Tuple>>::value>{});
48 }
49 
51 
52 } // namespace vccc
53 
54 #endif // VCCC_TUPLE_TUPLE_TRANSFORM_HPP
constexpr invoke_result_t< F, Args... > invoke(F &&f, Args &&... args) noexcept(is_nothrow_invocable< F, Args... >::value)
Definition: invoke.hpp:38
constexpr auto tuple_transform(Tuple &&t, F &&f) noexcept(noexcept(detail::tuple_transform_impl(std::forward< Tuple >(t), std::forward< F >(f), std::make_index_sequence< std::tuple_size< remove_cvref_t< Tuple >>::value >{})))
Constructs a new tuple with each elements transformed.
Definition: tuple_transform.hpp:36
std::integral_constant< bool, v > bool_constant
Definition: bool_constant.hpp:19
typename remove_cvref< T >::type remove_cvref_t
Definition: remove_cvref.hpp:24
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35