Is the world coming to an end?

Nick Sabalausky a at a.a
Sun Apr 3 12:40:18 PDT 2011


"Andrej Mitrovic" <andrej.mitrovich at gmail.com> wrote in message 
news:mailman.3093.1301858962.4748.digitalmars-d at puremagic.com...
> On 4/3/11, Nick Sabalausky <a at a.a> wrote:
>> I've always thought that we should be able to do something like this:
>>
>> template foo(int val)
>> {
>>     enum foo = val.meta.argString;
>> }
>> static assert(foo!(2+3) == "2+3");
>>
>
> I wish we had some introspection to get the lines of code inside of a
> function. But it's still pretty cool that you can pass expressions to
> functions and automatically construct delegates. See here:
>
> import std.stdio;
>
> void main()
> {
>    int x;
>
>    foo(false, x = 5);
>    assert(x != 5);
>
>    foo(true, x = 5);
>    assert(x == 5);
> }
>
> void foo(bool doit, int delegate()[] dgs ...)
> {
>    if (doit)
>        dgs[0]();
> }
>
> I wonder how many people know about this feature. I just bumped into
> it a few days ago while looking through the docs.

I didn't know that. I think I remember the idea of it being discussed, but I 
didn't know it was in.





More information about the Digitalmars-d mailing list