c++11 - C++ Standard doesn't say anything about operator!=() and operator==() for enum classes -


section 7.2 enumeration declarations doesn't operator!=() , operator==() scoped enumeration. code below compiles.

#include <iostream>  enum class month{jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov , dec};  int main() {     month = month::feb;     month b = month::jul;     month c = a;      if( != b ) std::cout << "a |= b" << '\n';     if( == c ) std::cout << "a == c" << '\n'; } 

the built-in operators specified in 5.10:

the == (equal to) , != (not equal to) operators have same semantic restrictions, conversions, , result type relational operators except lower precedence , truth-value result.

this defers specification of relational operators in 5.9; enumerations that's specified 5.9/5:

if both operands (after conversions) of arithmetic or enumeration type, each of operators shall yield true if specified relationship true , false if false.

so, 1 might expect, comparison operators applicable enumerations, comparing numeric values.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -