UFCS not working with alias
Andre Pany via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Sep 8 08:29:01 PDT 2016
On Thursday, 8 September 2016 at 13:38:54 UTC, Steven
Schveighoffer wrote:
>
> There is a workaround, identified by Vladimir Panteleev
> (https://blog.thecybershadow.net/2015/04/28/the-amazing-template-that-does-nothing/):
>
>
> import std.algorithm;
> bool fulfillsKeyPredicate(string s, string t) {return true;}
>
> alias I(alias x) = x;
>
> void main(string[] args)
> {
> alias keyPredicateFilter = filter!(e =>
> e.fulfillsKeyPredicate(args[0]));
> string[] arr;
>
> keyPredicateFilter(arr);
> arr.I!keyPredicateFilter;
> }
>
> Unfortunately, you can't alias the I!someSymbol, as that has
> the same problem.
>
> -Steve
Thanks for this insight. In my case I prepare a presentation
about D
(audience doesn't now anything about D)
and tried to make my D code as beautiful as possible. As solution
I created now a free template method and hide it in a library
module.
T[] filterByKeyPredicate(T)(T[] arr, string[string] keyPredicate)
{
...filter!....
}
This way I can use UFCS.
Kind regards
André
More information about the Digitalmars-d-learn
mailing list