How to use std.meta.Filter?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Apr 21 17:15:47 UTC 2018


On Saturday, April 21, 2018 16:05:22 Dr.No via Digitalmars-d-learn wrote:
> import std.meta : Filter;
> enum isNotReservedSymbol(string name) = name != "none" && name !=
> "lastToken";
> enum string[] members = staticMembers!Token;
> static foreach(member; Filter!(isNotReservedSymbol, members))
> {{
>
>
> This return the error:
>
>   Error: template instance `pred!(["none", "word", "n", "digits",
> "name", /* my whole array here */ ])  does not match template
> declaration isNotReservedSymbol(string name)
>
> how should have isNotReservedSymbol be defined?

std.meta.Filter operates on an AliasSeq, not a dynamic array. If you have an
array, then you can just use std.algorithm.iteration.filter with a normal
lambda.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list