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() should be generalized beyond pair and array #260

Closed
StephanTLavavej opened this issue Nov 5, 2019 · 0 comments · Fixed by #2833
Closed

<tuple>: tuple_cat() should be generalized beyond pair and array #260

StephanTLavavej opened this issue Nov 5, 2019 · 0 comments · Fixed by #2833
Labels
enhancement Something can be improved fixed Something works now, yay!

Comments

@StephanTLavavej
Copy link
Member

When I overhauled tuple_cat() long ago, I special-cased pair and array:

STL/stl/inc/tuple

Lines 870 to 893 in d0d724f

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... _Types>
struct _View_as_tuple<tuple<_Types...>> { // view a tuple as a tuple
using type = tuple<_Types...>;
};
template <class _Ty1, class _Ty2>
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
};

This is unnecessary. We could simply use tuple_size and tuple_element to accept anything resembling a tuple.

The Standardese is N4835 [tuple.creation]/12 "[Note: An implementation may support additional types in the template parameter pack Tuples that support the tuple-like protocol, such as pair and array. -end note]"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something can be improved fixed Something works now, yay!
Projects
None yet
1 participant