From 2bebc1c5a025c39324668952054996b45b73432f Mon Sep 17 00:00:00 2001 From: Nick Erdmann Date: Mon, 2 Sep 2024 23:08:43 +0200 Subject: [PATCH] AK: Add tuple_element and tuple_size For structured bindings, these have to be defined in the std namespace. Co-Authored-By: implicitfield <114500360+implicitfield@users.noreply.github.com> --- AK/StdShim.h | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/AK/StdShim.h b/AK/StdShim.h index 411806cde23..9e133669b21 100644 --- a/AK/StdShim.h +++ b/AK/StdShim.h @@ -53,6 +53,41 @@ constexpr T* construct_at(T* location, Args&&... args) noexcept return ::new (static_cast(location)) T(forward(args)...); } +template +struct tuple_element; + +template +struct tuple_element { + using type = typename tuple_element::type volatile; +}; + +template +struct tuple_element { + using type = typename tuple_element::type const volatile; +}; + +template +struct tuple_element { + using type = typename tuple_element::type const; +}; + +template +struct tuple_size; + +template +using tuple_size_implementation = T; + +template +requires(!IsVolatile) +struct tuple_size::value)>> : public AK::Detail::IntegralConstant::value> { }; + +template +requires(!IsConst) +struct tuple_size::value)>> : public AK::Detail::IntegralConstant::value> { }; + +template +struct tuple_size::value)>> : public AK::Detail::IntegralConstant::value> { }; + } #else @@ -61,15 +96,19 @@ constexpr T* construct_at(T* location, Args&&... args) noexcept // GLIBC LIBSTDC++ # include # include +# include // tuple_{element,size} # elif __has_include(<__utility/forward.h>) && __has_include(<__memory/construct_at.h>) // LLVM LIBCXX # include <__memory/construct_at.h> +# include <__tuple/tuple_element.h> +# include <__tuple/tuple_size.h> # include <__utility/forward.h> # include <__utility/move.h> # else // FIXME: Find a smaller header to include in these cases -# warning "Using and for move, forward and construct_at" +# warning "Using , and for move, forward, construct_at and tuple_{element,size}" # include +# include # include # endif @@ -79,4 +118,6 @@ namespace AK { using std::construct_at; using std::forward; using std::move; +using std::tuple_element; +using std::tuple_size; }