| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | //====================================================================================================================== | ||
| 2 | /* | ||
| 3 | KUMI - Compact Tuple Tools | ||
| 4 | Copyright : KUMI Project Contributors | ||
| 5 | SPDX-License-Identifier: BSL-1.0 | ||
| 6 | */ | ||
| 7 | //====================================================================================================================== | ||
| 8 | #pragma once | ||
| 9 | |||
| 10 | namespace kumi | ||
| 11 | { | ||
| 12 | namespace _ | ||
| 13 | { | ||
| 14 | template<std::size_t, typename T> using always_t = T; | ||
| 15 | |||
| 16 | template<typename Target, typename T, std::size_t... I> | ||
| 17 | 22 | KUMI_HIDDEN_ABI constexpr decltype(auto) member_cast_(kumi::_::adl_tag_t, T&& t, std::index_sequence<I...>) | |
| 18 | { | ||
| 19 | if constexpr (kumi::concepts::record_type<T>) | ||
| 20 | 117 | return kumi::builder<T>::make(kumi::field_cast<Target>(get<I>(KUMI_FWD(t)))...); | |
| 21 | 36 | else return kumi::builder_make_t<T, kumi::_::always_t<I, Target>...>{static_cast<Target>(get<I>(KUMI_FWD(t)))...}; | |
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | template<typename Target> struct member_cast_t | ||
| 26 | { | ||
| 27 | template<kumi::concepts::product_type T> [[nodiscard]] KUMI_ABI constexpr auto operator()(T&& t) const | ||
| 28 | { | ||
| 29 | if constexpr (kumi::concepts::empty_product_type<T>) return KUMI_FWD(t); | ||
| 30 |
6/6✓ Branch 1 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
|
12 | else return member_cast_<Target>(kumi::_::adl_tag, KUMI_FWD(t), kumi::function::indexes_for<T>{}); |
| 31 | } | ||
| 32 | }; | ||
| 33 | |||
| 34 | //==================================================================================================================== | ||
| 35 | /** | ||
| 36 | @ingroup kumi_generators | ||
| 37 | |||
| 38 | @var member_cast | ||
| 39 | @brief Callable object converting a product_type<Ts...> to an instance of a product_type<Target...> | ||
| 40 | |||
| 41 | @qualifier nodiscard | ||
| 42 | @qualifier inline | ||
| 43 | @qualifier constexpr | ||
| 44 | |||
| 45 | @groupheader{Header file} | ||
| 46 | @code | ||
| 47 | #include <kumi/algorithm/cast.hpp> | ||
| 48 | @endcode | ||
| 49 | |||
| 50 | @groupheader{Call Signature} | ||
| 51 | |||
| 52 | @code | ||
| 53 | template<typename Target, product_type T> | ||
| 54 | constexpr auto member_cast<Target>(T && t) noexcept; | ||
| 55 | @endcode | ||
| 56 | |||
| 57 | @subgroupheader{Template Parameters} | ||
| 58 | - `Target`: destination type to associate to each member of the product type `t` | ||
| 59 | |||
| 60 | @subgroupheader{Parameters} | ||
| 61 | - `t`: Product Type to convert | ||
| 62 | |||
| 63 | @subgroupheader{Return value} | ||
| 64 | - A Product type containing the values of `t` where each member is of type Target | ||
| 65 | |||
| 66 | @groupheader{Helper type} | ||
| 67 | |||
| 68 | @snippet include/kumi/algorithm/cast.hpp member_cast_t | ||
| 69 | |||
| 70 | Computes the return type of a call to kumi::member_cast | ||
| 71 | |||
| 72 | @groupheader{Examples} | ||
| 73 | |||
| 74 | @tab_begin | ||
| 75 | |||
| 76 | @tab{Tuple} | ||
| 77 | @godbolt{doc/tuple/algo/member_cast.cpp} | ||
| 78 | |||
| 79 | @tab{Record} | ||
| 80 | @godbolt{doc/record/algo/member_cast.cpp} | ||
| 81 | |||
| 82 | @tab_end | ||
| 83 | **/ | ||
| 84 | //==================================================================================================================== | ||
| 85 | template<typename T> inline constexpr member_cast_t<T> member_cast{}; | ||
| 86 | |||
| 87 | namespace result | ||
| 88 | { | ||
| 89 | //! [member_cast_t] | ||
| 90 | template<typename Target, kumi::concepts::product_type T> | ||
| 91 | using member_cast_t = decltype(kumi::member_cast<Target>(std::declval<T>())); | ||
| 92 | |||
| 93 | template<typename Target, kumi::concepts::product_type T> struct member_cast | ||
| 94 | { | ||
| 95 | using type = kumi::result::member_cast_t<Target, T>; | ||
| 96 | }; | ||
| 97 | |||
| 98 | //! [member_cast_t] | ||
| 99 | } | ||
| 100 | } | ||
| 101 |