On Saturday, 18 February 2012 at 08:18:32 UTC, Denis Shelomovskij wrote:
Some remarks:
0. `string[] args` isn't needed;
1. `delegate` is not needed;
2. `isSomeString!(T)` can be replaced by `isSomeString!T`;
3. `static if` can be replaced by `auto m = mixin(isSomeString!T ? "n ~ i" : "n + i");`;
4. With nnew `=>` syntax function body can be replaced by
`return (T i) => mixin(isSomeString!T ? "n ~ i" : "n + i");`
or
`return (T i) => mixin("n" ~ (isSomeString!T ? '~' : '+') ~ 'i');`


So your code can looks like this:
---
import std.stdio, std.traits;

void main() {
    auto foo(T)(T n) {
return (T i) => mixin("n" ~ (isSomeString!T ? '~' : '+') ~ 'i');
    }
    writeln(foo("Hello")(" World!"));
    writeln(foo(18)(24));
}

IMHO, all these three versions should be on the site grouped somehow (i.e. one can navigate between analogous).

Ahhh, thats much cleaner, thanks.

Reply via email to