Re: [PATCH 1/8] gdbsupport: Provide global operators |=, &=, and ^= for enum bit flags

Pedro Alves
2020-08-20T16:00:47Z

On 8/17/20 11:40 AM, Andrew Burgess wrote:
>> Andrew> The current enum bit flags mechanism provides global operators &, |,
>> Andrew> ^, ~, but does not provide &=, |=, ^=.
>>
>> Andrew> The implementation for one of these, |=, would look like this:
>>
>> Andrew> template <typename enum_type>
>> Andrew> typename enum_flags_type<enum_type>::type &
>> Andrew> operator|= (enum_type &e1, enum_type e2)
>>
>> Why "enum_type &e1" and not "enum_flags_type<enum_type>::type &e1"
>> here?

The

typename enum_flags_type<enum_type>::type

in the return type is written that way instead of simply

enum_flags<enum_type> &
operator|= (enum_type &e1, enum_type e2)

in order to have SFINAE disable the function if
enum_flags_type<enum_type> is not defined for the flags
type. I.e., that's what makes sure the function is only
defined for enums we only want it defined for.

There's no point in doing the SFINAE trick in both the return type
and in the parameters.