On 04/11/2011 08:16 PM, KennyTM~ wrote:
If the goal of YesOrNo is simply for documentation, why not define it like this?
import std.stdio;
template YesOrNo(T) if(is(T == enum) && !T.no && T.yes) {
alias T YesOrNo;
}
enum Redraw : bool { no, yes }
void drawCircle(YesOrNo!Redraw redraw) {
writeln(cast(bool) redraw);
}
void main() {
drawCircle(Redraw.yes);
drawCircle(Redraw.no);
// drawCircle(false); (cannot implicitly convert expression (false) of
type bool to Redraw)
}
Very nice, indeed. Also the side-effect that forces the caller to write
readable code ;-)
Denis
--
_________________
vita es estrany
spir.wikidot.com