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)
7 // 04 Jan 2001 Factored counting_iterator stuff into
8 // boost/counting_iterator.hpp (David Abrahams)
10 #ifndef BOOST_INTEGER_RANGE_HPP_
11 #define BOOST_INTEGER_RANGE_HPP_
13 #include <boost/config.hpp>
14 #include <boost/iterator/counting_iterator.hpp>
19 //=============================================================================
20 // Counting Iterator and Integer Range Class
22 template <class IntegerType
>
23 struct integer_range
{
24 typedef counting_iterator
<IntegerType
> iterator
;
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
;
35 integer_range(IntegerType start
, IntegerType finish
)
36 : m_start(start
), m_finish(finish
) { }
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
);
47 IntegerType m_start
, m_finish
;
50 template <class IntegerType
>
51 inline integer_range
<IntegerType
>
52 make_integer_range(IntegerType first
, IntegerType last
)
54 return integer_range
<IntegerType
>(first
, last
);
59 #endif // BOOST_INTEGER_RANGE_HPP_