You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
Suppose a template function in global namespace:
template <class Enum>
inline bitwise_enum<Enum> operator | (Enum a, Enum b)
{
return bitwise_enum<Enum>(a) | bitwise_enum<Enum>(b);
}
This will overload and instantiate any operators with arbitrary type of
operands:
#include "bitwise_enums.h"
enum E {A = 1, B = 2};
int main (int argc, const char * argv[])
{
int x = A | B;
}
What is the expected output? What do you see instead?
It should compile.
The above would not compile because it selects the above template, and there is
no conversion from bitwise_enum to int. Anyway, it should not select this
operator at all.
Please provide any additional information below.
There is no easy solution to this problem, unless using strong type safe enums
proposed in C++0x.
A more elaborated solution would involve to use traits for selected types of
enums and use these traits to enable the operators defined in global namespace.
Using boost type traits and boost utility library may help to implement this.
Btw, embedding the bitwise_enum into a namespace does NOT solve the problem.
Original issue reported on code.google.com by [email protected] on 31 Aug 2011 at 2:06
Original issue reported on code.google.com by
[email protected]
on 31 Aug 2011 at 2:06The text was updated successfully, but these errors were encountered: