From fe236db18c12fb5b0ad850e9382cf55e69faf61f Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Fri, 4 Sep 2026 16:30:49 -0600 Subject: [PATCH] :bug: Fix `tuple_size_v` for types which shouldn't have it Problem: - The concept `has_tuple_protocol` incorrectly succeeds on some platforms for types like `std::optional` because the primary template definition for `stdx::tuple_size_v` is: ```cpp template constexpr auto tuple_size_v = 0u; ``` And on some platforms, `std::size_t` is `unsigned int`, which means literally any type satisfies `has_vacuous_tuple_protocol` concept! Solution: - Make the primary template definition of `tuple_size_v` an invalid type. --- include/stdx/type_traits.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/stdx/type_traits.hpp b/include/stdx/type_traits.hpp index 9381289..515fa98 100644 --- a/include/stdx/type_traits.hpp +++ b/include/stdx/type_traits.hpp @@ -323,7 +323,12 @@ constexpr auto is_complete_v> = true; template constexpr auto is_same_template_v = template_base() == template_base(); -template constexpr auto tuple_size_v = 0u; +namespace detail { +struct invalid_tuple_size_t {}; +} // namespace detail +template +constexpr auto tuple_size_v = detail::invalid_tuple_size_t{}; + template requires requires { T::size(); } constexpr auto tuple_size_v = T::size();