Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#ifndef Q20VECTOR_H
6#define Q20VECTOR_H
7
8#include <QtCore/qtconfigmacros.h>
9
10#include <algorithm>
11#include <vector>
12#if __has_include(<memory_resource>)
13# include <memory_resource>
14#endif
15
16//
17// W A R N I N G
18// -------------
19//
20// This file is not part of the Qt API. Types and functions defined in this
21// file can reliably be replaced by their std counterparts, once available.
22// You may use these definitions in your own code, but be aware that we
23// will remove them once Qt depends on the C++ version that supports
24// them in namespace std. There will be NO deprecation warning, the
25// definitions will JUST go away.
26//
27// If you can't agree to these terms, don't use these definitions!
28//
29// We mean it.
30//
31
32QT_BEGIN_NAMESPACE
33
34namespace q20 {
35// like std::erase/std::erase_if for std::vector
36#if defined(__cpp_lib_erase_if) && __cpp_lib_erase_if >= 202002L // the one returning size_type
37using std::erase;
38using std::erase_if;
39#else
40
41// Make it more specialized than the compiler's, so that our implementation is preferred over
42// the compiler's (which may be present, but return void instead of the number of erased elements).
43
44template <typename T, typename U>
45constexpr typename std::vector<T, std::allocator<T>>::size_type
46erase(std::vector<T, std::allocator<T>> &c, const U &value)
47{
48 const auto origSize = c.size();
49 auto it = std::remove(c.begin(), c.end(), value);
50 c.erase(it, c.end());
51 return origSize - c.size();
52}
53
54template <typename T, typename Pred>
55constexpr typename std::vector<T, std::allocator<T>>::size_type
56erase_if(std::vector<T, std::allocator<T>> &c, Pred pred)
57{
58 const auto origSize = c.size();
59 auto it = std::remove_if(c.begin(), c.end(), pred);
60 c.erase(it, c.end());
61 return origSize - c.size();
62}
63
64#ifdef __cpp_lib_polymorphic_allocator
65template <typename T, typename U>
66constexpr typename std::vector<T, std::pmr::polymorphic_allocator<T>>::size_type
68{
69 const auto origSize = c.size();
70 auto it = std::remove(c.begin(), c.end(), value);
71 c.erase(it, c.end());
72 return origSize - c.size();
73}
74
75template <typename T, typename Pred>
76constexpr typename std::vector<T, std::pmr::polymorphic_allocator<T>>::size_type
78{
79 const auto origSize = c.size();
80 auto it = std::remove_if(c.begin(), c.end(), pred);
81 c.erase(it, c.end());
82 return origSize - c.size();
83}
84#endif // __cpp_lib_polymorphic_allocator
85
86#endif // __cpp_lib_erase_if
87} // namespace q20
88
89QT_END_NAMESPACE
90
91#endif /* Q20VECTOR_H */
void unregisterObserver(const SharedObjectRemoveObserver &)
std::optional< ObjectSerial > findSourceNodeSerial(std::string_view nodeName) const
DeviceLists getDeviceLists(bool verifyThreading=true)
std::optional< ObjectId > findObjectId(ObjectSerial)
std::optional< ObjectSerial > findSinkNodeSerial(std::string_view nodeName) const
void objectAdded(ObjectId, uint32_t permissions, PipewireRegistryType, uint32_t version, const spa_dict &props)
std::optional< ObjectSerial > findObjectSerial(ObjectId)
bool registerObserver(SharedObjectRemoveObserver)
Combined button and popup list for selecting options.
Q_STATIC_LOGGING_CATEGORY(lcPipewireRegistry, "qt.multimedia.pipewire.registry")
StrongIdType< uint32_t, ObjectIdTag > ObjectId
StrongIdType< uint64_t, ObjectSerialTag > ObjectSerial
std::shared_ptr< ObjectRemoveObserver > SharedObjectRemoveObserver
constexpr std::vector< T, std::allocator< T > >::size_type erase(std::vector< T, std::allocator< T > > &c, const U &value)
Definition q20vector.h:46
constexpr std::vector< T, std::allocator< T > >::size_type erase_if(std::vector< T, std::allocator< T > > &c, Pred pred)
Definition q20vector.h:56
#define __has_include(x)