Library of Assembled Shared Sources
integral_range.h
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
43/** @class lass::stde::integral_range
44 * @brief integral range.
45 * @author Bram de Greve [Bramz]
46 */
47
48#ifndef LASS_GUARDIAN_OF_INCLUSION_STDE_INTEGRAL_RANGE_H
49#define LASS_GUARDIAN_OF_INCLUSION_STDE_INTEGRAL_RANGE_H
50
51#include "stde_common.h"
52#include "../util/type_traits.h"
53
54namespace lass
55{
56namespace stde
57{
58
59template <typename integral_type> class const_integral_iterator;
60
61template <typename I> bool operator==(const const_integral_iterator<I>& a, const const_integral_iterator<I>& b);
62template <typename I> bool operator!=(const const_integral_iterator<I>& a, const const_integral_iterator<I>& b);
63template <typename I> bool operator< (const const_integral_iterator<I>& a, const const_integral_iterator<I>& b);
64template <typename I> bool operator> (const const_integral_iterator<I>& a, const const_integral_iterator<I>& b);
65template <typename I> bool operator<=(const const_integral_iterator<I>& a, const const_integral_iterator<I>& b);
66template <typename I> bool operator>=(const const_integral_iterator<I>& a, const const_integral_iterator<I>& b);
67
68template <typename integral_type>
69class const_integral_iterator:
70{
71public:
72 typedef const_integral_iterator<integral_type> self_type;
73 typedef std::random_access_iterator_tag iterator_category;
74 typedef integral_type value_type;
75 typedef std::ptrdiff_t difference_type;
76 typedef const integral_type* pointer;
77 typedef const integral_type& reference;
78
79 const_integral_iterator(value_type value, value_type step);
80
81 pointer operator->() const;
82 reference operator*() const;
83 value_type operator[](difference_type n) const;
84
85 self_type& operator++();
86 self_type operator++(int);
87 self_type& operator--();
88 self_type operator--(int);
89
90 self_type& operator+=(difference_type n);
91 self_type& operator-=(difference_type n);
92 self_type operator+(difference_type n) const;
93 self_type operator-(difference_type n) const;
94
95 difference_type operator-(const self_type& other) const;
96
97private:
98
99 friend bool operator== <integral_type>(const const_integral_iterator<integral_type>&, const const_integral_iterator<integral_type>& );
100 friend bool operator< <integral_type>(const const_integral_iterator<integral_type>&, const const_integral_iterator<integral_type>& );
101
102 integral_type value_;
103 integral_type step_;
104};
105
106
107
108template <typename integral_type> class integral_range_t;
109
110template <typename I> bool operator==(const integral_range_t<I>& a, const integral_range_t<I>& b);
111template <typename I> bool operator!=(const integral_range_t<I>& a, const integral_range_t<I>& b);
112template <typename I> bool operator< (const integral_range_t<I>& a, const integral_range_t<I>& b);
113template <typename I> bool operator> (const integral_range_t<I>& a, const integral_range_t<I>& b);
114template <typename I> bool operator<=(const integral_range_t<I>& a, const integral_range_t<I>& b);
115template <typename I> bool operator>=(const integral_range_t<I>& a, const integral_range_t<I>& b);
116
117template <typename integral_type>
118class integral_range_t
119{
120public:
121
122 typedef integral_range_t<integral_type> self_type;
123
124 typedef const_integral_iterator<integral_type> const_iterator;
125 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
126
127 typedef typename const_iterator::value_type value_type;
128 typedef typename const_iterator::pointer const_pointer;
129 typedef typename const_iterator::reference const_reference;
130 typedef typename const_iterator::difference_type difference_type;
131 typedef std::size_t size_type;
132
133 integral_range_t();
134 integral_range_t(value_type last);
135 integral_range_t(value_type first, value_type last);
136 integral_range_t(value_type first, value_type last, value_type step);
137
138 const_iterator begin() const;
139 const_iterator end() const;
140 const_reverse_iterator rbegin() const;
141 const_reverse_iterator rend() const;
142
143 const_pointer operator->() const;
144 const_reference operator*() const;
145 value_type operator[](difference_type index) const;
146
147 self_type& operator++();
148 self_type operator++(int);
149 self_type& operator--();
150 self_type operator--(int);
151
152 self_type& operator+=(difference_type n);
153 self_type& operator-=(difference_type n);
154 self_type operator+(difference_type n) const;
155 self_type operator-(difference_type n) const;
156
157 const size_type size() const;
158 const bool empty() const;
159 const bool operator!() const;
160 explicit operator bool() const;
161
162 void swap(self_type& other);
163
164private:
165
166 friend bool operator== <integral_type>(const integral_range_t<integral_type>& a, const integral_range_t<integral_type>& b);
167 friend bool operator< <integral_type>(const integral_range_t<integral_type>& a, const integral_range_t<integral_type>& b);
168
169 integral_type first_;
170 integral_type last_;
171 integral_type step_;
172};
173
174template <typename I> integral_range_t<I> integral_range(const I& last);
175template <typename I> integral_range_t<I> integral_range(const I& first, const I& last);
176template <typename I> integral_range_t<I> integral_range(const I& first, const I& last, const I& step);
177
178}
179
180}
181
182#include "integral_range.inl"
183
184#endif
185
186// EOF
integral range.
Library for Assembled Shared Sources.
Definition config.h:53