The D Scripting Language

Simen kjaeraas simen.kjaras at gmail.com
Mon Nov 15 09:40:13 PST 2010


Per Ångström <d-news at autark.se> wrote:

> /++
> Simulates type-returning or-expression
> +/
> template or(T) {
>      T _(T a, lazy T b) {T tmp = a; return tmp ? tmp : b;}
> }

You should probably use a function template[1] or at least an eponymous  
template here:

// function template:
auto or( T )( T a, lazy T b ) {
     return a ? a : b;
}

// eponymous template:
template or( T ) {
     auto or( T a, lazy T b ) {
         return a ? a : b;
     }
}

[1]: http://digitalmars.com/d/2.0/template.html#function-templates


-- 
Simen


More information about the Digitalmars-d mailing list