mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
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.
This commit is contained in:
parent
a2e791277e
commit
bf82d9b5d7
Notes:
sideshowbarker
2024-07-17 20:08:08 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/bf82d9b5d7c Pull-request: https://github.com/SerenityOS/serenity/pull/12158
1 changed files with 3 additions and 7 deletions
10
AK/Variant.h
10
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))...
|
||||
|
|
Loading…
Reference in a new issue