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