diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-01-23 18:01:07 +0330 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-01-28 00:50:04 +0330 |
commit | bf82d9b5d7c96db9d591594c6e26ee72a82fc5aa (patch) | |
tree | 8384dc8b7d08500b0ccde2d1ab01c32b8229883f /AK | |
parent | a2e791277ed64fd78465da06517f409a2d738e95 (diff) | |
download | serenity-bf82d9b5d7c96db9d591594c6e26ee72a82fc5aa.zip |
AK: Simplify Variant's explicit overload detection mechanism a bit
This also allows us to remove the max-64-visitors restriction, and so
removes that assertion.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Variant.h | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/AK/Variant.h b/AK/Variant.h index 175ec3fdad..e620df5476 100644 --- a/AK/Variant.h +++ b/AK/Variant.h @@ -81,22 +81,19 @@ struct Variant<IndexType, InitialIndex> { template<typename IndexType, typename... Ts> struct VisitImpl { template<typename RT, typename T, size_t I, typename Fn> - static consteval u64 get_explicitly_named_overload_if_exists() + static consteval bool has_explicitly_named_overload() { // If we're not allowed to make a member function pointer and call it directly (without explicitly resolving it), // we have a templated function on our hands (or a function overload set). // in such cases, we don't have an explicitly named overload, and we would have to select it. - if constexpr (requires { (declval<Fn>().*(&Fn::operator()))(declval<T>()); }) - return 1ull << I; - - return 0; + return requires { (declval<Fn>().*(&Fn::operator()))(declval<T>()); }; } template<typename ReturnType, typename T, typename Visitor, auto... Is> static consteval bool should_invoke_const_overload(IndexSequence<Is...>) { // Scan over all the different visitor functions, if none of them are suitable for calling with `T const&`, avoid calling that first. - return ((get_explicitly_named_overload_if_exists<ReturnType, T, Is, typename Visitor::Types::template Type<Is>>()) | ...) != 0; + return ((has_explicitly_named_overload<ReturnType, T, Is, typename Visitor::Types::template Type<Is>>()) || ...); } template<typename Self, typename Visitor, IndexType CurrentIndex = 0> @@ -453,7 +450,6 @@ private: template<typename... Fs> struct Visitor : Fs... { using Types = TypeList<Fs...>; - static_assert(Types::size < 64, "Variant::visit() can take a maximum of 64 visit functions."); Visitor(Fs&&... args) : Fs(forward<Fs>(args))... |