Bug 19475 – add a staticIndexOf overload taking a pred

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-12-11T09:58:48Z
Last change time
2024-12-01T16:34:36Z
Assigned to
No Owner
Creator
basile-z
Moved to GitHub: phobos#9767 →

Comments

Comment #0 by b2.temp — 2018-12-11T09:58:48Z
Overloads of std.meta.staticIndexOf allow only to find an exact needle but in some case it more useful to get the index of something based on a predicate, for example to get the index of a compile time value that partially matches (e.g member value of a struct used as UDA). It even may be better to name them firstStaticIndexOf lastStaticIndexOf
Comment #1 by simen.kjaras — 2018-12-11T13:52:18Z
This can be trivially done as a combination of existing templates: import std.meta; enum predStaticIndexOf(alias Fn, T...) = staticIndexOf!(true, staticMap!(Fn, T)); template MoreThan2(T...) { enum MoreThan2 = T[0] > 2; } unittest { static assert(predStaticIndexOf!(MoreThan2, 1,2,3) == 2); }
Comment #2 by robert.schadek — 2024-12-01T16:34:36Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9767 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB