Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
forward_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 <forward_list>
27#include <ostream>
28
29#include <extensions/range.hpp>
30
31namespace ext {
32
42template < class T, class Alloc = std::allocator < T > >
43class forward_list : public std::forward_list < T, Alloc >, AllocFix < Alloc > {
44public:
48 using std::forward_list < T, Alloc >::forward_list; // NOLINT(modernize-use-equals-default)
49
53 using std::forward_list < T, Alloc >::operator =;
54#ifndef __clang__
55
59 forward_list ( ) = default;
60
64 forward_list ( const forward_list & other ) = default;
65
69 forward_list ( forward_list && other ) = default;
70
74 forward_list & operator = ( forward_list && other ) = default;
75
79 forward_list & operator = ( const forward_list & other ) = default;
80#endif
81
89 template < class Iterator >
91 }
92
99 auto begin ( ) & {
101 }
102
109 auto begin ( ) const & {
111 }
112
119 auto begin ( ) && {
120 return make_move_iterator ( this->begin ( ) );
121 }
122
129 auto end ( ) & {
131 }
132
139 auto end ( ) const & {
141 }
142
149 auto end ( ) && {
150 return make_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};
189
202template< class T, class ... Ts >
203std::ostream& operator<<(std::ostream& out, const ext::forward_list<T, Ts ... >& forward_list) {
204 out << "[";
205
206 bool first = true;
207 for(const T& item : forward_list) {
208 if(!first) out << ", ";
209 first = false;
210 out << item;
211 }
212
213 out << "]";
214 return out;
215}
216
217} /* namespace ext */
Class extending the forward_list class from the standard library. Original reason is to allow printin...
Definition: forward_list.hpp:43
forward_list()=default
auto range() &
Make range of non-const begin to end iterators.
Definition: forward_list.hpp:159
auto range() const &
Make range of non-const begin to end iterators.
Definition: forward_list.hpp:171
forward_list(const ext::iterator_range< Iterator > &range)
Definition: forward_list.hpp:90
auto begin() &&
Inherited behavior of begin for rvalues.
Definition: forward_list.hpp:119
forward_list(forward_list &&other)=default
auto end() const &
Inherited behavior of end for const instance.
Definition: forward_list.hpp:139
auto end() &
Inherited behavior of end for non-const instance.
Definition: forward_list.hpp:129
auto end() &&
Inherited behavior of end for rvalues.
Definition: forward_list.hpp:149
auto range() &&
Make range of move begin to end iterators.
Definition: forward_list.hpp:183
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: forward_list.hpp:99
forward_list(const forward_list &other)=default
forward_list & operator=(forward_list &&other)=default
auto begin() const &
Inherited behavior of begin for const instance.
Definition: forward_list.hpp:109
Implementation of iterator_range, i.e. pair of iterators. The class provides most notably begin and e...
Definition: range.hpp:24
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