Extending UFCS

Piotr Szturmaj bncrbme at jadamspam.pl
Wed Aug 29 13:20:03 PDT 2012


The current possibility of UFCS is:

struct S { }
void func(S s) { }

S s;
s.func(); // equivalent of func(s);

why not add:

template sizeInInts(T)
{
     enum sizeInInts = T.sizeof / 4;
}

S.sizeInInts // equivalent of sizeInInts!S

Is it worth it? I mean adding static members to aggregate types.

Consider another example:

struct MD5 { ... }
struct SHA1 { ... }

string hash(Digest)(const(void)[] data)
     if (isDigest!Digest)
{
     Digest d;
     ubyte[DigestLen!Digest] h;
     d.put(cast(const(ubyte)[])data);
     d.finish(h);
     return xformat("%(%02x%)", h);
}

and instead of writing hash!SHA1("abc"), write SHA1.hash("abc");


More information about the Digitalmars-d mailing list