Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
list.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 <list>
27
28#include <ext/ostream>
29
30#include <extensions/range.hpp>
31
32namespace ext {
33
43template < class T, class Alloc = std::allocator < T > >
44class list : public std::list < T, Alloc > {
45public:
49 using std::list < T, Alloc >::list; // NOLINT(modernize-use-equals-default)
50
54 using std::list < T, Alloc >::operator =;
55#ifndef __clang__
56
60 list ( ) = default;
61
65 list ( const list & other ) = default;
66
70 list ( list && other ) = default;
71
75 list & operator = ( list && other ) = default;
76
80 list & operator = ( const list & other ) = default;
81#endif
82
90 template < class Iterator >
91 explicit list ( const ext::iterator_range < Iterator > & range ) : list ( 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 for(const T& item : list) {
209 if(!first) out << ", ";
210 first = false;
211 out << item;
212 }
213
214 out << "]";
215 return out;
216}
217
218} /* 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
list & operator=(list &&other)=default
auto range() &
Make range of non-const begin to end iterators.
Definition: list.hpp:160
auto begin() &&
Inherited behavior of begin for rvalues.
Definition: list.hpp:120
auto end() &&
Inherited behavior of end for rvalues.
Definition: list.hpp:150
auto end() const &
Inherited behavior of end for const instance.
Definition: list.hpp:140
list(const list &other)=default
list(list &&other)=default
list()=default
list(const ext::iterator_range< Iterator > &range)
Definition: list.hpp:91
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: list.hpp:100
auto range() const &
Make range of non-const begin to end iterators.
Definition: list.hpp:172
auto range() &&
Make range of move begin to end iterators.
Definition: list.hpp:184
auto end() &
Inherited behavior of end for non-const instance.
Definition: list.hpp:130
auto begin() const &
Inherited behavior of begin for const instance.
Definition: list.hpp:110
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