Reputation: 42371
Below is excerpted from cppreference link 1 and cppreference link 2:
enum codecvt_mode
{
consume_header = 4,
generate_header = 2,
little_endian = 1
};
template
<
class Elem,
unsigned long Maxcode = 0x10ffff,
std::codecvt_mode Mode = (std::codecvt_mode)0
>
class codecvt_utf8_utf16 : public std::codecvt<Elem, char, std::mbstate_t>;
Obviously, 0
is not a well-defined value of enum type codecvt_mode
. The C++ standard might intentionally leave the default value implementation-defined.
However, I think an implementation-defined default value can be vague to the user.
Why does C++11 define
std::codecvt_mode Mode = (std::codecvt_mode)0
rather than
std::codecvt_mode Mode = std::little_endian
?
Upvotes: 1
Views: 110
Reputation: 320541
0
is a valid value for your enum type. According to language standard enum types whose underlying type is not fixed (your case) can represent all integer values representable in a bit-field of sufficient width (sufficient to represent all named enum members you declared). The fact that you sometimes need an explicit cast to force all these value into that enum type is just a little inconvenience. This means that 0
is a valid value for any enum type.
Upvotes: 6
Reputation: 155438
The enumeration is a set of bit flags that can be combined (via bitwise operations), not values that are selected independently. A value of zero means none of the flags are active (which makes it big endian, and does not consume or generate a BOM).
Upvotes: 5