samedi 18 mai 2019

Scoped Enums (enum class) relational operators

I've looked all over the place and I can't believe this question has not been asked before.

Is the ordering of enum class defined in the standard? Say if I have the following

enum class Fruits {Apple, Orange, Tomato};

int main(){

   std::cout << (Fruits::Apple < Fruits::Orange);
   std::cout << (Fruits::Orange > Fruits::Tomato);
   return 0;
}


output:
1 0

This outputs 1 0 in g++. But is this standard or compiler specific?

Aucun commentaire:

Enregistrer un commentaire