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