Flag proposal
Michel Fortin
michel.fortin at michelf.com
Sat Jun 11 06:25:19 PDT 2011
On 2011-06-11 09:05:52 -0400, "Steven Schveighoffer"
<schveiguy at yahoo.com> said:
> As far as the negation, I think we need one more layer of type:
>
> struct FlagParam(string pname)
> {
> Flag!pname value;
> alias value this;
> this(Flag!pname x) { this.value = x }
> FlagParam op???() const { return FlagParam(cast(Flag!pname)!value); }
> }
>
> BTW, is there a way to hook "!"? Maybe this won't work... The idea is
> to have Yes.abc return FlagParam!"abc"(Flag!"abc".yes).
If you need to convert a bool to a Flag!"abc", you can do any of these:
func(expression ? Yes.abc : No.abc);
or
func(cast(Flag!"abc")expression);
or, with your proposal:
func(FlagParam!"abc"(expression));
None of this is very appealing, but I find the first is the most readable.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list