AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
ASet.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include <set>
15#include <ostream>
16#include <AUI/Traits/containers.h>
17
18
23template <class KeyType, class Comparator = std::less<KeyType>, class Allocator = std::allocator<KeyType>>
24class ASet: public std::set<KeyType, Comparator, Allocator>
25{
26private:
27 using p = std::set<KeyType, Comparator, Allocator>;
29
30public:
31
32 using p::p;
33 using iterator = typename p::iterator;
34
35
42 template<typename OtherContainer>
43 void insertAll(const OtherContainer& c) noexcept {
44 p::insert(c.begin(), c.end());
45 }
46
50 template<typename OtherContainer>
51 bool isSubsetOf(const OtherContainer& c) const noexcept
52 {
53 return aui::container::is_subset(*this, c);
54 }
55
61 inline self& operator<<(const KeyType& rhs) noexcept
62 {
63 p::insert(rhs);
64 return *this;
65 }
66
72 inline self& operator<<(KeyType&& rhs) noexcept
73 {
74 p::insert(std::move(rhs));
75 return *this;
76 }
82 inline self& operator>>(const KeyType& rhs) noexcept
83 {
84 p::erase(rhs);
85 return *this;
86 }
87
93 template<typename OtherContainer, std::enable_if_t<!std::is_convertible_v<OtherContainer, KeyType>, bool> = true>
94 inline self& operator<<(const OtherContainer& c) noexcept
95 {
96 insertAll(c);
97 return *this;
98 }
99
100
101 bool contains(const KeyType& value) const noexcept
102 {
103 return p::find(value) != p::end();
104 }
105};
106
107
108template<typename T>
109inline std::ostream& operator<<(std::ostream& o, const ASet<T>& v) {
110 if (v.empty()) {
111 o << "[empty]";
112 } else {
113 auto it = v.begin();
114 o << "[ " << *it;
115 ++it;
116 for (; it != v.end(); ++it) {
117 o << ", " << *it;
118 }
119 o << " ]";
120 }
121
122 return o;
123}
124
A std::set with AUI extensions.
Definition: ASet.h:25
self & operator<<(const KeyType &rhs) noexcept
Definition: ASet.h:61
bool isSubsetOf(const OtherContainer &c) const noexcept
Definition: ASet.h:51
self & operator<<(const OtherContainer &c) noexcept
Definition: ASet.h:94
self & operator>>(const KeyType &rhs) noexcept
Definition: ASet.h:82
self & operator<<(KeyType &&rhs) noexcept
Definition: ASet.h:72
void insertAll(const OtherContainer &c) noexcept
Definition: ASet.h:43
bool is_subset(LContainer &l, RContainer &r) noexcept
Definition: containers.h:233