Is the world coming to an end?
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sun Apr 3 12:29:11 PDT 2011
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.
More information about the Digitalmars-d
mailing list