Creating a composite type from two enum classes, ready for STL map

后端 未结 6 1698
星月不相逢
星月不相逢 2021-02-14 05:26

I would like to create a composite type out of two enum classes.

enum class Color {RED, GREEN, BLUE};
enum class Shape {SQUARE, CIRCLE, TRIANGLE};

         


        
6条回答
  •  伪装坚强ぢ
    2021-02-14 05:50

    Consider using simply std::tuple as the "composite enum." This will come with comparison operators already defined for you, using a dictionary ordering. For example, valid code:

    bool b = std::make_tuple(Color::RED, Shape::CIRCLE)
           < std::make_tuple(Color::GREEN, Shape::SQUARE);
    

提交回复
热议问题