46 #include <forward_list>
47 #include <unordered_set>
48 #include <unordered_map>
50 #if defined(__cpp_lib_erase_if) && __cpp_lib_erase_if >= 202002L
51 # define STDLIB_HAS_UNIFORM_ERASURE
58 return os <<
c.toLatin1();
106 return d.nospace() <<
"Movable(" <<
m.i <<
")";
132 {
i =
o.i;
return *
this; }
138 {
return os <<
c.i; }
140 {
return os >>
c.i; }
152 return d.nospace() <<
"Complex(" <<
c.i <<
")";
176 return lhs.i ==
rhs.i;
181 return lhs.i !=
rhs.i;
186 return lhs.i <
rhs.i;
196 return lhs.i ==
rhs.i && lhs.j ==
rhs.j;
202 return d.nospace() <<
"DuplicateStrategyTestType(" <<
c.i <<
"," <<
c.j <<
")";
212 return hash<int>()(
m.i);
221 return hash<int>()(
m.i);
230 return hash<int>()(
m.i);
248 int m_movableInstanceCount;
249 int m_complexInstanceCount;
256 template <
typename Container>
257 void ranged_ctor_non_associative_impl()
const;
259 template<
template<
typename ...
T>
class Container>
260 void non_associative_container_duplicates_strategy()
const;
262 template <
typename Container>
263 void ranged_ctor_associative_impl()
const;
267 void ranged_ctor_std_vector_int() { ranged_ctor_non_associative_impl<std::vector<int>>(); }
268 void ranged_ctor_std_vector_char() { ranged_ctor_non_associative_impl<std::vector<char>>(); }
269 void ranged_ctor_std_vector_QChar() { ranged_ctor_non_associative_impl<std::vector<QChar>>(); }
270 void ranged_ctor_std_vector_Movable() { ranged_ctor_non_associative_impl<std::vector<Movable>>(); }
271 void ranged_ctor_std_vector_Complex() { ranged_ctor_non_associative_impl<std::vector<Complex>>(); }
272 void ranged_ctor_std_vector_duplicates_strategy() { non_associative_container_duplicates_strategy<std::vector>(); }
274 void ranged_ctor_QVarLengthArray_int() { ranged_ctor_non_associative_impl<QVarLengthArray<int>>(); }
275 void ranged_ctor_QVarLengthArray_Movable() { ranged_ctor_non_associative_impl<QVarLengthArray<Movable>>(); }
276 void ranged_ctor_QVarLengthArray_Complex() { ranged_ctor_non_associative_impl<QVarLengthArray<Complex>>(); }
277 void ranged_ctor_QVarLengthArray_duplicates_strategy() { non_associative_container_duplicates_strategy<VarLengthArray>(); }
279 void ranged_ctor_QList_int() { ranged_ctor_non_associative_impl<QList<int>>(); }
280 void ranged_ctor_QList_char() { ranged_ctor_non_associative_impl<QList<char>>(); }
281 void ranged_ctor_QList_QChar() { ranged_ctor_non_associative_impl<QList<QChar>>(); }
282 void ranged_ctor_QList_Movable() { ranged_ctor_non_associative_impl<QList<Movable>>(); }
283 void ranged_ctor_QList_Complex() { ranged_ctor_non_associative_impl<QList<Complex>>(); }
284 void ranged_ctor_QList_duplicates_strategy() { non_associative_container_duplicates_strategy<QList>(); }
286 void ranged_ctor_std_list_int() { ranged_ctor_non_associative_impl<std::list<int>>(); }
287 void ranged_ctor_std_list_Movable() { ranged_ctor_non_associative_impl<std::list<Movable>>(); }
288 void ranged_ctor_std_list_Complex() { ranged_ctor_non_associative_impl<std::list<Complex>>(); }
289 void ranged_ctor_std_list_duplicates_strategy() { non_associative_container_duplicates_strategy<std::list>(); }
291 void ranged_ctor_std_forward_list_int() { ranged_ctor_non_associative_impl<std::forward_list<int>>(); }
292 void ranged_ctor_std_forward_list_Movable() {ranged_ctor_non_associative_impl<std::forward_list<Movable>>(); }
293 void ranged_ctor_std_forward_list_Complex() { ranged_ctor_non_associative_impl<std::forward_list<Complex>>(); }
294 void ranged_ctor_std_forward_list_duplicates_strategy() { non_associative_container_duplicates_strategy<std::forward_list>(); }
296 void ranged_ctor_std_set_int() { ranged_ctor_non_associative_impl<std::set<int>>(); }
297 void ranged_ctor_std_set_Movable() { ranged_ctor_non_associative_impl<std::set<Movable>>(); }
298 void ranged_ctor_std_set_Complex() { ranged_ctor_non_associative_impl<std::set<Complex>>(); }
299 void ranged_ctor_std_set_duplicates_strategy() { non_associative_container_duplicates_strategy<std::set>(); }
301 void ranged_ctor_std_multiset_int() { ranged_ctor_non_associative_impl<std::multiset<int>>(); }
302 void ranged_ctor_std_multiset_Movable() { ranged_ctor_non_associative_impl<std::multiset<Movable>>(); }
303 void ranged_ctor_std_multiset_Complex() { ranged_ctor_non_associative_impl<std::multiset<Complex>>(); }
304 void ranged_ctor_std_multiset_duplicates_strategy() { non_associative_container_duplicates_strategy<std::multiset>(); }
306 void ranged_ctor_std_unordered_set_int() { ranged_ctor_non_associative_impl<std::unordered_set<int>>(); }
307 void ranged_ctor_std_unordered_set_Movable() { ranged_ctor_non_associative_impl<std::unordered_set<Movable>>(); }
308 void ranged_ctor_std_unordered_set_Complex() { ranged_ctor_non_associative_impl<std::unordered_set<Complex>>(); }
309 void ranged_ctor_std_unordered_set_duplicates_strategy() { non_associative_container_duplicates_strategy<std::unordered_set>(); }
311 void ranged_ctor_std_unordered_multiset_int() { ranged_ctor_non_associative_impl<std::unordered_multiset<int>>(); }
312 void ranged_ctor_std_unordered_multiset_Movable() { ranged_ctor_non_associative_impl<std::unordered_multiset<Movable>>(); }
313 void ranged_ctor_std_unordered_multiset_Complex() { ranged_ctor_non_associative_impl<std::unordered_multiset<Complex>>(); }
314 void ranged_ctor_std_unordered_multiset_duplicates_strategy() { non_associative_container_duplicates_strategy<std::unordered_multiset>(); }
316 void ranged_ctor_QSet_int() { ranged_ctor_non_associative_impl<QSet<int>>(); }
317 void ranged_ctor_QSet_Movable() { ranged_ctor_non_associative_impl<QSet<Movable>>(); }
318 void ranged_ctor_QSet_Complex() { ranged_ctor_non_associative_impl<QSet<Complex>>(); }
319 void ranged_ctor_QSet_duplicates_strategy() { non_associative_container_duplicates_strategy<QSet>(); }
322 void ranged_ctor_std_map_int() { ranged_ctor_associative_impl<std::map<int, int>>(); }
323 void ranged_ctor_std_map_Movable() { ranged_ctor_associative_impl<std::map<Movable, int>>(); }
324 void ranged_ctor_std_map_Complex() { ranged_ctor_associative_impl<std::map<Complex, int>>(); }
326 void ranged_ctor_std_multimap_int() { ranged_ctor_associative_impl<std::multimap<int, int>>(); }
327 void ranged_ctor_std_multimap_Movable() { ranged_ctor_associative_impl<std::multimap<Movable, int>>(); }
328 void ranged_ctor_std_multimap_Complex() { ranged_ctor_associative_impl<std::multimap<Complex, int>>(); }
330 void ranged_ctor_unordered_map_int() { ranged_ctor_associative_impl<std::unordered_map<int, int>>(); }
331 void ranged_ctor_unordered_map_Movable() { ranged_ctor_associative_impl<std::unordered_map<Movable, Movable>>(); }
332 void ranged_ctor_unordered_map_Complex() { ranged_ctor_associative_impl<std::unordered_map<Complex, Complex>>(); }
334 void ranged_ctor_QHash_int() { ranged_ctor_associative_impl<QHash<int, int>>(); }
335 void ranged_ctor_QHash_Movable() { ranged_ctor_associative_impl<QHash<Movable, int>>(); }
336 void ranged_ctor_QHash_Complex() { ranged_ctor_associative_impl<QHash<Complex, int>>(); }
338 void ranged_ctor_unordered_multimap_int() { ranged_ctor_associative_impl<std::unordered_multimap<int, int>>(); }
339 void ranged_ctor_unordered_multimap_Movable() { ranged_ctor_associative_impl<std::unordered_multimap<Movable, Movable>>(); }
340 void ranged_ctor_unordered_multimap_Complex() { ranged_ctor_associative_impl<std::unordered_multimap<Complex, Complex>>(); }
342 void ranged_ctor_QMultiHash_int() { ranged_ctor_associative_impl<QMultiHash<int, int>>(); }
343 void ranged_ctor_QMultiHash_Movable() { ranged_ctor_associative_impl<QMultiHash<Movable, int>>(); }
344 void ranged_ctor_QMultiHash_Complex() { ranged_ctor_associative_impl<QMultiHash<Complex, int>>(); }
347 template <
typename Container>
348 void front_back_impl()
const;
351 void front_back_std_vector() { front_back_impl<std::vector<int>>(); }
352 void front_back_QList() { front_back_impl<QList<qintptr>>(); }
353 void front_back_QVarLengthArray() { front_back_impl<QVarLengthArray<int>>(); }
354 void front_back_QString() { front_back_impl<QString>(); }
355 void front_back_QStringView() { front_back_impl<QStringView>(); }
356 void front_back_QLatin1String() { front_back_impl<QLatin1String>(); }
357 void front_back_QByteArray() { front_back_impl<QByteArray>(); }
360 template <
typename Container>
361 void erase_impl()
const;
363 template <
typename Container>
364 void erase_if_impl()
const;
366 template <
typename Container>
367 void erase_if_associative_impl()
const;
370 void erase_QList() { erase_impl<QList<int>>(); }
371 void erase_QVarLengthArray() { erase_impl<QVarLengthArray<int>>(); }
372 void erase_QString() { erase_impl<QString>(); }
373 void erase_QByteArray() { erase_impl<QByteArray>(); }
374 void erase_std_vector() {
375 #ifdef STDLIB_HAS_UNIFORM_ERASURE
376 erase_impl<std::vector<int>>();
380 void erase_if_QList() { erase_if_impl<QList<int>>(); }
381 void erase_if_QVarLengthArray() { erase_if_impl<QVarLengthArray<int>>(); }
382 void erase_if_QSet() { erase_if_impl<QSet<int>>(); }
383 void erase_if_QString() { erase_if_impl<QString>(); }
384 void erase_if_QByteArray() { erase_if_impl<QByteArray>(); }
385 void erase_if_std_vector() {
386 #ifdef STDLIB_HAS_UNIFORM_ERASURE
387 erase_if_impl<std::vector<int>>();
390 void erase_if_QMap() { erase_if_associative_impl<QMap<int, int>>(); }
391 void erase_if_QMultiMap() {erase_if_associative_impl<QMultiMap<int, int>>(); }
392 void erase_if_QHash() { erase_if_associative_impl<QHash<int, int>>(); }
393 void erase_if_QMultiHash() { erase_if_associative_impl<QMultiHash<int, int>>(); }
396 void tst_ContainerApiSymmetry::init()
402 void tst_ContainerApiSymmetry::cleanup()
409 template <
typename Container>
414 return {
V(0),
V(1),
V(2),
V(0)};
417 template <
typename Container>
418 void tst_ContainerApiSymmetry::ranged_ctor_non_associative_impl()
const
423 const auto reference = createContainerReference<Container>();
426 const V values1[] = {
V(0),
V(1),
V(2),
V(0) };
428 const Container c1(values1, values1 +
sizeof(values1)/
sizeof(values1[0]));
432 l2 <<
V(0) <<
V(1) <<
V(2) <<
V(0);
443 const Container c3a(l3.begin(), l3.end());
446 const std::list<V> l3c = l3;
447 const Container c3b(l3c.begin(), l3c.end());
455 std::stringstream ss;
456 for (
auto &
v : values1)
459 return Container(std::istream_iterator<V>{ss},
460 std::istream_iterator<V>{});
482 template<
typename Container>
485 template<
typename ...
T>
488 template<
typename ...
T>
491 template<
typename ...
T>
494 template<
typename ...
T>
497 template<
typename ...
T>
500 template<
typename ...
T>
504 template<
typename ...
T>
507 template<
typename ...
T>
511 template<
typename ...
T>
514 template<
typename ...
T>
517 template<
typename ...
T>
520 template<
typename Container>
534 template<
typename Container>
537 std::vector<DuplicateStrategyTestType> valuesAlreadySeen;
561 const auto &valueInContainerIterator =
std::find(
c.begin(),
c.end(),
value);
562 QVERIFY(valueInContainerIterator !=
c.end());
568 const auto &valuesAlreadySeenIterator =
std::find(valuesAlreadySeen.cbegin(), valuesAlreadySeen.cend(),
value);
569 const bool valueIsDuplicated = (valuesAlreadySeenIterator != valuesAlreadySeen.cend());
572 QCOMPARE(std::find_if(
c.begin(),
c.end(), reallyEqualCheck) ==
c.end(), valueIsDuplicated);
574 valuesAlreadySeen.push_back(
value);
588 template<
typename Container>
594 template<
typename Container>
600 template<
typename Container>
606 template<
template<
class ...
T>
class Container>
622 template <
typename Container>
623 void tst_ContainerApiSymmetry::ranged_ctor_associative_impl()
const
647 const std::pair<K, V> values1[] = {
648 std::make_pair(K(0),
V(1000)),
649 std::make_pair(K(1),
V(1001)),
650 std::make_pair(K(2),
V(1002)),
651 std::make_pair(K(0),
V(1003))
654 const Container c1(values1, values1 +
sizeof(values1)/
sizeof(values1[0]));
658 l2 << std::make_pair(K(0),
V(1000))
659 << std::make_pair(K(1),
V(1001))
660 << std::make_pair(K(2),
V(1002))
661 << std::make_pair(K(0),
V(1003));
667 std::list<std::pair<K, V>> l3;
668 l3.push_back(std::make_pair(K(0),
V(1000)));
669 l3.push_back(std::make_pair(K(1),
V(1001)));
670 l3.push_back(std::make_pair(K(2),
V(1002)));
671 l3.push_back(std::make_pair(K(0),
V(1003)));
672 const Container c3a(l3.begin(), l3.end());
675 const std::list<std::pair<K, V>> l3c = l3;
676 const Container c3b(l3c.begin(), l3c.end());
689 template <
typename Container>
695 std::generate_n(std::inserter(
c,
c.end()),
size, [
i = 1]()
mutable { return V(i++); });
699 template <
typename Container>
705 for (
int i = 1;
i <=
size; ++
i)
706 c.insert(K(
i),
V(
i));
717 template <
typename T>
T clean(
T &&
t) {
return std::forward<T>(
t); }
720 template <
typename Container>
721 void tst_ContainerApiSymmetry::front_back_impl()
const
724 auto c1 = make<Container>(1);
730 auto c2 = make<Container>(2);
739 template <
typename T>
740 static int toInt(
T i) {
return i; }
741 static int toInt(
QChar ch) {
return ch.unicode(); }
745 template <
typename Container>
746 void tst_ContainerApiSymmetry::erase_impl()
const
748 using S =
typename Container::size_type;
750 auto c = make<Container>(7);
766 template <
typename Container>
767 void tst_ContainerApiSymmetry::erase_if_impl()
const
769 using S =
typename Container::size_type;
771 auto c = make<Container>(7);
774 decltype(
c.size()) oldSize,
count;
805 template <
typename Container>
806 void tst_ContainerApiSymmetry::erase_if_associative_impl()
const
808 using S =
typename Container::size_type;
812 using P = std::pair<const K &, V &>;
814 auto c = makeAssociative<Container>(20);
834 c = makeAssociative<Container>(20);
855 #include "tst_containerapisymmetry.moc"
small capitals from c petite p scientific i
[1]
The QByteArray class provides an array of bytes.
The QChar class provides a 16-bit Unicode character.
operator>>(QDataStream &ds, qfloat16 &f)
operator<<(QDataStream &ds, qfloat16 f)
The QDebug class provides an output stream for debugging information.
Convenience class for custom QDebug operators.
bool operator<(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
template< typename Enum > bool operator!=(Enum lhs, QFlags< Enum > rhs)
template< typename Enum > size_t qHash(QFlags< Enum > flags, size_t seed=0) noexcept
template< typename Enum > bool operator==(Enum lhs, QFlags< Enum > rhs)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
const_iterator cend() const noexcept
const_iterator cbegin() const noexcept
The QObject class is the base class of all Qt objects.
The QString class provides a Unicode character string.
QString left(qsizetype n) const
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QStrin...
constexpr QStringView left(qsizetype n) const noexcept
QHash< int, QWidget * > hash
[35multi]
auto it unsigned count const
typename C::value_type value_type
typename C::const_iterator const_iterator
typename C::key_type key_type
typename C::mapped_type mapped_type
typename C::iterator iterator
int distance(TestIterator &a, TestIterator &b)
qsizetype erase_if(QByteArray &ba, Predicate pred)
qsizetype erase(QByteArray &ba, const T &t)
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputLayerEXT EGLint EGLAttrib value
GLsizei const GLfloat * v
[13]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei count
#define QStringLiteral(str)
#define QTEST_APPLESS_MAIN(TestObject)
#define QVERIFY(statement)
QFuture< QSet< QChar > > set
[10]
friend std::istream & operator>>(std::istream &os, Complex &c)
Complex(int i=0) noexcept
constexpr Complex & operator=(const Complex &o) noexcept
Complex(const Complex &c)
friend std::ostream & operator<<(std::ostream &os, const Complex &c)
DuplicateStrategyTestType(int i=0) noexcept
Movable(const Movable &m)
Movable(int i=0) noexcept
friend std::ostream & operator<<(std::ostream &os, const Movable &m)
friend std::istream & operator>>(std::istream &os, Movable &m)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
constexpr char toLatin1() const noexcept
std::size_t operator()(Complex m) const noexcept
std::size_t operator()(DuplicateStrategyTestType m) const noexcept
std::size_t operator()(Movable m) const noexcept
void non_associative_container_check_duplicates_impl_no_duplicates(const std::initializer_list< DuplicateStrategyTestType > &reference, const Container &c, IterationOnReference ior)
Container makeAssociative(int size)
Container createContainerReference()
QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO(Movable, Q_RELOCATABLE_TYPE)
bool reallyEqual(DuplicateStrategyTestType lhs, DuplicateStrategyTestType rhs) noexcept
void non_associative_container_check_duplicates(const std::initializer_list< DuplicateStrategyTestType > &reference, const Container &c)
void non_associative_container_check_duplicates_impl(const std::initializer_list< DuplicateStrategyTestType > &reference, const Container &c, ContainerAcceptsDuplicateValues)
QDomElement find(const QString &tagName, const QDomElement &e)