[Webkit-unassigned] [Bug 266798] New: Consider replacing WTF::Visitor (used by WTF::switchOn) with idiomatic `overloaded`

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Dec 21 16:31:20 PST 2023


https://bugs.webkit.org/show_bug.cgi?id=266798

            Bug ID: 266798
           Summary: Consider replacing WTF::Visitor (used by
                    WTF::switchOn) with idiomatic `overloaded`
           Product: WebKit
           Version: WebKit Nightly Build
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Minor
          Priority: P2
         Component: Web Template Framework
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: g_squelart at apple.com

- Visitor is a recursive template, which can cost higher build time and memory compared to a flat struct.
- Also because of recursion, error/warning/debug display is more difficult to read.
- The constructors seem to take their parameter by-value, which could potentially add a copy.

I think we could instead use the almost-standard `overloaded` template struct, as seen in https://en.cppreference.com/w/cpp/utility/variant/visit :
```
template<class... Ts>
struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;
```

(My assumptions about build costs, and that `Visitor` and `overloaded` are equivalent, should be verified!)

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20231222/ce21cacb/attachment-0001.htm>


More information about the webkit-unassigned mailing list