Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Concepts
set.hpp
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include <set>
27
28#include <ext/ostream>
29
30#include <extensions/range.hpp>
31
32namespace ext {
33
43template < typename T, typename Cmp = std::less < >, typename Alloc = std::allocator < T > >
44class set : public std::set < T, Cmp, Alloc > {
45public:
49 using std::set < T, Cmp, Alloc >::set; // NOLINT(modernize-use-equals-default)
50
54 using std::set < T, Cmp, Alloc >::operator =;
55#ifndef __clang__
56
60 set ( ) = default;
61
65 set ( const set & other ) = default;
66
70 set ( set && other ) = default;
71
75 set & operator = ( set && other ) = default;
76
80 set & operator = ( const set & other ) = default;
81#endif
89 template < class Iterator >
90 explicit set ( const ext::iterator_range < Iterator > & range ) : set ( range.begin ( ), range.end ( ) ) {
91 }
92
99 auto begin ( ) & {
101 }
102
109 auto begin ( ) const & {
111 }
112
119 auto begin ( ) && {
120 return make_set_move_iterator ( this->begin ( ) );
121 }
122
129 auto end ( ) & {
131 }
132
139 auto end ( ) const & {
141 }
142
149 auto end ( ) && {
150 return make_set_move_iterator ( this->end ( ) );
151 }
152
159 auto range ( ) & {
160 auto endIter = end ( );
161 auto beginIter = begin ( );
162 return ext::iterator_range < decltype ( endIter ) > ( beginIter, endIter );
163 }
164
171 auto range ( ) const & {
172 auto endIter = end ( );
173 auto beginIter = begin ( );
174 return ext::iterator_range < decltype ( endIter ) > ( beginIter, endIter );
175 }
176
183 auto range ( ) && {
184 auto endIter = std::move ( * this ).end ( );
185 auto beginIter = std::move ( * this ).begin ( );
186 return ext::iterator_range < decltype ( endIter ) > ( beginIter, endIter );
187 }
188
199 template < class K >
200 auto equal_range ( K && key ) const & {
201 auto res = std::set < T, Cmp, Alloc >::equal_range ( std::forward < K > ( key ) );
202 return ext::iterator_range < decltype ( res.first ) > ( res.first, res.second );
203 }
204
215 template < class K >
216 auto equal_range ( K && key ) & {
217 auto res = std::set < T, Cmp, Alloc >::equal_range ( std::forward < K > ( key ) );
218 return ext::iterator_range < decltype ( res.first ) > ( res.first, res.second );
219 }
220
231 template < class K >
232 auto equal_range ( K && key ) && {
233 auto res = std::set < T, Cmp, Alloc >::equal_range ( std::forward < K > ( key ) );
234 return ext::make_iterator_range ( make_set_move_iterator < T > ( res.first ), make_set_move_iterator < T > ( res.second ) );
235 }
236
237};
238
252template< class T, class ... Ts >
254 out << "{";
255
256 bool first = true;
257 for(const T& item : list) {
258 if(!first) out << ", ";
259 first = false;
260 out << item;
261 }
262
263 out << "}";
264 return out;
265}
266
278template < class T >
280 ext::set < T > res ( first );
281
282 res.insert ( second.begin ( ), second.end ( ) );
283 return res;
284}
285
286} /* namespace ext */
Implementation of iterator_range, i.e. pair of iterators. The class provides most notably begin and e...
Definition: range.hpp:24
Class extending the list class from the standard library. Original reason is to allow printing of the...
Definition: list.hpp:44
Definition: ostream.h:14
Definition: set.hpp:44
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: set.hpp:99
auto end() &
Inherited behavior of end for non-const instance.
Definition: set.hpp:129
set(const ext::iterator_range< Iterator > &range)
Definition: set.hpp:90
auto equal_range(K &&key) const &
Make range of elements with key equal to the key.
Definition: set.hpp:200
auto end() const &
Inherited behavior of end for const instance.
Definition: set.hpp:139
auto begin() &&
New variant of begin for rvalues.
Definition: set.hpp:119
auto begin() const &
Inherited behavior of begin for const instance.
Definition: set.hpp:109
auto range() const &
Make range of non-const begin to end iterators.
Definition: set.hpp:171
auto end() &&
New variant of end for rvalues.
Definition: set.hpp:149
auto equal_range(K &&key) &&
Make range of elements with key equal to the key.
Definition: set.hpp:232
auto range() &
Make range of non-const begin to end iterators.
Definition: set.hpp:159
set & operator=(set &&other)=default
set(const set &other)=default
auto equal_range(K &&key) &
Make range of elements with key equal to the key.
Definition: set.hpp:216
auto range() &&
Make range of move begin to end iterators.
Definition: set.hpp:183
set()=default
set(set &&other)=default
p second
Definition: ToRegExpAlgebraic.h:126
return res
Definition: MinimizeByPartitioning.h:145
Definition: sigHandler.cpp:20
ext::multiset< T > operator+(const ext::multiset< T > &first, const ext::multiset< T > &second)
Implementation of union of two multisets.
Definition: multiset.hpp:279
set_move_iterator< Iterator > make_set_move_iterator(Iterator it)
Move from set iterator adaptor construction function.
Definition: iterator.hpp:200
iterator_range< Iter > make_iterator_range(Iter begin, Iter end)
Helper to create iterator_range from two iterators.
Definition: range.hpp:235
std::ostream & operator<<(ext::reference_wrapper< std::ostream > &os, std::ostream &(*const func)(std::ostream &))
Overloaded function allowing same operations on wrapped output stream as on the actual output stream,...
Definition: GlobalData.cpp:33
auto begin(Container &&cont) -> decltype(std::forward(cont).begin())
Definition: iterator.hpp:900
void end()
Definition: measurements.cpp:19