Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<tuple>: tuple_cat for tuple-like types #461

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions stl/inc/tuple
Original file line number Diff line number Diff line change
Expand Up @@ -866,10 +866,40 @@ _NODISCARD constexpr _Ty&& get(array<_Ty, _Size>&& _Arr) noexcept;
template <size_t _Idx, class _Ty, size_t _Size>
_NODISCARD constexpr const _Ty&& get(const array<_Ty, _Size>&& _Arr) noexcept;

// STRUCT TEMPLATE _Repeat_type_in_tuple
template <class _Ty, class... _Meta>
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
struct _Repeat_type_in_tuple {
static_assert(_Always_false<_Ty>, "Requires index_sequence as second template argument.");
};

template <class _Ty, size_t... _Ix>
struct _Repeat_type_in_tuple<_Ty, index_sequence<_Ix...>> {
using type = tuple<typename remove_reference_t<decltype(_Ix, declval<_Identity<_Ty>>())>::type...>;
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
};

// STRUCT TEMPLATE _Is_tuple_like
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
template <class _Ty, class = int>
struct _Is_tuple_like : false_type {};

template <class _Ty>
struct _Is_tuple_like<_Ty, decltype((void)tuple_size<_Ty>::size, 0)> : true_type {};
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved

// STRUCT TEMPLATE _View_custom_as_tuple
template <class _Ty, class... _Meta>
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
struct _View_custom_as_tuple {
static_assert(_Always_false<_Ty>, "Requires index_sequence as second template argument.");
};

template <class _Ty, size_t... _Ix>
struct _View_custom_as_tuple<_Ty, index_sequence<_Ix...>> {
using type = tuple<tuple_element_t<_Ix, _Ty>...>;
};

// STRUCT TEMPLATE _View_as_tuple
template <class _Ty, class... _For_array>
struct _View_as_tuple { // tuple_cat() supports only tuples, pairs, and arrays
static_assert(_Always_false<_Ty>, "Unsupported tuple_cat arguments.");
template <class _Ty>
struct _View_as_tuple {
static_assert(_Is_tuple_like<_Ty>::value, "Unsupported tuple_cat arguments.");
using type = typename _View_custom_as_tuple<_Ty, make_index_sequence<tuple_size<_Ty>::size>>::type;
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
};

template <class... _Types>
Expand All @@ -882,14 +912,9 @@ struct _View_as_tuple<pair<_Ty1, _Ty2>> { // view a pair as a tuple
using type = tuple<_Ty1, _Ty2>;
};

template <class _Ty, class... _Types>
struct _View_as_tuple<array<_Ty, 0>, _Types...> { // view an array as a tuple; ends recursion at 0
using type = tuple<_Types...>;
};

template <class _Ty, size_t _Size, class... _Types>
struct _View_as_tuple<array<_Ty, _Size>, _Types...>
: _View_as_tuple<array<_Ty, _Size - 1>, _Ty, _Types...> { // view an array as a tuple; counts down to 0
template <class _Ty, size_t _Size>
struct _View_as_tuple<array<_Ty, _Size>> { // view an array as a tuple
using type = typename _Repeat_type_in_tuple<_Ty, make_index_sequence<_Size>>::type;
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
};

// STRUCT TEMPLATE _Repeat_for
Expand Down