Summary: | Enhance Vector::map to allow specifying what kind of Vector to return (e.g. inline capacity, overflow, etc.) | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Sam Weinig <sam> | ||||||||
Component: | Web Template Framework | Assignee: | Sam Weinig <sam> | ||||||||
Status: | RESOLVED FIXED | ||||||||||
Severity: | Normal | CC: | benjamin, cdumez, cmarcelo, darin, ews-watchlist, webkit-bug-importer | ||||||||
Priority: | P2 | Keywords: | InRadar | ||||||||
Version: | Other | ||||||||||
Hardware: | Unspecified | ||||||||||
OS: | Unspecified | ||||||||||
Attachments: |
|
Description
Sam Weinig
2021-12-25 17:43:45 PST
This is a bit tricky to tack onto the existing map due to the order of template arguments: template<typename MapFunction, typename R = typename std::invoke_result<MapFunction, const T&>::type> Vector<R> map(MapFunction) const; The naive approach, to make R an overridable parameter like the following: template<typename MapFunction, typename R = Vector<typename std::invoke_result<MapFunction, const T&>::type>> R map(MapFunction) const; has the problem that now, to specify the Vector type, you also need to specify the MapFunction type, which can be hard / impossible when used with lambdas. My current idea is to use overloading + SFINAE to have another version that looks like: template<typename R, typename MapFunction, typename SOME_SFINAE_TEST_HERE> R map(MapFunction) const; Created attachment 447965 [details]
Patch
Comment on attachment 447965 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=447965&action=review Seems like we should include at least one use of the new template, maybe in the tests directory? > Source/WTF/ChangeLog:15 > + (WTF::Malloc>::map const const): > + (WTF::Malloc>::map const const const): > + (WTF::Malloc>::map const): Deleted. Garbled function names. (In reply to Darin Adler from comment #3) > Comment on attachment 447965 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=447965&action=review > > Seems like we should include at least one use of the new template, maybe in > the tests directory? Yeah, I also meant to actually use this as well, but failed to upload the whole patch :(. > > > Source/WTF/ChangeLog:15 > > + (WTF::Malloc>::map const const): > > + (WTF::Malloc>::map const const const): > > + (WTF::Malloc>::map const): Deleted. > > Garbled function names. So close little script. Created attachment 448046 [details]
Patch with tests
Created attachment 448047 [details]
Patch with tests
Committed r287472 (245607@main): <https://commits.webkit.org/245607@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 448047 [details]. |