diff --git a/src/corelib/tools/qminimalflatset_p.h b/src/corelib/tools/qminimalflatset_p.h index c6466cf361..6074688f6e 100644 --- a/src/corelib/tools/qminimalflatset_p.h +++ b/src/corelib/tools/qminimalflatset_p.h @@ -16,6 +16,7 @@ // #include +#include // CompactStorage #include //#define QMINIMAL_FLAT_SET_DEBUG @@ -29,7 +30,7 @@ #endif #include // for std::lower_bound -#include // for std::less +#include // for std::less, std::ref QT_BEGIN_NAMESPACE @@ -43,20 +44,26 @@ QT_BEGIN_NAMESPACE bit, we can consider moving it as QFlatSet alongside QFlatMap. */ -template > -class QMinimalFlatSet +template , typename Compare = std::less> +class QMinimalFlatSet : QtPrivate::CompactStorage { Container c; + using CompareStorage = QtPrivate::CompactStorage; public: - // compiler-generated default ctor is ok! - // compiler-generated copy/move ctor/assignment operators are ok! - // compiler-generated dtor is ok! + QMinimalFlatSet() = default; + explicit QMinimalFlatSet(const Compare &cmp) : CompareStorage{cmp} {} + // Rule Of Zero applies using const_iterator = typename Container::const_iterator; using iterator = const_iterator; using const_reverse_iterator = typename Container::const_reverse_iterator; using reverse_iterator = const_reverse_iterator; using value_type = T; + using key_compare = Compare; + using value_compare = Compare; + + key_compare key_comp() const { return this->object(); } + value_compare value_comp() const { return key_comp(); } iterator begin() const { return c.cbegin(); } iterator end() const { return c.cend(); } @@ -121,7 +128,7 @@ private: bool exists; }; - auto cmp = std::less{}; + auto cmp = std::ref(this->object()); // don't let std::lower_bound copy it const auto it = std::lower_bound(c.cbegin(), c.cend(), v, cmp); return R{it, it != c.cend() && !cmp(v, *it)};