concepts: protect tuple concept against empty tuples

This commit is contained in:
Danny Robson 2020-02-25 11:16:26 +11:00
parent fb4e70d146
commit 1427a61745
2 changed files with 4 additions and 1 deletions

View File

@ -285,7 +285,7 @@ namespace cruft::concepts {
template <typename T>
concept tuple = requires (T a, T b)
{
{ std::tuple_element<0,T> {} };
{ std::tuple_size<T>::value == 0 || std::tuple_element<0,T> {} };
{ std::tuple_size<T>::value } -> convertible_to<std::size_t>;
{ std::tuple_cat (a, b) };
};

View File

@ -8,5 +8,8 @@ int main ()
tap.expect (cruft::concepts::container<std::vector<int>>, "vector is a container");
tap.expect (!cruft::concepts::container<int>, "int is not a container");
tap.expect (cruft::concepts::tuple<std::tuple<>>, "tuple<> is a tuple");
tap.expect (cruft::concepts::tuple<std::tuple<int>>, "tuple<int> is a tuple");
return tap.status ();
}