| 4 | #include <compare> // For std::partial_ordering (see Chapter 4) |
| 5 | |
| 6 | class Box |
| 7 | { |
| 8 | public: |
| 9 | // Constructors |
| 10 | Box() = default; |
| 11 | Box(double l, double w, double h) : m_length{ l }, m_width{ w }, m_height{ h } {} |
| 12 | |
| 13 | double volume() const { return m_length * m_width * m_height; } |
| 14 | |
| 15 | // Accessors |
| 16 | double getLength() const { return m_length; } |
| 17 | double getWidth() const { return m_width; } |
| 18 | double getHeight() const { return m_height; } |
| 19 | |
| 20 | std::partial_ordering operator<=>(const Box& otherBox) const |
| 21 | { |
| 22 | return volume() <=> otherBox.volume(); |
| 23 | } |
| 24 | std::partial_ordering operator<=>(double otherVolume) const |
| 25 | { |
| 26 | return volume() <=> otherVolume; |
| 27 | } |
| 28 | |
| 29 | bool operator==(const Box& otherBox) const |
| 30 | { |
| 31 | return m_length == otherBox.m_length |
| 32 | && m_width == otherBox.m_width |
| 33 | && m_height == otherBox.m_height; |
| 34 | } |
| 35 | |
| 36 | private: |
| 37 | double m_length{ 1.0 }; |
| 38 | double m_width{ 1.0 }; |
| 39 | double m_height{ 1.0 }; |
| 40 | }; |
| 41 | |
| 42 | #endif |
nothing calls this directly
no outgoing calls
no test coverage detected