digitalmars.D - Extending UFCS
- Piotr Szturmaj (25/25) Aug 29 2012 The current possibility of UFCS is:
- Piotr Szturmaj (17/18) Aug 29 2012 Another example:
- Tommi (5/5) Aug 30 2012 A similar feature suggestion over there:
- Jacob Carlborg (4/29) Aug 29 2012 I would like to have this feature. I've asked about it before.
- Tommi (7/32) Aug 29 2012 See my suggestion for a similar feature:
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");
Aug 29 2012
Piotr Szturmaj wrote:and instead of writing hash!SHA1("abc"), write SHA1.hash("abc");Another example: template MutablePointer(T) { alias PointerTarget!(Unqual!T) MutablePointer; } alias const(int) CInt; static assert(is(MutablePointer!CInt == int*)); Alternative syntax: template MutablePointer(T) { alias T.Unqual.PointerTarget MutablePointer; } alias const(int) CInt; static assert(is(CInt.MutablePointer == int*)); This is just for convenience, as with UFCS. Second syntax is IMO a lot cleaner.
Aug 29 2012
A similar feature suggestion over there: http://forum.dlang.org/thread/uufohvapbyceuaylostl forum.dlang.org Also notice the enhancement request I made, there's more discussion about it: http://d.puremagic.com/issues/show_bug.cgi?id=8381
Aug 30 2012
On 2012-08-29 22:20, Piotr Szturmaj wrote: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");I would like to have this feature. I've asked about it before. -- /Jacob Carlborg
Aug 29 2012
On Wednesday, 29 August 2012 at 20:20:04 UTC, Piotr Szturmaj wrote: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");See my suggestion for a similar feature: http://forum.dlang.org/thread/uufohvapbyceuaylostl forum.dlang.org And notice the enhancement request I made. There's more discussion there: http://d.puremagic.com/issues/show_bug.cgi?id=8381
Aug 29 2012