digitalmars.D.learn - anonymous template predicates
- Vlad Levenfeld (13/13) Apr 30 2015 I was wondering if there's a mechanism to make anonymous
- Idan Arye (3/16) Apr 30 2015 The syntax is a bit ugly, but it can be done:
I was wondering if there's a mechanism to make anonymous
templates, e.g.
given:
enum Policy {A, B}
alias List = TypeTuple!(...);
instead of this:
enum has_policy_A (T) = T.policy == Policy.A;
alias Result = Filter!(has_policy_A, List);
use something like this:
Filter!(T => T.policy == Policy.A, List);
I've tried templates that generate eponymous predicates from
mixed-in strings but these have a number of caveats that limit
their usability.
Apr 30 2015
On Thursday, 30 April 2015 at 21:01:36 UTC, Vlad Levenfeld wrote:
I was wondering if there's a mechanism to make anonymous
templates, e.g.
given:
enum Policy {A, B}
alias List = TypeTuple!(...);
instead of this:
enum has_policy_A (T) = T.policy == Policy.A;
alias Result = Filter!(has_policy_A, List);
use something like this:
Filter!(T => T.policy == Policy.A, List);
I've tried templates that generate eponymous predicates from
mixed-in strings but these have a number of caveats that limit
their usability.
The syntax is a bit ugly, but it can be done:
http://dpaste.dzfl.pl/d17912ccdeb9
Apr 30 2015








"Idan Arye" <GenericNPC gmail.com>