Re: using enum classes for enumerated CSS property values in nsStyleConsts.h

Daniel Holbert <[email protected]>
Newsgroups gmane.comp.mozilla.devel.layout
Message-ID <[email protected]>
On 11/10/2015 11:24 PM, Xidorn Quan wrote:
> On Wed, Nov 11, 2015 at 6:21 PM, Daniel Holbert <[email protected]> wrote:
>>
>> P.S. (I can work around this by adding an "operator bool" to the
>> CastableTypedEnumResult type-definition in mfbt/TypedEnumBits.h. Maybe
>> that's something we should do.)
> 
> We should just add "explicit operator bool() const;" to
> CastableTypedEnumResult, which we are allowed to use since VS2012
> support was dropped.

Cool -- though, are you sure we'd want "explicit"?

The point of my email was that *implicit* conversion to bool is
convenient & desirable (IMO) for these bitmask types, particularly when
passing them as a boolean function-argument.

I don't see too much danger from bool-conversion here, and I'd much
rather type:
  SomeFunc(foo | MyMaskType::SomeBit);

...rather than having to use explicit conversion like:
  SomeFunc(static_cast<bool>(foo | MyMaskType::SomeBit)));

If we use the "explicit" keyword, then we'd have to resort to the second
example here. (or we'd have to use "!!", or we'd have to rewrite
SomeFunc to stop taking a bool)

~Daniel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.