It seems pure ain't so pure after all
jerro
a at a.com
Mon Oct 1 13:29:27 PDT 2012
> private auto _funimpl(string s) {
> /* what was previously in fun(string) */
> }
>
> template fun(string s)
> {
> enum fun = _funimpl(s);
> }
>
> // usage:
>
> fun!("times"); // always executes _funimpl at compile time
>
> -Steve
You could even use this template:
template ct(alias f)
{
template ct(params...)
{
enum ct = f(params);
}
}
to define templates like this:
alias ct!((string s)
{
// function body...
}) fun;
or with this syntax:
alias ct!(a => a * a) pow2;
More information about the Digitalmars-d
mailing list