Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
q20vector.h
Go to the documentation of this file.
1// Copyright (C) 2023 Ahmad Samir <a.samirh78@gmail.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef Q20VECTOR_H
5#define Q20VECTOR_H
6
7#include <QtCore/qtconfigmacros.h>
8
9#include <algorithm>
10#include <vector>
11#if __has_include(<memory_resource>)
12# include <memory_resource>
13#endif
14
15//
16// W A R N I N G
17// -------------
18//
19// This file is not part of the Qt API. Types and functions defined in this
20// file can reliably be replaced by their std counterparts, once available.
21// You may use these definitions in your own code, but be aware that we
22// will remove them once Qt depends on the C++ version that supports
23// them in namespace std. There will be NO deprecation warning, the
24// definitions will JUST go away.
25//
26// If you can't agree to these terms, don't use these definitions!
27//
28// We mean it.
29//
30
32
33namespace q20 {
34// like std::erase/std::erase_if for std::vector
35#if defined(__cpp_lib_erase_if) && __cpp_lib_erase_if >= 202002L // the one returning size_type
36using std::erase;
37using std::erase_if;
38#else
39
40// Make it more specialized than the compiler's, so that our implementation is preferred over
41// the compiler's (which may be present, but return void instead of the number of erased elements).
42
43template <typename T, typename U>
44constexpr typename std::vector<T, std::allocator<T>>::size_type
45erase(std::vector<T, std::allocator<T>> &c, const U &value)
46{
47 const auto origSize = c.size();
48 auto it = std::remove(c.begin(), c.end(), value);
49 c.erase(it, c.end());
50 return origSize - c.size();
51}
52
53template <typename T, typename Pred>
54constexpr typename std::vector<T, std::allocator<T>>::size_type
55erase_if(std::vector<T, std::allocator<T>> &c, Pred pred)
56{
57 const auto origSize = c.size();
58 auto it = std::remove_if(c.begin(), c.end(), pred);
59 c.erase(it, c.end());
60 return origSize - c.size();
61}
62
63#ifdef __cpp_lib_polymorphic_allocator
64template <typename T, typename U>
65constexpr typename std::vector<T, std::pmr::polymorphic_allocator<T>>::size_type
66erase(std::vector<T, std::pmr::polymorphic_allocator<T>> &c, const U &value)
67{
68 const auto origSize = c.size();
69 auto it = std::remove(c.begin(), c.end(), value);
70 c.erase(it, c.end());
71 return origSize - c.size();
72}
73
74template <typename T, typename Pred>
75constexpr typename std::vector<T, std::pmr::polymorphic_allocator<T>>::size_type
76erase_if(std::vector<T, std::pmr::polymorphic_allocator<T>> &c, Pred pred)
77{
78 const auto origSize = c.size();
79 auto it = std::remove_if(c.begin(), c.end(), pred);
80 c.erase(it, c.end());
81 return origSize - c.size();
82}
83#endif // __cpp_lib_polymorphic_allocator
84
85#endif // __cpp_lib_erase_if
86} // namespace q20
87
89
90#endif /* Q20VECTOR_H */
iterator end()
Definition qset.h:140
QSet< QString >::iterator it
Combined button and popup list for selecting options.
constexpr std::vector< T, std::allocator< T > >::size_type erase(std::vector< T, std::allocator< T > > &c, const U &value)
Definition q20vector.h:45
constexpr std::vector< T, std::allocator< T > >::size_type erase_if(std::vector< T, std::allocator< T > > &c, Pred pred)
Definition q20vector.h:55
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
const GLubyte * c