Title
[tiny] contextual bool conversion from scoped enum
Status
nad
Section
[dcl.enum]
Submitter
Jeffrey Yasskin

Created on 2012-10-20.00:00:00 last changed 135 months ago

Messages

Date: 2013-04-28.20:20:29

In Beman's filesystem code, I found the following problem, which he didn't see because he's been building with MSVC 10: A scoped enum defined at

https://github.com/Beman/filesystem-proposal/blob/master/include/boost/filesystem/operations.hpp#L230

is used like

if (opts & copy_options::skip_existing) ++ct;

at

https://github.com/Beman/filesystem-proposal/blob/master/src/operations.cpp#L773.

This causes an error like:

../../../libs/filesystem/src/operations.cpp:773:9: error: value of type 'boost::filesystem::copy_options' is not contextually convertible to 'bool'

I believe it makes sense to define a contextual conversion to bool for certain scoped enumerations, but I don't see a way to do it. I do see a way to overload & to return bool, but that seems to prevent using & to remove bits from a value, which shouldn't always be prevented.

Bristol 2013: Stroustrup pointed out that the existing behavior is deliberately trying to avoid supporting anything like this, in order to play safe. He further explained that allowing member functions for scoped enums has been attempted but the attempts failed. Gregor pointed out that not all scoped enums have a zero value, so doing it generally is hard. Stroustrup said he would want to have member functions for enums. Yasskin said he's not interested in writing a paper. Other people are invited to do so.

History
Date User Action Args
2013-10-11 23:34:25adminsetstatus: open -> nad
2012-10-20 00:00:00admincreate