Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
deque.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 <deque>
27
28#include <ext/ostream>
29
30#include <extensions/range.hpp>
31
32namespace ext {
33
43template < class T, class Alloc = std::allocator < T > >
44class deque : public std::deque < T, Alloc > {
45public:
49 using std::deque < T, Alloc >::deque; // NOLINT(modernize-use-equals-default)
50
54 using std::deque < T, Alloc >::operator =;
55#ifndef __clang__
56
60 deque ( ) = default;
61
65 deque ( const deque & other ) = default;
66
70 deque ( deque && other ) = default;
71
75 deque & operator = ( deque && other ) = default;
76
80 deque & operator = ( const deque & other ) = default;
81#endif
82
90 template < class Iterator >
91 explicit deque ( const ext::iterator_range < Iterator > & range ) : deque ( range.begin ( ), range.end ( ) ) {
92 }
93
100 auto begin ( ) & {
102 }
103
110 auto begin ( ) const & {
112 }
113
120 auto begin ( ) && {
121 return make_move_iterator ( this->begin ( ) );
122 }
123
130 auto end ( ) & {
132 }
133
140 auto end ( ) const & {
142 }
143
150 auto end ( ) && {
151 return make_move_iterator ( this->end ( ) );
152 }
153
160 auto range ( ) & {
161 auto endIter = end ( );
162 auto beginIter = begin ( );
163 return ext::iterator_range < decltype ( endIter ) > ( beginIter, endIter );
164 }
165
172 auto range ( ) const & {
173 auto endIter = end ( );
174 auto beginIter = begin ( );
175 return ext::iterator_range < decltype ( endIter ) > ( beginIter, endIter );
176 }
177
184 auto range ( ) && {
185 auto endIter = std::move ( * this ).end ( );
186 auto beginIter = std::move ( * this ).begin ( );
187 return ext::iterator_range < decltype ( endIter ) > ( beginIter, endIter );
188 }
189};
190
203template < class T, class ... Ts >
205 out << "[";
206
207 bool first = true;
208
209 for ( const T & item : list ) {
210 if ( !first ) out << ", ";
211
212 first = false;
213 out << item;
214 }
215
216 out << "]";
217 return out;
218}
219
220} /* namespace ext */
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
auto range() &
Make range of non-const begin to end iterators.
Definition: deque.hpp:160
deque(const deque &other)=default
deque & operator=(deque &&other)=default
auto range() &&
Make range of move begin to end iterators.
Definition: deque.hpp:184
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: deque.hpp:100
auto begin() &&
Inherited behavior of begin for rvalues.
Definition: deque.hpp:120
auto begin() const &
Inherited behavior of begin for const instance.
Definition: deque.hpp:110
deque(const ext::iterator_range< Iterator > &range)
Definition: deque.hpp:91
auto end() &&
Inherited behavior of end for rvalues.
Definition: deque.hpp:150
auto end() &
Inherited behavior of end for non-const instance.
Definition: deque.hpp:130
auto end() const &
Inherited behavior of end for const instance.
Definition: deque.hpp:140
deque()=default
deque(deque &&other)=default
auto range() const &
Make range of non-const begin to end iterators.
Definition: deque.hpp:172
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: sigHandler.cpp:20
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