Extending UFCS to templates
Andrej Mitrovic
andrej.mitrovich at gmail.com
Fri Mar 2 13:18:22 PST 2012
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?
More information about the Digitalmars-d
mailing list