YesOrNo: useful idiom helper or wanking?
spir
denis.spir at gmail.com
Mon Apr 11 12:24:44 PDT 2011
On 04/11/2011 08:16 PM, KennyTM~ wrote:
> 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)
> }
If this gets used, would be good style to name the enum using the argument name
Capitalised, just like in your example (redraw --> Redraw).
Denis
--
_________________
vita es estrany
spir.wikidot.com
More information about the Digitalmars-d
mailing list