On 2010-11-15 18:40, Simen kjaeraas wrote:
Per Ångström <d-n...@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
Great, using either of those makes this possible:
string s = or(func2("..."), "default");
Which is a lot less ugly.
Cheers,
--
Per Å.