On 6/11/11 8:25 AM, Michel Fortin wrote:
On 2011-06-11 09:05:52 -0400, "Steven Schveighoffer"
<schvei...@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.

Agreed. I'll venture to add that I find the first also more desirable than an implicit conversion from func(expression).

Andrei

Reply via email to