diff --git a/Telegram/SourceFiles/data/data_msg_id.h b/Telegram/SourceFiles/data/data_msg_id.h index 45d43644bb..b7c12a0af8 100644 --- a/Telegram/SourceFiles/data/data_msg_id.h +++ b/Telegram/SourceFiles/data/data_msg_id.h @@ -35,6 +35,8 @@ struct MsgId { constexpr MsgId operator--(int) noexcept { return bare--; } + constexpr auto operator<=>(const MsgId &other) const = default; + constexpr bool operator==(const MsgId &other) const = default; int64 bare = 0; }; @@ -49,30 +51,6 @@ Q_DECLARE_METATYPE(MsgId); return MsgId(a.bare - b.bare); } -[[nodiscard]] inline constexpr bool operator==(MsgId a, MsgId b) noexcept { - return (a.bare == b.bare); -} - -[[nodiscard]] inline constexpr bool operator!=(MsgId a, MsgId b) noexcept { - return (a.bare != b.bare); -} - -[[nodiscard]] inline constexpr bool operator<(MsgId a, MsgId b) noexcept { - return (a.bare < b.bare); -} - -[[nodiscard]] inline constexpr bool operator>(MsgId a, MsgId b) noexcept { - return (a.bare > b.bare); -} - -[[nodiscard]] inline constexpr bool operator<=(MsgId a, MsgId b) noexcept { - return (a.bare <= b.bare); -} - -[[nodiscard]] inline constexpr bool operator>=(MsgId a, MsgId b) noexcept { - return (a.bare >= b.bare); -} - constexpr auto StartClientMsgId = MsgId(0x01 - (1LL << 58)); constexpr auto EndClientMsgId = MsgId(-(1LL << 57)); constexpr auto ServerMaxMsgId = MsgId(1LL << 56); @@ -132,52 +110,13 @@ struct FullMsgId { constexpr bool operator!() const noexcept { return msg == 0; } + constexpr auto operator<=>(const FullMsgId &other) const = default; + constexpr bool operator==(const FullMsgId &other) const = default; ChannelId channel = NoChannel; MsgId msg = 0; }; -[[nodiscard]] inline constexpr bool operator<( - const FullMsgId &a, - const FullMsgId &b) noexcept { - if (a.channel < b.channel) { - return true; - } else if (a.channel > b.channel) { - return false; - } - return a.msg < b.msg; -} - -[[nodiscard]] inline constexpr bool operator>( - const FullMsgId &a, - const FullMsgId &b) noexcept { - return b < a; -} - -[[nodiscard]] inline constexpr bool operator<=( - const FullMsgId &a, - const FullMsgId &b) noexcept { - return !(b < a); -} - -[[nodiscard]] inline constexpr bool operator>=( - const FullMsgId &a, - const FullMsgId &b) noexcept { - return !(a < b); -} - -[[nodiscard]] inline constexpr bool operator==( - const FullMsgId &a, - const FullMsgId &b) noexcept { - return (a.channel == b.channel) && (a.msg == b.msg); -} - -[[nodiscard]] inline constexpr bool operator!=( - const FullMsgId &a, - const FullMsgId &b) noexcept { - return !(a == b); -} - Q_DECLARE_METATYPE(FullMsgId); namespace std { diff --git a/Telegram/SourceFiles/data/data_peer_id.h b/Telegram/SourceFiles/data/data_peer_id.h index 5944173d56..5702a48c2c 100644 --- a/Telegram/SourceFiles/data/data_peer_id.h +++ b/Telegram/SourceFiles/data/data_peer_id.h @@ -34,103 +34,15 @@ struct ChatIdType { [[nodiscard]] constexpr bool operator!() const noexcept { return !bare; } + [[nodiscard]] constexpr auto operator<=>(const ChatIdType &other) const = default; + [[nodiscard]] constexpr bool operator==(const ChatIdType &other) const = default; + constexpr auto operator<=>(PeerIdZero) const = delete; + [[nodiscard]] constexpr bool operator==(PeerIdZero) const noexcept { + return (bare == 0); + } }; -template -[[nodiscard]] inline constexpr bool operator==( - ChatIdType a, - ChatIdType b) noexcept { - return (a.bare == b.bare); -} - -template -[[nodiscard]] inline constexpr bool operator!=( - ChatIdType a, - ChatIdType b) noexcept { - return (a.bare != b.bare); -} - -template -[[nodiscard]] inline constexpr bool operator<( - ChatIdType a, - ChatIdType b) noexcept { - return (a.bare < b.bare); -} - -template -[[nodiscard]] inline constexpr bool operator>( - ChatIdType a, - ChatIdType b) noexcept { - return (a.bare > b.bare); -} - -template -[[nodiscard]] inline constexpr bool operator<=( - ChatIdType a, - ChatIdType b) noexcept { - return (a.bare <= b.bare); -} - -template -[[nodiscard]] inline constexpr bool operator>=( - ChatIdType a, - ChatIdType b) noexcept { - return (a.bare >= b.bare); -} - -template -[[nodiscard]] inline constexpr bool operator==( - ChatIdType a, - PeerIdZero) noexcept { - return (a.bare == 0); -} - -template -[[nodiscard]] inline constexpr bool operator==( - PeerIdZero, - ChatIdType a) noexcept { - return (0 == a.bare); -} - -template -[[nodiscard]] inline constexpr bool operator!=( - ChatIdType a, - PeerIdZero) noexcept { - return (a.bare != 0); -} - -template -[[nodiscard]] inline constexpr bool operator!=( - PeerIdZero, - ChatIdType a) noexcept { - return (0 != a.bare); -} - -template -bool operator<(ChatIdType, PeerIdZero) = delete; - -template -bool operator<(PeerIdZero, ChatIdType) = delete; - -template -bool operator>(ChatIdType, PeerIdZero) = delete; - -template -bool operator>(PeerIdZero, ChatIdType) = delete; - -template -bool operator<=(ChatIdType, PeerIdZero) = delete; - -template -bool operator<=(PeerIdZero, ChatIdType) = delete; - -template -bool operator>=(ChatIdType, PeerIdZero) = delete; - -template -bool operator>=(PeerIdZero, ChatIdType) = delete; - using UserId = ChatIdType<0>; using ChatId = ChatIdType<1>; using ChannelId = ChatIdType<2>; @@ -177,65 +89,15 @@ struct PeerId { return !value; } + [[nodiscard]] constexpr auto operator<=>(const PeerId &other) const = default; + [[nodiscard]] constexpr bool operator==(const PeerId &other) const = default; + constexpr auto operator<=>(PeerIdZero) const = delete; + [[nodiscard]] constexpr bool operator==(PeerIdZero) const noexcept { + return (value == 0); + } + }; -[[nodiscard]] inline constexpr bool operator==(PeerId a, PeerId b) noexcept { - return (a.value == b.value); -} - -[[nodiscard]] inline constexpr bool operator!=(PeerId a, PeerId b) noexcept { - return (a.value != b.value); -} - -[[nodiscard]] inline constexpr bool operator<(PeerId a, PeerId b) noexcept { - return (a.value < b.value); -} - -[[nodiscard]] inline constexpr bool operator>(PeerId a, PeerId b) noexcept { - return (a.value > b.value); -} - -[[nodiscard]] inline constexpr bool operator<=(PeerId a, PeerId b) noexcept { - return (a.value <= b.value); -} - -[[nodiscard]] inline constexpr bool operator>=(PeerId a, PeerId b) noexcept { - return (a.value >= b.value); -} - -[[nodiscard]] inline constexpr bool operator==( - PeerId a, - PeerIdZero) noexcept { - return (a.value == 0); -} - -[[nodiscard]] inline constexpr bool operator==( - PeerIdZero, - PeerId a) noexcept { - return (0 == a.value); -} - -[[nodiscard]] inline constexpr bool operator!=( - PeerId a, - PeerIdZero) noexcept { - return (a.value != 0); -} - -[[nodiscard]] inline constexpr bool operator!=( - PeerIdZero, - PeerId a) noexcept { - return (0 != a.value); -} - -bool operator<(PeerId, PeerIdZero) = delete; -bool operator<(PeerIdZero, PeerId) = delete; -bool operator>(PeerId, PeerIdZero) = delete; -bool operator>(PeerIdZero, PeerId) = delete; -bool operator<=(PeerId, PeerIdZero) = delete; -bool operator<=(PeerIdZero, PeerId) = delete; -bool operator>=(PeerId, PeerIdZero) = delete; -bool operator>=(PeerIdZero, PeerId) = delete; - [[nodiscard]] inline constexpr bool peerIsUser(PeerId id) noexcept { return id.is(); } diff --git a/Telegram/SourceFiles/dialogs/dialogs_key.h b/Telegram/SourceFiles/dialogs/dialogs_key.h index 2f5967b45b..3ade07b173 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_key.h +++ b/Telegram/SourceFiles/dialogs/dialogs_key.h @@ -40,29 +40,8 @@ public: Data::Folder *folder() const; PeerData *peer() const; - inline bool operator<(const Key &other) const { - return _value < other._value; - } - inline bool operator>(const Key &other) const { - return (other < *this); - } - inline bool operator<=(const Key &other) const { - return !(other < *this); - } - inline bool operator>=(const Key &other) const { - return !(*this < other); - } - inline bool operator==(const Key &other) const { - return _value == other._value; - } - inline bool operator!=(const Key &other) const { - return !(*this == other); - } - - // Not working :( - //friend inline auto value_ordering_helper(const Key &key) { - // return key.value; - //} + constexpr auto operator<=>(const Key &other) const = default; + constexpr bool operator==(const Key &other) const = default; private: Entry *_value = nullptr; @@ -74,41 +53,24 @@ struct RowDescriptor { RowDescriptor(Key key, FullMsgId fullId) : key(key), fullId(fullId) { } + constexpr auto operator<=>(const RowDescriptor &other) const noexcept { + if (const auto result = (key <=> other.key); result != 0) { + return result; + } else if (!fullId.msg && !other.fullId.msg) { + return (fullId.msg <=> other.fullId.msg); + } else { + return (fullId <=> other.fullId); + } + } + constexpr bool operator==(const RowDescriptor &other) const noexcept { + return ((*this) <=> other) == 0; + } + Key key; FullMsgId fullId; }; -inline bool operator==(const RowDescriptor &a, const RowDescriptor &b) { - return (a.key == b.key) - && ((a.fullId == b.fullId) || (!a.fullId.msg && !b.fullId.msg)); -} - -inline bool operator!=(const RowDescriptor &a, const RowDescriptor &b) { - return !(a == b); -} - -inline bool operator<(const RowDescriptor &a, const RowDescriptor &b) { - if (a.key < b.key) { - return true; - } else if (a.key > b.key) { - return false; - } - return a.fullId < b.fullId; -} - -inline bool operator>(const RowDescriptor &a, const RowDescriptor &b) { - return (b < a); -} - -inline bool operator<=(const RowDescriptor &a, const RowDescriptor &b) { - return !(b < a); -} - -inline bool operator>=(const RowDescriptor &a, const RowDescriptor &b) { - return !(a < b); -} - struct EntryState { enum class Section { History,