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};
As commented and as already stated by others, give precedence to either Shape
or Color
in the operator<
and only compare the other if the first is equal.
An alternative implementation for operator<
using std::tie:
#include
friend bool operator<(const Object& lhs, const Object& rhs)
{
return std::tie(lhs.color, lhs.shape) < std::tie(rhs.color, rhs.shape);
}