Library of Assembled Shared Sources
iterator_range.inl
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43namespace lass
44{
45namespace stde
46{
47
48// --- public --------------------------------------------------------------------------------------
49
50template <typename I> inline
51iterator_range<I>::iterator_range(iterator first, iterator last):
52 first_(first),
53 last_(last)
54{
55}
56
57
58
59template <typename I> inline
60typename iterator_range<I>::iterator
61iterator_range<I>::begin() const
62{
63 return first_;
64}
65
66
67
68template <typename I> inline
69typename iterator_range<I>::iterator
70iterator_range<I>::end() const
71{
72 return last_;
73}
74
75
76
77template <typename I> inline
78typename iterator_range<I>::iterator
79iterator_range<I>::operator->() const
80{
81 LASS_ASSERT(!this->empty());
82 return first_;
83}
84
85
86
87template <typename I> inline
88typename iterator_range<I>::reference
89iterator_range<I>::operator*() const
90{
91 LASS_ASSERT(!this->empty());
92 return *first_;
93}
94
95
96
97template <typename I> inline
98typename iterator_range<I>::reference
99iterator_range<I>::operator[](difference_type index) const
100{
101 LASS_ASSERT(index < this->size());
102 iterator result = first_;
103 std::advance(result, index);
104 return *result;
105}
106
107
108
109template <typename I> inline
110iterator_range<I>&
111iterator_range<I>::operator++()
112{
113 LASS_ASSERT(first_ != last_);
114 ++first_;
115 return *this;
116}
117
118
119
120template <typename I> inline
121iterator_range<I>
122iterator_range<I>::operator++(int)
123{
124 iterator_range<I> result(*this);
125 this->operator++();
126 return result;
127}
128
129
130
131template <typename I> inline
132const typename iterator_range<I>::difference_type
133iterator_range<I>::size() const
134{
135 return std::distance(first_, last_);
136}
137
138
139
140template <typename I> inline
141bool iterator_range<I>::empty() const
142{
143 return first_ == last_;
144}
145
146
147
148template <typename I> inline
149bool iterator_range<I>::operator!() const
150{
151 return this->empty();
152}
153
154
155
156template <typename I> inline
157iterator_range<I>::operator bool() const
158{
159 return !this->empty();
160}
161
162
163
164template <typename I> inline
165void iterator_range<I>::swap(iterator_range<I>& other)
166{
167 std::swap(first_, other.first_);
168 std::swap(last_, other.last_);
169}
170
171
172
173// --- protected -----------------------------------------------------------------------------------
174
175
176
177// --- private -------------------------------------------------------------------------------------
178
179
180
181// --- free functions ------------------------------------------------------------------------------
182
183template <typename I> inline
184iterator_range<I> range(const I& a, const I& b)
185{
186 return iterator_range<I>(a, b);
187}
188
189
190
191template <typename T, size_t n> inline
192iterator_range<T*> range(T (&a)[n])
193{
194 return iterator_range<T*>(a, a + n);
195}
196
197
198
199template <typename I> inline
200bool operator==(const iterator_range<I>& a, const iterator_range<I>& b)
201{
202 return a.begin() == b.begin() && a.end() == b.end();
203}
204
205
206
207template <typename I> inline
208bool operator!=(const iterator_range<I>& a, const iterator_range<I>& b)
209{
210 return !(a == b);
211}
212
213
214
215}
216
217}
218
219// EOF
lass extensions to the standard library
Library for Assembled Shared Sources.
Definition config.h:53