Skip to content

Commit addb2da

Browse files
author
Julian LALU
committed
Update tuple
1 parent 5568ebf commit addb2da

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

interface/core/containers/tuple.h

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,8 @@ namespace hud
816816
template<usize element_index, typename... u_types_t>
817817
friend constexpr const tuple_element_t<element_index, tuple<u_types_t...>> &&get(const tuple<u_types_t...> &&tuple) noexcept;
818818

819-
template<usize idx_to_reach, typename... types_t>
820-
friend constexpr auto &&piecewise_get(hud::tuple<types_t...> &&tuple) noexcept;
819+
template<usize idx_to_reach, typename... u_types_t>
820+
friend constexpr auto &&piecewise_get(hud::tuple<u_types_t...> &&tuple) noexcept;
821821

822822
private:
823823
/**
@@ -891,11 +891,11 @@ namespace hud
891891
};
892892

893893
/**
894-
* Retrieves a lvalue reference to the member of a tuple at an index
895-
* @tparam idx_to_reach The index to reach
896-
* @tparam types_t... types_t of the tuple
897-
* @param tuple The tuple to access
898-
* @return LValue reference to the member mFirst if index is 0, mSecond if index is 1.
894+
* Returns an lvalue reference to the element at `idx_to_reach`.
895+
* @tparam idx_to_reach Index of the element to access.
896+
* @tparam types_t Parameter pack of the tuple’s types.
897+
* @param t Tuple to access.
898+
* @return `T&` reference to the selected element.
899899
*/
900900
template<usize idx_to_reach, typename... types_t>
901901
[[nodiscard]] HD_FORCEINLINE constexpr tuple_element_t<idx_to_reach, tuple<types_t...>> &get(tuple<types_t...> &t) noexcept
@@ -905,12 +905,11 @@ namespace hud
905905
}
906906

907907
/**
908-
* Retrieves a lvalue reference to the member of a tuple at an index
909-
* @tparam idx_to_reach The index to reach
910-
* @tparam T1 type_t of the first component
911-
* @tparam T2 type_t of the second component
912-
* @param pair The pair to access
913-
* @return LValue reference to the member mFirst if index is 0, mSecond if index is 1.
908+
* Returns a const lvalue reference to the element at `idx_to_reach`.
909+
* @tparam idx_to_reach Index of the element to access.
910+
* @tparam types_t Parameter pack of the tuple’s types.
911+
* @param t Tuple to access.
912+
* @return `const T&` reference to the selected element.
914913
*/
915914
template<usize idx_to_reach, typename... types_t>
916915
[[nodiscard]] HD_FORCEINLINE constexpr const tuple_element_t<idx_to_reach, tuple<types_t...>> &get(const tuple<types_t...> &t) noexcept
@@ -920,11 +919,11 @@ namespace hud
920919
}
921920

922921
/**
923-
* Retrieves a rvalue reference to the member of a tuple at an index
924-
* @tparam idx_to_reach The index to reach
925-
* @tparam types_t... types_t of the tuple
926-
* @param tuple The tuple to access
927-
* @return RValue reference to the member mFirst if index is 0, mSecond if index is 1.
922+
* Returns an rvalue reference to the element at `idx_to_reach`.
923+
* @tparam idx_to_reach Index of the element to access.
924+
* @tparam types_t Parameter pack of the tuple’s types.
925+
* @param t Tuple to access (rvalue).
926+
* @return `T&&` reference to the selected element, preserving cv‑qualifiers.
928927
*/
929928
template<usize idx_to_reach, typename... types_t>
930929
[[nodiscard]] HD_FORCEINLINE constexpr tuple_element_t<idx_to_reach, tuple<types_t...>> &&get(tuple<types_t...> &&t) noexcept
@@ -934,11 +933,11 @@ namespace hud
934933
}
935934

936935
/**
937-
* Retrieves a rvalue reference to the member of a tuple at an index
938-
* @tparam idx_to_reach The index to reach
939-
* @tparam types_t... types_t of the tuple
940-
* @param tuple The tuple to access
941-
* @return RValue reference to the member mFirst if index is 0, mSecond if index is 1.
936+
* Returns a const rvalue reference to the element at `idx_to_reach`.
937+
* @tparam idx_to_reach Index of the element to access.
938+
* @tparam types_t Parameter pack of the tuple’s types.
939+
* @param t Tuple to access (const rvalue).
940+
* @return `const T&&` reference to the selected element.
942941
*/
943942
template<usize idx_to_reach, typename... types_t>
944943
[[nodiscard]] HD_FORCEINLINE constexpr const tuple_element_t<idx_to_reach, tuple<types_t...>> &&get(const tuple<types_t...> &&t) noexcept
@@ -947,6 +946,22 @@ namespace hud
947946
return hud::forward<const type_t>(static_cast<const details::tuple_leaf<idx_to_reach, type_t> &&>(t).content);
948947
}
949948

949+
/**
950+
* Retrieves an rvalue reference to a tuple element for forwarding purposes.
951+
* This function extracts the element at the specified index from an rvalue tuple and
952+
* casts it explicitly to `T&&`, without preserving the value category or cv-qualifiers
953+
* of the stored element.
954+
* It is primarily intended for internal use in scenarios like piecewise construction,
955+
* where tuple elements are forwarded to construct other objects.
956+
* Warning: This function does **not** preserve reference or constness qualifiers.
957+
* Using it on tuples that contain reference types (`T&`, `const T&`) or non-movable types
958+
* may result in incorrect behavior or undefined reference binding.
959+
* For safe and category-preserving access to tuple elements, prefer using `get<Index>(std::move(tuple))` instead.
960+
* @tparam idx_to_reach The index of the element to extract.
961+
* @param t The rvalue tuple from which to extract the element.
962+
* @return An rvalue reference to the element at the specified index, cast as `T&&`
963+
* without regard for its original value category.
964+
*/
950965
template<usize idx_to_reach, typename... types_t>
951966
[[nodiscard]] constexpr auto &&piecewise_get(hud::tuple<types_t...> &&t) noexcept
952967
{

0 commit comments

Comments
 (0)