mirror of
https://github.com/boostorg/iterator.git
synced 2025-06-26 12:31:41 +02:00
Compare commits
32 Commits
boost-1.24
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
abffbb8300 | |||
34c159dd8d | |||
b22a3adc02 | |||
4a24e0f401 | |||
3844edc4bf | |||
fdd1601ba4 | |||
e9b33b336c | |||
2574365b5c | |||
12b9366f33 | |||
4772bb099e | |||
2be5179020 | |||
8cb49713b4 | |||
bd666dc0e9 | |||
57251d58cc | |||
ebcb4d861a | |||
15a7a839f9 | |||
76a307d31e | |||
37aee7c13b | |||
50a502bb81 | |||
8a4839354e | |||
4da7371246 | |||
e162a75e53 | |||
e60df6ad92 | |||
4c2b3a9d2c | |||
75023a1dd3 | |||
79370a6dfb | |||
4566798afc | |||
3fd1c4bc5d | |||
2d6f48d5ab | |||
d1c7594344 | |||
ac327f51e9 | |||
4e18b11263 |
@ -56,9 +56,7 @@
|
||||
# include <boost/type_traits.hpp>
|
||||
# include <boost/detail/numeric_traits.hpp>
|
||||
# include <boost/static_assert.hpp>
|
||||
# ifndef BOOST_NO_LIMITS
|
||||
# include <limits>
|
||||
# endif
|
||||
# include <boost/limits.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
@ -135,7 +133,15 @@ namespace detail {
|
||||
// For a while, this wasn't true, but we rely on it below. This is a regression assert.
|
||||
BOOST_STATIC_ASSERT(::boost::is_integral<char>::value);
|
||||
# ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||
BOOST_STATIC_CONSTANT(bool, value = std::numeric_limits<T>::is_specialized);
|
||||
# if defined(BOOST_HAS_LONG_LONG)
|
||||
BOOST_STATIC_CONSTANT(bool,
|
||||
value = (
|
||||
std::numeric_limits<T>::is_specialized
|
||||
| boost::is_same<T,long long>::value
|
||||
| boost::is_same<T,unsigned long long>::value));
|
||||
# else
|
||||
BOOST_STATIC_CONSTANT(bool, value = std::numeric_limits<T>::is_specialized);
|
||||
# endif
|
||||
# else
|
||||
# if !defined(__BORLANDC__)
|
||||
BOOST_STATIC_CONSTANT(bool, value = (
|
||||
@ -173,14 +179,17 @@ struct counting_iterator_traits {
|
||||
template <class Incrementable>
|
||||
struct counting_iterator_policies : public default_iterator_policies
|
||||
{
|
||||
const Incrementable& dereference(type<const Incrementable&>, const Incrementable& i) const
|
||||
{ return i; }
|
||||
|
||||
template <class Difference, class Iterator1, class Iterator2>
|
||||
Difference distance(type<Difference>, const Iterator1& x,
|
||||
const Iterator2& y) const
|
||||
template <class IteratorAdaptor>
|
||||
typename IteratorAdaptor::reference dereference(const IteratorAdaptor& i) const
|
||||
{ return i.base(); }
|
||||
|
||||
template <class Iterator1, class Iterator2>
|
||||
typename Iterator1::difference_type distance(
|
||||
const Iterator1& x, const Iterator2& y) const
|
||||
{
|
||||
return boost::detail::any_distance<Difference>(x, y);//,(Difference*)());
|
||||
typedef typename Iterator1::difference_type difference_type;
|
||||
return boost::detail::any_distance<difference_type>(
|
||||
x.base(), y.base());
|
||||
}
|
||||
};
|
||||
|
||||
@ -188,15 +197,20 @@ struct counting_iterator_policies : public default_iterator_policies
|
||||
template <class Incrementable>
|
||||
struct counting_iterator_generator
|
||||
{
|
||||
typedef counting_iterator_traits<Incrementable> traits;
|
||||
typedef typename boost::remove_const<
|
||||
Incrementable
|
||||
>::type value_type;
|
||||
|
||||
typedef iterator_adaptor<Incrementable,
|
||||
counting_iterator_policies<Incrementable>,
|
||||
Incrementable,
|
||||
const Incrementable&,
|
||||
const Incrementable*,
|
||||
typename traits::iterator_category,
|
||||
typename traits::difference_type
|
||||
typedef counting_iterator_traits<value_type> traits;
|
||||
|
||||
typedef iterator_adaptor<
|
||||
value_type
|
||||
, counting_iterator_policies<value_type>
|
||||
, value_type
|
||||
, value_type const&
|
||||
, value_type const*
|
||||
, typename traits::iterator_category
|
||||
, typename traits::difference_type
|
||||
> type;
|
||||
};
|
||||
|
||||
|
@ -99,17 +99,17 @@ struct half_open_range
|
||||
|
||||
public:
|
||||
typedef iter_t const_iterator;
|
||||
typedef typename counting_iterator_traits<Incrementable>::value_type value_type;
|
||||
typedef typename counting_iterator_traits<Incrementable>::difference_type difference_type;
|
||||
typedef typename counting_iterator_traits<Incrementable>::reference reference;
|
||||
typedef typename counting_iterator_traits<Incrementable>::reference const_reference;
|
||||
typedef typename counting_iterator_traits<Incrementable>::pointer pointer;
|
||||
typedef typename counting_iterator_traits<Incrementable>::pointer const_pointer;
|
||||
typedef typename iterator::value_type value_type;
|
||||
typedef typename iterator::difference_type difference_type;
|
||||
typedef typename iterator::reference reference;
|
||||
typedef typename iterator::reference const_reference;
|
||||
typedef typename iterator::pointer pointer;
|
||||
typedef typename iterator::pointer const_pointer;
|
||||
|
||||
// It would be nice to select an unsigned type, but this is appropriate
|
||||
// since the library makes an attempt to select a difference_type which can
|
||||
// hold the difference between any two iterators.
|
||||
typedef typename counting_iterator_traits<Incrementable>::difference_type size_type;
|
||||
typedef typename iterator::difference_type size_type;
|
||||
|
||||
half_open_range(Incrementable start, Incrementable finish)
|
||||
: m_start(start),
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
# ifdef BOOST_NO_STD_ITERATOR
|
||||
# if defined(BOOST_NO_STD_ITERATOR) && !defined(BOOST_MSVC_STD_ITERATOR)
|
||||
template <class Category, class T,
|
||||
class Distance = std::ptrdiff_t,
|
||||
class Pointer = T*, class Reference = T&>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,6 +5,10 @@
|
||||
// test suite for STL concepts such as iterators and containers.
|
||||
//
|
||||
// Revision History:
|
||||
// 28 Apr 2002 Fixed input iterator requirements.
|
||||
// For a == b a++ == b++ is no longer required.
|
||||
// See 24.1.1/3 for details.
|
||||
// (Thomas Witt)
|
||||
// 08 Feb 2001 Fixed bidirectional iterator test so that
|
||||
// --i is no longer a precondition.
|
||||
// (Jeremy Siek)
|
||||
@ -74,22 +78,40 @@ void mutable_trivial_iterator_test(const Iterator i, const Iterator j, T val)
|
||||
template <class Iterator, class T>
|
||||
void input_iterator_test(Iterator i, T v1, T v2)
|
||||
{
|
||||
Iterator i1 = i, i2 = i;
|
||||
Iterator i1(i);
|
||||
|
||||
assert(i == i1++);
|
||||
assert(i != ++i2);
|
||||
|
||||
trivial_iterator_test(i, i1, v1);
|
||||
trivial_iterator_test(i, i2, v1);
|
||||
|
||||
++i;
|
||||
assert(i == i1);
|
||||
assert(i == i2);
|
||||
++i1;
|
||||
++i2;
|
||||
assert(!(i != i1));
|
||||
|
||||
trivial_iterator_test(i, i1, v2);
|
||||
trivial_iterator_test(i, i2, v2);
|
||||
// I can see no generic way to create an input iterator
|
||||
// that is in the domain of== of i and != i.
|
||||
// The following works for istream_iterator but is not
|
||||
// guaranteed to work for arbitrary input iterators.
|
||||
//
|
||||
// Iterator i2;
|
||||
//
|
||||
// assert(i != i2);
|
||||
// assert(!(i == i2));
|
||||
|
||||
assert(*i1 == v1);
|
||||
assert(*i == v1);
|
||||
|
||||
// we cannot test for equivalence of (void)++i & (void)i++
|
||||
// as i is only guaranteed to be single pass.
|
||||
assert(*i++ == v1);
|
||||
|
||||
i1 = i;
|
||||
|
||||
assert(i == i1);
|
||||
assert(!(i != i1));
|
||||
|
||||
assert(*i1 == v2);
|
||||
assert(*i == v2);
|
||||
|
||||
// i is dereferencable, so it must be incrementable.
|
||||
++i;
|
||||
|
||||
// how to test for operator-> ?
|
||||
}
|
||||
|
||||
// how to test output iterator?
|
||||
@ -124,6 +146,23 @@ void forward_iterator_test(Iterator i, T v1, T v2)
|
||||
{
|
||||
input_iterator_test(i, v1, v2);
|
||||
|
||||
Iterator i1 = i, i2 = i;
|
||||
|
||||
assert(i == i1++);
|
||||
assert(i != ++i2);
|
||||
|
||||
trivial_iterator_test(i, i1, v1);
|
||||
trivial_iterator_test(i, i2, v1);
|
||||
|
||||
++i;
|
||||
assert(i == i1);
|
||||
assert(i == i2);
|
||||
++i1;
|
||||
++i2;
|
||||
|
||||
trivial_iterator_test(i, i1, v2);
|
||||
trivial_iterator_test(i, i2, v2);
|
||||
|
||||
// borland doesn't allow non-type template parameters
|
||||
# if !defined(__BORLANDC__) || (__BORLANDC__ > 0x551)
|
||||
lvalue_test<(boost::is_pointer<Iterator>::value)>::check(i);
|
||||
|
72
include/boost/permutation_iterator.hpp
Normal file
72
include/boost/permutation_iterator.hpp
Normal file
@ -0,0 +1,72 @@
|
||||
// (C) Copyright Toon Knapen 2001. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
//
|
||||
|
||||
#ifndef boost_permutation_iterator_hpp
|
||||
#define boost_permutation_iterator_hpp
|
||||
|
||||
#include <boost/iterator_adaptors.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
template < typename IndexIterator >
|
||||
struct permutation_iterator_policies : public default_iterator_policies
|
||||
{
|
||||
permutation_iterator_policies() {}
|
||||
|
||||
permutation_iterator_policies(IndexIterator order_it)
|
||||
: order_it_( order_it )
|
||||
{}
|
||||
|
||||
template <class IteratorAdaptor>
|
||||
typename IteratorAdaptor::reference dereference(const IteratorAdaptor& x) const
|
||||
{ return *(x.base() + *order_it_); }
|
||||
|
||||
template <class IteratorAdaptor>
|
||||
void increment(IteratorAdaptor&)
|
||||
{ ++order_it_; }
|
||||
|
||||
template <class IteratorAdaptor>
|
||||
void decrement(IteratorAdaptor&)
|
||||
{ --order_it_; }
|
||||
|
||||
template <class IteratorAdaptor, class DifferenceType>
|
||||
void advance(IteratorAdaptor& x, DifferenceType n)
|
||||
{ std::advance( order_it_, n ); }
|
||||
|
||||
template <class IteratorAdaptor1, class IteratorAdaptor2>
|
||||
typename IteratorAdaptor1::difference_type
|
||||
distance(const IteratorAdaptor1& x, const IteratorAdaptor2& y) const
|
||||
{ return std::distance( x.policies().order_it_, y.policies().order_it_ ); }
|
||||
|
||||
template <class IteratorAdaptor1, class IteratorAdaptor2>
|
||||
bool equal(const IteratorAdaptor1& x, const IteratorAdaptor2& y) const
|
||||
{ return x.policies().order_it_ == y.policies().order_it_; }
|
||||
|
||||
IndexIterator order_it_;
|
||||
};
|
||||
|
||||
template < typename ElementIterator, typename IndexIterator >
|
||||
struct permutation_iterator_generator
|
||||
{
|
||||
typedef boost::iterator_adaptor
|
||||
< ElementIterator,
|
||||
permutation_iterator_policies< IndexIterator >
|
||||
> type;
|
||||
};
|
||||
|
||||
template < class IndexIterator, class ElementIterator >
|
||||
inline typename permutation_iterator_generator< ElementIterator, IndexIterator >::type
|
||||
make_permutation_iterator(ElementIterator base, IndexIterator order)
|
||||
{
|
||||
typedef typename permutation_iterator_generator< ElementIterator, IndexIterator >::type result_t;
|
||||
return result_t( base, order );
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // boost_permutation_iterator_hpp
|
||||
|
Reference in New Issue
Block a user