From a209f961a67e9675bc34810ba66207b7a4028206 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 4 Jul 2016 18:12:16 +0100 Subject: [PATCH] refs #698 Added unorderedEqualsByKeys method for sequences. --- src/blackmisc/sequence.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/blackmisc/sequence.h b/src/blackmisc/sequence.h index f17673b4d..4180d4d30 100644 --- a/src/blackmisc/sequence.h +++ b/src/blackmisc/sequence.h @@ -463,6 +463,16 @@ namespace BlackMisc return partiallySorted(n, BlackMisc::Predicates::MemberLess(key1, keys...)); } + //! Return true if this container equals another container, considering only the given element members. + //! Order of elements is not considered; this is implemented using a transient sort, so don't overuse. + template + bool unorderedEqualsByKeys(const U &other, Key0 k0, Keys... keys) const + { + if (equalPointers(this, &other)) { return true; } + if (size() != other.size()) { return false; } + return sorted(k0, keys...).equalsByKeys(other.sorted(k0, keys...)); + } + //! Split up the sequence into subsequences for which the given predicate returns the same value. template auto separate(Predicate p) const -> QMap())), CSequence>