W
woodbrian77
I'm trying to do a bitwise and of a uint8_t and a member
of a scoped enum.
Here's the type with the uint8_t:
struct cmw_user_input
{
uint8_t marshalling_bits;
::std::deque<cmw::File> headers;
::cmw::File middlefile;
uint16_t choices;
// some stuff removed.
};
Here's the enum:
enum class cmw_user_input_data_member_flags : ::std::uint8_t
{
headers=0x1
, middlefile=0x2
, choices=0x4
};
GCC and clang are OK with those, but don't like this:
void
cmw_user_input::MarshalMemberData :cmw::SendBuffer& buf) const
{
buf.Receive(marshalling_bits);
if(marshalling_bits&cmw_user_input_data_member_flags::headers){
buf.ReceiveGroup(false,headers);
}
// some stuff removed.
}
GCC says:
error: no match for 'operator&' (operand types are 'const uint8_t {aka const unsigned char}' and 'cmw_user_input_data_member_flags')
if(marshalling_bits&(cmw_user_input_data_member_flags::headers)){
-----------------------------------------------------------------------
If I add a static_cast to the if statement:
if(marshalling_bits&static_cast<uint8_t> (cmw_user_input_data_member_flags::headers)){
buf.ReceiveGroup(false,headers);
}
the compiler is OK with it. I guess the compilers are
doing what they're supposed to, but I'm not sure what to do.
In the code above, the scoped enum is being generated
based on cmw_user_input, so I don't think it will
work to make marshalling_bits be a
cmw_user_input_data_member_flags.
Is there a better option than the cast? Tia.
Brian
Ebenezer Enterprises - John 3:16.
http://webEbenezer.net
of a scoped enum.
Here's the type with the uint8_t:
struct cmw_user_input
{
uint8_t marshalling_bits;
::std::deque<cmw::File> headers;
::cmw::File middlefile;
uint16_t choices;
// some stuff removed.
};
Here's the enum:
enum class cmw_user_input_data_member_flags : ::std::uint8_t
{
headers=0x1
, middlefile=0x2
, choices=0x4
};
GCC and clang are OK with those, but don't like this:
void
cmw_user_input::MarshalMemberData :cmw::SendBuffer& buf) const
{
buf.Receive(marshalling_bits);
if(marshalling_bits&cmw_user_input_data_member_flags::headers){
buf.ReceiveGroup(false,headers);
}
// some stuff removed.
}
GCC says:
error: no match for 'operator&' (operand types are 'const uint8_t {aka const unsigned char}' and 'cmw_user_input_data_member_flags')
if(marshalling_bits&(cmw_user_input_data_member_flags::headers)){
-----------------------------------------------------------------------
If I add a static_cast to the if statement:
if(marshalling_bits&static_cast<uint8_t> (cmw_user_input_data_member_flags::headers)){
buf.ReceiveGroup(false,headers);
}
the compiler is OK with it. I guess the compilers are
doing what they're supposed to, but I'm not sure what to do.
In the code above, the scoped enum is being generated
based on cmw_user_input, so I don't think it will
work to make marshalling_bits be a
cmw_user_input_data_member_flags.
Is there a better option than the cast? Tia.
Brian
Ebenezer Enterprises - John 3:16.
http://webEbenezer.net