QFlatMap: fix is_transparent detection

Add a level of indirection via void_t such that

    struct is_transparent {};

works, and not just

    using is_transparent = <unspecified>;

Pick-to: 6.3
Change-Id: I3ca2af6a07e6989dc95abc10fb2d0078a5269e5b
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
bb10
Marc Mutz 2022-01-28 10:48:49 +01:00
parent 2b617a29dc
commit 58e8ae5605
2 changed files with 26 additions and 3 deletions

View File

@ -417,7 +417,7 @@ private:
struct is_marked_transparent_type : std::false_type { };
template <class X>
struct is_marked_transparent_type<X, typename X::is_transparent> : std::true_type { };
struct is_marked_transparent_type<X, std::void_t<typename X::is_transparent>> : std::true_type { };
template <class X>
using is_marked_transparent = typename std::enable_if<

View File

@ -52,10 +52,15 @@ private slots:
void extraction();
void iterators();
void statefulComparator();
void transparency();
void transparency_using();
void transparency_struct();
void try_emplace_and_insert_or_assign();
void viewIterators();
void varLengthArray();
private:
template <typename Compare>
void transparency_impl();
};
void tst_QFlatMap::constructing()
@ -405,7 +410,7 @@ void tst_QFlatMap::statefulComparator()
QVERIFY(m2.key_comp().count > m1.key_comp().count);
}
void tst_QFlatMap::transparency()
void tst_QFlatMap::transparency_using()
{
struct StringViewCompare
{
@ -415,7 +420,25 @@ void tst_QFlatMap::transparency()
return lhs < rhs;
}
};
transparency_impl<StringViewCompare>();
}
void tst_QFlatMap::transparency_struct()
{
struct StringViewCompare
{
struct is_transparent {};
bool operator()(QAnyStringView lhs, QAnyStringView rhs) const
{
return lhs < rhs;
}
};
transparency_impl<StringViewCompare>();
}
template <typename StringViewCompare>
void tst_QFlatMap::transparency_impl()
{
using Map = QFlatMap<QString, QString, StringViewCompare>;
auto m = Map{ { "one", "een" }, { "two", "twee" }, { "three", "dree" } };