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