Extending UFCS to templates

Kapps opantm2+spam at gmail.com
Fri Mar 2 16:58:26 PST 2012


On Friday, 2 March 2012 at 21:18:31 UTC, Andrej Mitrovic wrote:
> I thought I'd be cool if we could use UFCS for templates. For 
> example
> instead of this:
>
> template isOneOf(X, T...)
> {
>     static if (!T.length)
>         enum bool isOneOf = false;
>     else static if (is(Unqual!X == T[0]))
>         enum bool isOneOf = true;
>     else
>         enum bool isOneOf = isOneOf!(Unqual!X, T[1..$]);
> }
>
> void test(T)(T t)
>     if (isOneOf!(T, int, double))
> { }
>
> void main() {
>     test(1);
> }
>
> We would be able use code like this:
>
> void test(T)(T t)
>     if (T.isOneOf!(int, double))  // UFCS (or maybe Uniform 
> Template
> Instantiation Syntax? :p)
> { }
>
> A far-fetched dream?

 From what I understand, UFCS should work on templates once 
properly implemented.
A.someNonExistentThing(params)
basically becomes
.someNonExistentThing(A, params)
I think that (at least in the current UFCS pull request) it 
*should* work, but I've never actually tried it.


More information about the Digitalmars-d mailing list