Bug 234683

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 FrameworkAssignee: 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 Flags
Patch
darin: review+
Patch with tests
sam: commit-queue+
Patch with tests none

Sam Weinig
Reported 2021-12-25 17:43:45 PST
Enhance Vector::map to allow specifying what kind of Vector to return (e.g. inline capacity, overflow, etc.).
Attachments
Patch (3.32 KB, patch)
2021-12-25 19:51 PST, Sam Weinig
darin: review+
Patch with tests (6.85 KB, patch)
2021-12-28 09:02 PST, Sam Weinig
sam: commit-queue+
Patch with tests (6.85 KB, patch)
2021-12-28 09:03 PST, Sam Weinig
no flags
Sam Weinig
Comment 1 2021-12-25 18:46:17 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;
Sam Weinig
Comment 2 2021-12-25 19:51:11 PST
Darin Adler
Comment 3 2021-12-27 10:11:17 PST
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.
Sam Weinig
Comment 4 2021-12-27 11:49:58 PST
(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.
Sam Weinig
Comment 5 2021-12-28 09:02:34 PST Comment hidden (obsolete)
Sam Weinig
Comment 6 2021-12-28 09:03:41 PST
Created attachment 448047 [details] Patch with tests
EWS
Comment 7 2021-12-28 10:02:51 PST
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].
Radar WebKit Bug Importer
Comment 8 2021-12-28 10:03:19 PST
Note You need to log in before you can comment on or make changes to this bug.