1 | // (C) Copyright David Abrahams and Jeremy Siek 2000-2001. |
---|
2 | // Distributed under the Boost Software License, Version 1.0. (See |
---|
3 | // accompanying file LICENSE_1_0.txt or copy at |
---|
4 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
5 | // |
---|
6 | // Revision History: |
---|
7 | // 04 Jan 2001 Factored counting_iterator stuff into |
---|
8 | // boost/counting_iterator.hpp (David Abrahams) |
---|
9 | |
---|
10 | #ifndef BOOST_INTEGER_RANGE_HPP_ |
---|
11 | #define BOOST_INTEGER_RANGE_HPP_ |
---|
12 | |
---|
13 | #include <boost/config.hpp> |
---|
14 | #include <boost/iterator/counting_iterator.hpp> |
---|
15 | #include <algorithm> |
---|
16 | |
---|
17 | namespace boost { |
---|
18 | |
---|
19 | //============================================================================= |
---|
20 | // Counting Iterator and Integer Range Class |
---|
21 | |
---|
22 | template <class IntegerType> |
---|
23 | struct integer_range { |
---|
24 | typedef counting_iterator<IntegerType> iterator; |
---|
25 | |
---|
26 | typedef iterator const_iterator; |
---|
27 | typedef IntegerType value_type; |
---|
28 | typedef std::ptrdiff_t difference_type; |
---|
29 | typedef IntegerType reference; |
---|
30 | typedef IntegerType const_reference; |
---|
31 | typedef const IntegerType* pointer; |
---|
32 | typedef const IntegerType* const_pointer; |
---|
33 | typedef IntegerType size_type; |
---|
34 | |
---|
35 | integer_range(IntegerType start, IntegerType finish) |
---|
36 | : m_start(start), m_finish(finish) { } |
---|
37 | |
---|
38 | iterator begin() const { return iterator(m_start); } |
---|
39 | iterator end() const { return iterator(m_finish); } |
---|
40 | size_type size() const { return m_finish - m_start; } |
---|
41 | bool empty() const { return m_finish == m_start; } |
---|
42 | void swap(integer_range& x) { |
---|
43 | std::swap(m_start, x.m_start); |
---|
44 | std::swap(m_finish, x.m_finish); |
---|
45 | } |
---|
46 | protected: |
---|
47 | IntegerType m_start, m_finish; |
---|
48 | }; |
---|
49 | |
---|
50 | template <class IntegerType> |
---|
51 | inline integer_range<IntegerType> |
---|
52 | make_integer_range(IntegerType first, IntegerType last) |
---|
53 | { |
---|
54 | return integer_range<IntegerType>(first, last); |
---|
55 | } |
---|
56 | |
---|
57 | } // namespace boost |
---|
58 | |
---|
59 | #endif // BOOST_INTEGER_RANGE_HPP_ |
---|