Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 20 additions & 43 deletions stl/inc/compare
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,7 @@ enum class _Compare_ord : _Compare_t { less = -1, greater = 1 };
enum class _Compare_ncmp : _Compare_t { unordered = -128 };

// CLASS partial_ordering
class partial_ordering {
public:
_NODISCARD constexpr explicit partial_ordering(const _Compare_eq _Value_) noexcept
: _Value(static_cast<_Compare_t>(_Value_)) {}
_NODISCARD constexpr explicit partial_ordering(const _Compare_ord _Value_) noexcept
: _Value(static_cast<_Compare_t>(_Value_)) {}
_NODISCARD constexpr explicit partial_ordering(const _Compare_ncmp _Value_) noexcept
: _Value(static_cast<_Compare_t>(_Value_)) {}

struct partial_ordering {
static const partial_ordering less;
static const partial_ordering equivalent;
static const partial_ordering greater;
Expand Down Expand Up @@ -98,32 +90,25 @@ public:
// The stored value is either less (0xff), equivalent (0x00), greater (0x01), or unordered (0x80).
// Subtracting from 0 produces either 0x01, 0x00, 0xff, or 0x80. Note that the effect is to
// exchange less for greater (and vice versa), while leaving equivalent and unordered unchanged.
return partial_ordering{static_cast<_Compare_ord>(0 - static_cast<unsigned int>(_Val._Value))};
return {static_cast<_Compare_t>(0 - static_cast<unsigned int>(_Val._Value))};
}

private:
_Compare_t _Value;
};

inline constexpr partial_ordering partial_ordering::less(_Compare_ord::less);
inline constexpr partial_ordering partial_ordering::equivalent(_Compare_eq::equivalent);
inline constexpr partial_ordering partial_ordering::greater(_Compare_ord::greater);
inline constexpr partial_ordering partial_ordering::unordered(_Compare_ncmp::unordered);
inline constexpr partial_ordering partial_ordering::less{static_cast<_Compare_t>(_Compare_ord::less)};
inline constexpr partial_ordering partial_ordering::equivalent{static_cast<_Compare_t>(_Compare_eq::equivalent)};
inline constexpr partial_ordering partial_ordering::greater{static_cast<_Compare_t>(_Compare_ord::greater)};
inline constexpr partial_ordering partial_ordering::unordered{static_cast<_Compare_t>(_Compare_ncmp::unordered)};

// CLASS weak_ordering
class weak_ordering {
public:
_NODISCARD constexpr explicit weak_ordering(const _Compare_eq _Value_) noexcept
: _Value(static_cast<_Compare_t>(_Value_)) {}
_NODISCARD constexpr explicit weak_ordering(const _Compare_ord _Value_) noexcept
: _Value(static_cast<_Compare_t>(_Value_)) {}

struct weak_ordering {
static const weak_ordering less;
static const weak_ordering equivalent;
static const weak_ordering greater;

constexpr operator partial_ordering() const noexcept {
return partial_ordering{static_cast<_Compare_ord>(_Value)};
return {static_cast<_Compare_t>(_Value)};
}

_NODISCARD friend constexpr bool operator==(const weak_ordering _Val, _Literal_zero) noexcept {
Expand Down Expand Up @@ -169,36 +154,29 @@ public:
}

_NODISCARD friend constexpr weak_ordering operator<=>(_Literal_zero, const weak_ordering _Val) noexcept {
return weak_ordering{static_cast<_Compare_ord>(-_Val._Value)};
return {static_cast<_Compare_t>(-_Val._Value)};
}

private:
_Compare_t _Value;
};

inline constexpr weak_ordering weak_ordering::less(_Compare_ord::less);
inline constexpr weak_ordering weak_ordering::equivalent(_Compare_eq::equivalent);
inline constexpr weak_ordering weak_ordering::greater(_Compare_ord::greater);
inline constexpr weak_ordering weak_ordering::less{static_cast<_Compare_t>(_Compare_ord::less)};
inline constexpr weak_ordering weak_ordering::equivalent{static_cast<_Compare_t>(_Compare_eq::equivalent)};
inline constexpr weak_ordering weak_ordering::greater{static_cast<_Compare_t>(_Compare_ord::greater)};

// CLASS strong_ordering
class strong_ordering {
public:
_NODISCARD constexpr explicit strong_ordering(const _Compare_eq _Value_) noexcept
: _Value(static_cast<_Compare_t>(_Value_)) {}
_NODISCARD constexpr explicit strong_ordering(const _Compare_ord _Value_) noexcept
: _Value(static_cast<_Compare_t>(_Value_)) {}

struct strong_ordering {
static const strong_ordering less;
static const strong_ordering equal;
static const strong_ordering equivalent;
static const strong_ordering greater;

constexpr operator partial_ordering() const noexcept {
return partial_ordering{static_cast<_Compare_ord>(_Value)};
return {static_cast<_Compare_t>(_Value)};
}

constexpr operator weak_ordering() const noexcept {
return weak_ordering{static_cast<_Compare_ord>(_Value)};
return {static_cast<_Compare_t>(_Value)};
}

_NODISCARD friend constexpr bool operator==(const strong_ordering _Val, _Literal_zero) noexcept {
Expand Down Expand Up @@ -244,17 +222,16 @@ public:
}

_NODISCARD friend constexpr strong_ordering operator<=>(_Literal_zero, const strong_ordering _Val) noexcept {
return strong_ordering{static_cast<_Compare_ord>(-_Val._Value)};
return {static_cast<_Compare_t>(-_Val._Value)};
}

private:
_Compare_t _Value;
};

inline constexpr strong_ordering strong_ordering::less(_Compare_ord::less);
inline constexpr strong_ordering strong_ordering::equal(_Compare_eq::equal);
inline constexpr strong_ordering strong_ordering::equivalent(_Compare_eq::equivalent);
inline constexpr strong_ordering strong_ordering::greater(_Compare_ord::greater);
inline constexpr strong_ordering strong_ordering::less{static_cast<_Compare_t>(_Compare_ord::less)};
inline constexpr strong_ordering strong_ordering::equal{static_cast<_Compare_t>(_Compare_eq::equal)};
inline constexpr strong_ordering strong_ordering::equivalent{static_cast<_Compare_t>(_Compare_eq::equivalent)};
inline constexpr strong_ordering strong_ordering::greater{static_cast<_Compare_t>(_Compare_ord::greater)};

// FUNCTION is_eq
_NODISCARD constexpr bool is_eq(const partial_ordering _Comp) noexcept {
Expand Down