| 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 | struct front_t | ||
| 13 | { | ||
| 14 | template<kumi::concepts::non_empty_product_type T> | ||
| 15 | [[nodiscard]] KUMI_ABI constexpr decltype(auto) operator()(T&& t) const | ||
| 16 | { | ||
| 17 | 26 | if constexpr (kumi::concepts::record_type<T>) return (*this)(kumi::values_of(KUMI_FWD(t))); | |
| 18 | 36 | else return get<0>(KUMI_FWD(t)); | |
| 19 | } | ||
| 20 | }; | ||
| 21 | |||
| 22 | struct back_t | ||
| 23 | { | ||
| 24 | template<kumi::concepts::non_empty_product_type T> | ||
| 25 | [[nodiscard]] KUMI_ABI constexpr decltype(auto) operator()(T&& t) const | ||
| 26 | { | ||
| 27 | 26 | if constexpr (kumi::concepts::record_type<T>) return (*this)(kumi::values_of(KUMI_FWD(t))); | |
| 28 | 36 | else return get<kumi::size_v<T> - 1>(KUMI_FWD(t)); | |
| 29 | } | ||
| 30 | }; | ||
| 31 | |||
| 32 | //==================================================================================================================== | ||
| 33 | /** | ||
| 34 | @ingroup kumi_queries | ||
| 35 | |||
| 36 | @var front | ||
| 37 | @brief Callable object used to retrieve the front of a product type | ||
| 38 | |||
| 39 | @note This function does not take part in overload resolution if t is an empty product type. | ||
| 40 | |||
| 41 | @qualifier nodiscard | ||
| 42 | @qualifier inline | ||
| 43 | @qualifier constexpr | ||
| 44 | |||
| 45 | @groupheader{Header file} | ||
| 46 | @code | ||
| 47 | #include <kumi/algorithm/back_front.hpp> | ||
| 48 | @endcode | ||
| 49 | |||
| 50 | @groupheader{Call Signature} | ||
| 51 | |||
| 52 | @code | ||
| 53 | template<product_type T> | ||
| 54 | [[nodiscard]] constexpr decltype(auto) front(T && t); | ||
| 55 | @endcode | ||
| 56 | |||
| 57 | @subgroupheader{Parameters} | ||
| 58 | |||
| 59 | - `t`: Product Type to access | ||
| 60 | |||
| 61 | @subgroupheader{Return value} | ||
| 62 | |||
| 63 | - A reference to the first element of the product type `t`. | ||
| 64 | |||
| 65 | @groupheader{Helper type} | ||
| 66 | |||
| 67 | @snippet include/kumi/algorithm/back_front.hpp front_t | ||
| 68 | |||
| 69 | Computes the return type of a call to kumi::front | ||
| 70 | |||
| 71 | @groupheader{Examples} | ||
| 72 | |||
| 73 | @tab_begin | ||
| 74 | |||
| 75 | @tab{Tuple} | ||
| 76 | @godbolt{doc/tuple/algo/back-front.cpp} | ||
| 77 | |||
| 78 | @tab{Record} | ||
| 79 | @godbolt{doc/record/algo/back-front.cpp} | ||
| 80 | |||
| 81 | @tab_end | ||
| 82 | **/ | ||
| 83 | //==================================================================================================================== | ||
| 84 | KUMI_VARIABLE_ABI constexpr front_t front{}; | ||
| 85 | |||
| 86 | //==================================================================================================================== | ||
| 87 | /** | ||
| 88 | @ingroup kumi_queries | ||
| 89 | |||
| 90 | @var back | ||
| 91 | @brief Callable object used to retrieve the back of a product type | ||
| 92 | |||
| 93 | @note This function does not take part in overload resolution if t is an empty product type. | ||
| 94 | |||
| 95 | @qualifier nodiscard | ||
| 96 | @qualifier inline | ||
| 97 | @qualifier constexpr | ||
| 98 | |||
| 99 | @groupheader{Header file} | ||
| 100 | @code | ||
| 101 | #include <kumi/algorithm/back_front.hpp> | ||
| 102 | @endcode | ||
| 103 | |||
| 104 | @groupheader{Call Signature} | ||
| 105 | |||
| 106 | @code | ||
| 107 | template<product_type T> | ||
| 108 | [[nodiscard]] constexpr decltype(auto) back(T && t); | ||
| 109 | @endcode | ||
| 110 | |||
| 111 | @subgroupheader{Parameters} | ||
| 112 | |||
| 113 | - `t`: Product Type to access | ||
| 114 | |||
| 115 | @subgroupheader{Return value} | ||
| 116 | |||
| 117 | - A reference to the last element of the product type `t`. | ||
| 118 | |||
| 119 | @groupheader{Helper type} | ||
| 120 | |||
| 121 | @snippet include/kumi/algorithm/back_front.hpp back_t | ||
| 122 | |||
| 123 | Computes the return type of a call to kumi::back | ||
| 124 | |||
| 125 | @groupheader{Examples} | ||
| 126 | |||
| 127 | @tab_begin | ||
| 128 | |||
| 129 | @tab{Tuple} | ||
| 130 | @godbolt{doc/tuple/algo/back-front.cpp} | ||
| 131 | |||
| 132 | @tab{Record} | ||
| 133 | @godbolt{doc/record/algo/back-front.cpp} | ||
| 134 | |||
| 135 | @tab_end | ||
| 136 | **/ | ||
| 137 | //==================================================================================================================== | ||
| 138 | KUMI_VARIABLE_ABI constexpr back_t back{}; | ||
| 139 | |||
| 140 | namespace result | ||
| 141 | { | ||
| 142 | //! [front_t] | ||
| 143 | template<kumi::concepts::product_type T> using front_t = kumi::stored_member_t<0, T>; | ||
| 144 | |||
| 145 | template<kumi::concepts::product_type T> struct front | ||
| 146 | { | ||
| 147 | using type = kumi::result::front_t<T>; | ||
| 148 | }; | ||
| 149 | |||
| 150 | //! [front_t] | ||
| 151 | |||
| 152 | //! [back_t] | ||
| 153 | template<kumi::concepts::product_type T> using back_t = kumi::stored_member_t<kumi::size_v<T> - 1, T>; | ||
| 154 | |||
| 155 | template<kumi::concepts::product_type T> struct back | ||
| 156 | { | ||
| 157 | using type = kumi::result::back_t<T>; | ||
| 158 | }; | ||
| 159 | |||
| 160 | //! [back_t] | ||
| 161 | } | ||
| 162 | } | ||
| 163 |