Compare commits

..

65 Commits

Author SHA1 Message Date
6bfb6ff582 Try a new interface
[SVN r9061]
2001-02-09 21:00:31 +00:00
df4b9402bd This commit was manufactured by cvs2svn to create branch
'better_indirect'.

[SVN r9056]
2001-02-09 15:17:18 +00:00
8174963a45 Rolled back Jeremy's new constructor for now; it was causing problems with counting_iterator_test
Attempted fix for Borland


[SVN r9055]
2001-02-09 15:17:17 +00:00
86e183c75e MSVC porting
[SVN r9052]
2001-02-09 05:44:13 +00:00
a94c9d0db2 Added iterator constructor to allow const adaptor
from non-const adaptee.

      Changed make_xxx to pass iterators by-value to
      get arrays converted to pointers.

      Removed InnerIterator template parameter from
      indirect_iterator_generator.

      Rearranged parameters for make_filter_iterator


[SVN r9050]
2001-02-09 05:26:01 +00:00
8a73dcd052 Fixed bidirectional iterator test so that --i is no longer a precondition.
[SVN r9048]
2001-02-09 04:29:11 +00:00
8496571204 Fold in Jeremy's improvement to make_reverse_iterator
[SVN r9042]
2001-02-09 03:29:11 +00:00
bafe0703a6 Beginning of a failed attempt to appease Borland
[SVN r9041]
2001-02-09 03:27:40 +00:00
b05b38810c just whitespace
[SVN r9030]
2001-02-08 04:45:18 +00:00
edf17ba001 put indirect_iterator_pair_generator back in
[SVN r9027]
2001-02-08 03:41:23 +00:00
ee9f140fae Removed all pair generator's except for projection and
some const adaptor generators.

Added make_xxx_iterator() helper functions for remaining
iterator adaptors.

Removed some traits template parameters where they
where no longer needed thanks to detail::iterator_traits.

Moved some of the compile-time logic into enums for
EDG compatibility.


[SVN r9024]
2001-02-08 03:07:33 +00:00
762e603013 rename counting_iterator() -> make_counting_iterator()
[SVN r9015]
2001-02-07 22:27:02 +00:00
6eeeb23332 Removed iterator_adaptor_pair_generator and
reverse_iterator_pair_generator (more such culling to come)

Improved comments

Changed all uses of std::iterator_traits as default arguments
to boost::detail::iterator_traits for improved utility in
non-generic contexts

Fixed naming convention of non-template parameter names


[SVN r9003]
2001-02-07 17:22:16 +00:00
07482538ed Produce operator-> proxy objects for InputIterators
Added static assertions to do some basic concept checks

Renamed single-type generators -> xxx_generator
Renamed const/nonconst iterator generators -> xxx_pair_generator

Added make_transform_iterator(iter, function)

The existence of boost::detail::iterator_traits allowed many
template arguments to be defaulted. Some arguments had to be
moved to accomplish it.


[SVN r8994]
2001-02-07 05:15:42 +00:00
d17e8dae9b codewarrior bug workaround
[SVN r8989]
2001-02-06 23:59:02 +00:00
5e1bc30db9 1st draft
[SVN r8939]
2001-02-05 05:39:43 +00:00
e8389d5f49 start of iterator concept tests
[SVN r8938]
2001-02-05 05:38:44 +00:00
332f18cf9f changed category for transform iterator traits to input iterator
[SVN r8936]
2001-02-04 23:45:57 +00:00
7aea7b7881 Factored counting_iterator stuff into boost/counting_iterator.hpp
[SVN r8935]
2001-02-04 23:37:01 +00:00
3e6796ab91 Fixed lvalue test
[SVN r8934]
2001-02-04 23:35:26 +00:00
893b5c0e25 Moved contents to boost/iterator_adaptors.hpp
[SVN r8933]
2001-02-04 23:34:29 +00:00
41c334d718 MWERKS bug workaround
[SVN r8931]
2001-02-04 20:35:23 +00:00
05336f45c4 Support for user-defined iterator categories
[SVN r8930]
2001-02-04 20:33:45 +00:00
90299982a6 Added counting_iterator_generator; updated comments
[SVN r8928]
2001-02-04 19:38:28 +00:00
93b54c15c8 Inital checkin
[SVN r8927]
2001-02-04 19:11:30 +00:00
25f9acabac corrected preconditions
[SVN r8925]
2001-02-04 19:00:03 +00:00
bb2ffadade Added lvalue test
[SVN r8922]
2001-02-04 18:25:55 +00:00
b6aa32721f Inital checkin
[SVN r8813]
2001-01-30 16:00:37 +00:00
8f41e88f85 fixed bug in assignment operator under VC++, which was the cause of
the access violation error in graph/test/graph.cpp. The root
  of this bug is in compressed pair, which VC++ has a hard time
  generating a correct operator= for.


[SVN r8767]
2001-01-25 04:57:16 +00:00
58b56fbabb Initial checkin
[SVN r8757]
2001-01-24 18:36:52 +00:00
9a4b0b576d added filter iterator
[SVN r8735]
2001-01-23 19:09:30 +00:00
c948483ec1 added some #ifdefs to prevent compilation of workaround code
[SVN r8688]
2001-01-21 20:28:02 +00:00
a31a89ae7d fixed some mwerks compiler errors
[SVN r8683]
2001-01-21 19:33:06 +00:00
b8ccd48fa3 Moved type<> to boost/type.hpp
[SVN r8678]
2001-01-21 06:20:20 +00:00
cf1d6a30af fixed some warnings under g++
[SVN r8600]
2001-01-15 03:10:11 +00:00
7fa5da6778 fixed dispatch for MIPSpro workaround
[SVN r8599]
2001-01-15 02:51:45 +00:00
34a9d4e702 another MIPSpro workaround
[SVN r8597]
2001-01-14 21:10:44 +00:00
42710d0967 also, advance_impl should take non-const Iter param
[SVN r8595]
2001-01-14 19:23:19 +00:00
487acf8c1c iter() should be i.iter()
[SVN r8594]
2001-01-14 19:21:29 +00:00
d6ec67f6ed added version number for MIPSpro
[SVN r8586]
2001-01-14 01:27:01 +00:00
e1b64d45e2 MIPSpro port, avoid using operators that are not defined
[SVN r8584]
2001-01-14 01:14:39 +00:00
4314dd18ae added <cstddef> for std::ptrdiff_t
[SVN r8562]
2001-01-12 18:50:21 +00:00
b634113daf added concept checking classes for purposes of documentation (they don't get invoked)
[SVN r8499]
2000-12-28 03:00:45 +00:00
0c68369f23 changed reference type of counting_iterator to avoid problems on VC++
[SVN r8474]
2000-12-17 21:53:22 +00:00
42ddb0d47b added const in a couple places to make sure the iterator operators
that should be const (like operator* and operator[]) are indeed const


[SVN r8466]
2000-12-15 21:51:02 +00:00
e6191bc913 operator[] needed to be const
[SVN r8463]
2000-12-15 19:31:16 +00:00
8cf1b8acb2 forgot #include <iterator>
[SVN r8461]
2000-12-13 23:24:55 +00:00
3852c810f3 various changes, almost forgot to check in
[SVN r8379]
2000-12-03 06:20:23 +00:00
04c0c043e0 added projection iterator to the test
[SVN r8320]
2000-11-24 20:45:26 +00:00
ffec5207fa changed names to "Inner" and "Outer"
[SVN r8318]
2000-11-24 20:05:11 +00:00
31fef5252a simplified version of iterator_adaptor, plus fix to indirect iterator
and addition of projection iterator


[SVN r8317]
2000-11-24 19:40:51 +00:00
80bcc4e643 some concept checking changes as per review comments
[SVN r8268]
2000-11-20 18:17:52 +00:00
87a3007c92 completed codewarrior workaround
[SVN r8169]
2000-11-10 16:24:39 +00:00
ea1513596d changed counting iterator policies to a template class to avoid
using template  member functions


[SVN r8157]
2000-11-07 22:22:49 +00:00
9d659841a0 don't use iterator adaptors at all under VC++, even with STLport
until we can figure out why the INTERNAL COMPILER ERROR's are happening


[SVN r8139]
2000-11-04 23:15:10 +00:00
efcbd24229 port to Codewarrior 6.0
[SVN r8107]
2000-11-03 04:25:13 +00:00
3692175786 added base() function
[SVN r8098]
2000-11-02 02:29:53 +00:00
d3b8f893bc changed reference type
[SVN r8033]
2000-10-26 14:04:50 +00:00
cebe553621 ported the graph library to borland
[SVN r7965]
2000-10-17 00:16:05 +00:00
b54236986d work around for VC++ bug, triggered by overloading of remove_edge
[SVN r7860]
2000-09-27 21:02:16 +00:00
24c3beb791 rolled back the removal of the iterator_adaptor alternate code,
added the graph test file


[SVN r7851]
2000-09-26 22:09:34 +00:00
50c9214b82 completed conversion of properties to use _t and enums.
Also noticed that problems regarding iterator_adaptor has
gone away, so I've removed the ifdef's that took it out.


[SVN r7840]
2000-09-26 07:29:12 +00:00
c583cf8730 removed tabs
[SVN r7835]
2000-09-25 21:19:29 +00:00
61d2d43ea5 Use iterator adaptors with STLport.
[SVN r7788]
2000-09-24 01:06:34 +00:00
76efd2456c changes for visual c++ port
[SVN r7764]
2000-09-22 04:18:51 +00:00
6 changed files with 1007 additions and 883 deletions

View File

@ -1,58 +0,0 @@
// integer.hpp workarounds for non-conforming standard libraries -----------//
// (C) Copyright Boost.org 2000. 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.
// See http://www.boost.org for most recent version including documentation.
// Revision History
// 28 Jun 00 Workarounds to deal with known MSVC bugs (David Abrahams)
// 26 Jun 00 Initial version (Jeremy Siek)
#ifndef BOOST_ITERATOR_HPP
#define BOOST_ITERATOR_HPP
#include <iterator>
#include <boost/config.hpp>
namespace boost
{
# ifdef BOOST_NO_STD_ITERATOR
template <class Category, class T,
class Distance = std::ptrdiff_t,
class Pointer = T*, class Reference = T&>
struct iterator
{
typedef T value_type;
typedef Distance difference_type;
typedef Pointer pointer;
typedef Reference reference;
typedef Category iterator_category;
};
# else
// declare iterator_base in namespace detail to work around MSVC bugs which
// prevent derivation from an identically-named class in a different namespace.
namespace detail {
template <class Category, class T, class Distance, class Pointer, class Reference>
# if !defined(BOOST_MSVC_STD_ITERATOR)
struct iterator_base : std::iterator<Category, T, Distance, Pointer, Reference> {};
# else
struct iterator_base : std::iterator<Category, T, Distance>
{
typedef Reference reference;
typedef Pointer pointer;
typedef Distance difference_type;
};
# endif
}
template <class Category, class T, class Distance = std::ptrdiff_t,
class Pointer = T*, class Reference = T&>
struct iterator : detail::iterator_base<Category, T, Distance, Pointer, Reference> {};
# endif
} // namespace boost
#endif // BOOST_ITERATOR_HPP

File diff suppressed because it is too large Load Diff

View File

@ -1,68 +0,0 @@
// (C) Copyright Jeremy Siek 1999. 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_INT_ITERATOR_H
#define BOOST_INT_ITERATOR_H
#include <boost/iterator.hpp>
#if !defined BOOST_MSVC
#include <boost/operators.hpp>
#endif
#include <iostream>
//using namespace std;
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
namespace boost {
#endif
// this should use random_access_iterator_helper but I've had
// VC++ portablility problems with that. -JGS
template <class IntT>
class int_iterator
{
typedef int_iterator self;
public:
typedef std::random_access_iterator_tag iterator_category;
typedef IntT value_type;
typedef IntT& reference;
typedef IntT* pointer;
typedef ptrdiff_t difference_type;
inline int_iterator() : _i(0) { }
inline int_iterator(IntT i) : _i(i) { }
inline int_iterator(const self& x) : _i(x._i) { }
inline self& operator=(const self& x) { _i = x._i; return *this; }
inline IntT operator*() { return _i; }
inline IntT operator[](IntT n) { return _i + n; }
inline self& operator++() { ++_i; return *this; }
inline self operator++(int) { self t = *this; ++_i; return t; }
inline self& operator+=(IntT n) { _i += n; return *this; }
inline self operator+(IntT n) { self t = *this; t._i += n; return t; }
inline self& operator--() { --_i; return *this; }
inline self operator--(int) { self t = *this; --_i; return t; }
inline self& operator-=(IntT n) { _i -= n; return *this; }
inline IntT operator-(const self& x) const { return _i - x._i; }
inline bool operator==(const self& x) const { return _i == x._i; }
// vc++ had a problem finding != in random_access_iterator_helper
// need to look into this... for now implementing everything here -JGS
inline bool operator!=(const self& x) const { return _i != x._i; }
inline bool operator<(const self& x) const { return _i < x._i; }
protected:
IntT _i;
};
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
} /* namespace boost */
#endif
#ifdef BOOST_NO_OPERATORS_IN_NAMESPACE
namespace boost {
using ::int_iterator;
}
#endif
#endif /* BOOST_INT_ITERATOR_H */

View File

@ -1,76 +0,0 @@
// (C) Copyright David Abrahams 2000. 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.
//
// (C) Copyright Jeremy Siek 2000. 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_INTEGER_RANGE_HPP_
#define BOOST_INTEGER_RANGE_HPP_
#ifdef BOOST_MSVC
#include <boost/pending/detail/int_iterator.hpp>
#else
#include <boost/pending/iterator_adaptors.hpp>
#endif
namespace boost {
//=============================================================================
// Counting Iterator and Integer Range Class
struct counting_iterator_policies : public default_iterator_policies
{
template <class IntegerType>
IntegerType dereference(type<IntegerType>, const IntegerType& i) const
{ return i; }
};
template <class IntegerType>
struct counting_iterator_traits {
typedef IntegerType value_type;
typedef IntegerType reference;
typedef value_type* pointer;
typedef std::ptrdiff_t difference_type;
typedef std::random_access_iterator_tag iterator_category;
};
template <class IntegerType>
struct integer_range {
#ifdef BOOST_MSVC
typedef int_iterator<IntegerType> iterator;
#else
typedef iterator_adaptor<IntegerType, counting_iterator_policies,
counting_iterator_traits<IntegerType>, IntegerType> iterator;
#endif
typedef iterator const_iterator;
typedef IntegerType value_type;
typedef std::ptrdiff_t difference_type;
typedef IntegerType reference;
typedef IntegerType const_reference;
typedef const IntegerType* pointer;
typedef const IntegerType* const_pointer;
typedef IntegerType size_type;
integer_range(IntegerType start, IntegerType finish)
: m_start(start), m_finish(finish) { }
iterator begin() const { return iterator(m_start); }
iterator end() const { return iterator(m_finish); }
size_type size() const { return m_finish - m_start; }
bool empty() const { return m_finish == m_start; }
void swap(integer_range& x) {
std::swap(m_start, x.m_start);
std::swap(m_finish, x.m_finish);
}
protected:
IntegerType m_start, m_finish;
};
} // namespace boost
#endif // BOOST_INTEGER_RANGE_HPP_

View File

@ -1,510 +0,0 @@
// (C) Copyright David Abrahams 2000. 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.
//
// (C) Copyright Jeremy Siek 2000. 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_ITERATOR_ADAPTOR_DWA053000_HPP_
#define BOOST_ITERATOR_ADAPTOR_DWA053000_HPP_
#include <iterator>
#include <boost/utility.hpp>
#include <boost/operators.hpp>
#include <boost/compressed_pair.hpp>
// I was having some problems with VC6. I couldn't tell whether our hack for
// stock GCC was causing problems so I needed an easy way to turn it on and
// off. Now we can test the hack with various compilers and still have an "out"
// if it doesn't work. -dwa 7/31/00
#if __GNUC__ == 2 && __GNUC_MINOR__ <= 96 && !defined(__STL_USE_NAMESPACES)
# define BOOST_RELOPS_AMBIGUITY_BUG 1
#endif
namespace boost {
// Just a "type envelope"; works around some MSVC deficiencies.
template <class T>
struct type {};
//=============================================================================
// Default policies for iterator adaptors. You can use this as a base
// class if you want to customize particular policies.
struct default_iterator_policies
{
template <class Reference, class Iterator>
static Reference dereference(type<Reference>, const Iterator& x)
{ return *x; }
template <class Iterator>
static void increment(Iterator& x)
{ ++x; }
template <class Iterator>
static void decrement(Iterator& x)
{ --x; }
template <class Iterator, class DifferenceType>
static void advance(Iterator& x, DifferenceType n)
{ x += n; }
template <class Difference, class Iterator1, class Iterator2>
static Difference distance(type<Difference>, const Iterator1& x, const Iterator2& y)
{ return y - x; }
template <class Iterator1, class Iterator2>
static bool equal(const Iterator1& x, const Iterator2& y)
{ return x == y; }
template <class Iterator1, class Iterator2>
static bool less(const Iterator1& x, const Iterator2& y)
{ return x < y; }
};
// putting the comparisons in a base class avoids the g++
// ambiguous overload bug due to the relops operators
#ifdef BOOST_RELOPS_AMBIGUITY_BUG
template <class Derived, class Base>
struct iterator_comparisons : Base { };
template <class D1, class D2, class Base1, class Base2>
inline bool operator==(const iterator_comparisons<D1,Base1>& xb,
const iterator_comparisons<D2,Base2>& yb)
{
const D1& x = static_cast<const D1&>(xb);
const D2& y = static_cast<const D2&>(yb);
return x.policies().equal(x.iter(), y.iter());
}
template <class D1, class D2, class Base1, class Base2>
inline bool operator!=(const iterator_comparisons<D1,Base1>& xb,
const iterator_comparisons<D2,Base2>& yb)
{
const D1& x = static_cast<const D1&>(xb);
const D2& y = static_cast<const D2&>(yb);
return !x.policies().equal(x.iter(), y.iter());
}
template <class D1, class D2, class Base1, class Base2>
inline bool operator<(const iterator_comparisons<D1,Base1>& xb,
const iterator_comparisons<D2,Base2>& yb)
{
const D1& x = static_cast<const D1&>(xb);
const D2& y = static_cast<const D2&>(yb);
return x.policies().less(x.iter(), y.iter());
}
template <class D1, class D2, class Base1, class Base2>
inline bool operator>(const iterator_comparisons<D1,Base1>& xb,
const iterator_comparisons<D2,Base2>& yb)
{
const D1& x = static_cast<const D1&>(xb);
const D2& y = static_cast<const D2&>(yb);
return x.policies().less(y.iter(), x.iter());
}
template <class D1, class D2, class Base1, class Base2>
inline bool operator>=(const iterator_comparisons<D1,Base1>& xb,
const iterator_comparisons<D2,Base2>& yb)
{
const D1& x = static_cast<const D1&>(xb);
const D2& y = static_cast<const D2&>(yb);
return !x.policies().less(x.iter(), y.iter());
}
template <class D1, class D2, class Base1, class Base2>
inline bool operator<=(const iterator_comparisons<D1,Base1>& xb,
const iterator_comparisons<D2,Base2>& yb)
{
const D1& x = static_cast<const D1&>(xb);
const D2& y = static_cast<const D2&>(yb);
return !x.policies().less(y.iter(), x.iter());
}
#endif
//=============================================================================
// iterator_adaptor - A generalized adaptor around an existing
// iterator, which is itself an iterator
//
// Iterator - the iterator type being wrapped.
//
// Policies - a set of policies determining how the resulting iterator
// works.
//
// Traits - a class satisfying the same requirements as a specialization of
// std::iterator_traits for the resulting iterator.
//
// NonconstIterator - the corresponding non-const iterator type for
// Iterator, if any. You don't need to supply this if you are not make a
// const/non-const iterator pair.
//
template <class Iterator, class Policies,
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
class Traits,
#else
class Traits = std::iterator_traits<Iterator>,
#endif
class NonconstIterator = Iterator
>
struct iterator_adaptor :
#ifdef BOOST_RELOPS_AMBIGUITY_BUG
iterator_comparisons<
iterator_adaptor<Iterator,Policies,Traits,NonconstIterator>,
#endif
boost::iterator<typename Traits::iterator_category,
typename Traits::value_type, typename Traits::difference_type,
typename Traits::pointer, typename Traits::reference>
#ifdef BOOST_RELOPS_AMBIGUITY_BUG
>
#endif
{
typedef iterator_adaptor<Iterator, Policies, Traits,NonconstIterator> Self;
public:
typedef typename Traits::difference_type difference_type;
typedef typename Traits::value_type value_type;
typedef typename Traits::pointer pointer;
typedef typename Traits::reference reference;
typedef typename Traits::iterator_category iterator_category;
iterator_adaptor() { }
iterator_adaptor(const Iterator& iter, const Policies& p = Policies())
: m_iter_p(iter, p) {}
#ifdef BOOST_MSVC6_MEMBER_TEMPLATES
template <class MutableIterator, class OtherTraits>
iterator_adaptor(const iterator_adaptor<MutableIterator, Policies, OtherTraits, NonconstIterator>& rhs)
: m_iter_p(rhs.iter(), rhs.policies()) {}
template <class MutableIterator, class OtherTraits>
Self& operator=(const iterator_adaptor<MutableIterator, Policies, OtherTraits, NonconstIterator>& rhs)
{
iter() = rhs.iter();
policies() = rhs.policies();
return *this;
}
#else
template <class OtherTraits>
iterator_adaptor(const iterator_adaptor<NonconstIterator, Policies, OtherTraits, NonconstIterator>& rhs)
: m_iter_p(rhs.iter(), rhs.policies()) {}
template <class OtherTraits>
Self& operator=(const iterator_adaptor<NonconstIterator, Policies, OtherTraits, NonconstIterator>& rhs)
{
iter() = rhs.iter();
policies() = rhs.policies();
return *this;
}
#endif
reference operator*() const {
return policies().dereference(type<reference>(), iter());
}
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning( disable : 4284 )
#endif
pointer operator->() const
{ return &*this; }
#ifdef _MSC_VER
# pragma warning(pop)
#endif
reference operator[](difference_type n)
{ return *(*this + n); }
Self& operator++() {
policies().increment(iter());
return *this;
}
Self operator++(int) { Self tmp(*this); ++*this; return tmp; }
Self& operator--() {
policies().decrement(iter());
return *this;
}
Self operator--(int) { Self tmp(*this); --*this; return tmp; }
Self& operator+=(difference_type n) {
policies().advance(iter(), n);
return *this;
}
Self& operator-=(difference_type n) {
policies().advance(iter(), -n);
return *this;
}
private:
typedef Policies policies_type;
compressed_pair<Iterator,Policies> m_iter_p;
public: // too many compilers have trouble when these are private.
Policies& policies() { return m_iter_p.second(); }
const Policies& policies() const { return m_iter_p.second(); }
Iterator& iter() { return m_iter_p.first(); }
const Iterator& iter() const { return m_iter_p.first(); }
};
template <class Iterator, class Policies, class Traits, class NonconstIterator>
iterator_adaptor<Iterator,Policies,Traits,NonconstIterator>
operator-(iterator_adaptor<Iterator,Policies,Traits,NonconstIterator> p, const typename Traits::difference_type x)
{
return p -= x;
}
template <class Iterator, class Policies, class Traits, class NonconstIterator>
iterator_adaptor<Iterator,Policies,Traits,NonconstIterator>
operator+(iterator_adaptor<Iterator,Policies,Traits,NonconstIterator> p, const typename Traits::difference_type x)
{
return p += x;
}
template <class Iterator, class Policies, class Traits, class NonconstIterator>
iterator_adaptor<Iterator,Policies,Traits,NonconstIterator>
operator+(const typename Traits::difference_type x, iterator_adaptor<Iterator,Policies,Traits,NonconstIterator> p)
{
return p += x;
}
template <class Iterator1, class Iterator2, class Policies, class Traits1, class Traits2, class NonconstIterator>
typename Traits1::difference_type operator-(
const iterator_adaptor<Iterator1,Policies,Traits1,NonconstIterator>& x,
const iterator_adaptor<Iterator2,Policies,Traits2,NonconstIterator>& y )
{
typedef typename Traits1::difference_type difference_type;
return x.policies().distance(type<difference_type>(), y.iter(), x.iter());
}
#ifndef BOOST_RELOPS_AMBIGUITY_BUG
template <class Iterator1, class Iterator2, class Policies, class Traits1, class Traits2, class NonconstIterator>
inline bool
operator==(const iterator_adaptor<Iterator1,Policies,Traits1,NonconstIterator>& x, const iterator_adaptor<Iterator2,Policies,Traits2,NonconstIterator>& y) {
return x.policies().equal(x.iter(), y.iter());
}
template <class Iterator1, class Iterator2, class Policies, class Traits1, class Traits2, class NonconstIterator>
inline bool
operator<(const iterator_adaptor<Iterator1,Policies,Traits1,NonconstIterator>& x, const iterator_adaptor<Iterator2,Policies,Traits2,NonconstIterator>& y) {
return x.policies().less(x.iter(), y.iter());
}
template <class Iterator1, class Iterator2, class Policies, class Traits1, class Traits2, class NonconstIterator>
inline bool
operator>(const iterator_adaptor<Iterator1,Policies,Traits1,NonconstIterator>& x,
const iterator_adaptor<Iterator2,Policies,Traits2,NonconstIterator>& y) {
return x.policies().less(y.iter(), x.iter());
}
template <class Iterator1, class Iterator2, class Policies, class Traits1, class Traits2, class NonconstIterator>
inline bool
operator>=(const iterator_adaptor<Iterator1,Policies,Traits1,NonconstIterator>& x, const iterator_adaptor<Iterator2,Policies,Traits2,NonconstIterator>& y) {
return !x.policies().less(x.iter(), y.iter());
}
template <class Iterator1, class Iterator2, class Policies, class Traits1, class Traits2, class NonconstIterator>
inline bool
operator<=(const iterator_adaptor<Iterator1,Policies,Traits1,NonconstIterator>& x,
const iterator_adaptor<Iterator2,Policies,Traits2,NonconstIterator>& y) {
return !x.policies().less(y.iter(), x.iter());
}
template <class Iterator1, class Iterator2, class Policies, class Traits1, class Traits2, class NonconstIterator>
inline bool
operator!=(const iterator_adaptor<Iterator1,Policies,Traits1,NonconstIterator>& x,
const iterator_adaptor<Iterator2,Policies,Traits2,NonconstIterator>& y) {
return !x.policies().equal(x.iter(), y.iter());
}
#endif
//=============================================================================
// iterator_adaptors - A type generator that simplifies creating
// mutable/const pairs of iterator adaptors.
template <class Iterator, class ConstIterator,
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
class Traits,
class ConstTraits,
#else
class Traits = std::iterator_traits<Iterator>,
class ConstTraits = std::iterator_traits<ConstIterator>,
#endif
class Policies = default_iterator_policies>
class iterator_adaptors
{
public:
typedef iterator_adaptor<Iterator, Policies, Traits, Iterator> iterator;
typedef iterator_adaptor<ConstIterator, Policies, ConstTraits, Iterator>
const_iterator;
};
//=============================================================================
// Transform Iterator Adaptor
template <class AdaptableUnaryFunction>
struct transform_iterator_policies : public default_iterator_policies
{
transform_iterator_policies() { }
transform_iterator_policies(const AdaptableUnaryFunction& f) : m_f(f) { }
template <class Reference, class Iterator>
Reference dereference(type<Reference>, const Iterator& x) const
{ return m_f(*x); }
AdaptableUnaryFunction m_f;
};
template <class AdaptableUnaryFunction, class IteratorTraits>
struct transform_iterator_traits {
typedef typename AdaptableUnaryFunction::result_type value_type;
typedef value_type reference;
typedef value_type* pointer;
typedef typename IteratorTraits::difference_type difference_type;
typedef typename IteratorTraits::iterator_category iterator_category;
};
template <class AdaptableUnaryFunction,
class Iterator,
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
class Traits = std::iterator_traits<Iterator>
#else
class Traits
#endif
>
struct transform_iterator
{
typedef transform_iterator_traits<AdaptableUnaryFunction,Traits>
TransTraits;
typedef iterator_adaptor<Iterator,
transform_iterator_policies<AdaptableUnaryFunction>, TransTraits,
Iterator> type;
};
//=============================================================================
// Indirect Iterators Adaptor
// Tried implementing this with transform_iterator, but that required
// using boost::remove_ref, which is not compiler portable.
struct indirect_iterator_policies : public default_iterator_policies
{
template <class Reference, class Iterator>
Reference dereference(type<Reference>, const Iterator& x) const
{ return **x; }
};
template <class IndirectIterator,
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
class IndirectTraits,
class Traits
#else
class IndirectTraits = std::iterator_traits<IndirectIterator>,
class Traits =
std::iterator_traits<typename IndirectTraits::value_type>
#endif
>
struct indirect_traits
{
typedef typename IndirectTraits::difference_type difference_type;
typedef typename Traits::value_type value_type;
typedef typename Traits::pointer pointer;
typedef typename Traits::reference reference;
typedef typename IndirectTraits::iterator_category iterator_category;
};
template <class IndirectIterator, class ConstIndirectIterator,
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
class IndirectTraits,
class ConstIndirectTraits,
class Traits
#else
class IndirectTraits =
std::iterator_traits<IndirectIterator>,
class ConstIndirectTraits =
std::iterator_traits<ConstIndirectIterator>,
class Traits =
std::iterator_traits<typename IndirectTraits::value_type>
#endif
>
struct indirect_iterators
{
typedef typename IndirectTraits::value_type Iterator;
typedef typename Traits::value_type ValueType;
typedef iterator_adaptors<IndirectIterator, ConstIndirectIterator,
indirect_traits<IndirectIterator, IndirectTraits, Traits>,
indirect_traits<ConstIndirectIterator, ConstIndirectTraits, Traits>,
indirect_iterator_policies
> Adaptors;
typedef typename Adaptors::iterator iterator;
typedef typename Adaptors::const_iterator const_iterator;
};
//=============================================================================
// Reverse Iterators Adaptor
struct reverse_iterator_policies
{
template <class Reference, class Iterator>
Reference dereference(type<Reference>, const Iterator& x) const
{ return *boost::prior(x); }
template <class Iterator>
void increment(Iterator& x) const
{ --x; }
template <class Iterator>
void decrement(Iterator& x) const
{ ++x; }
template <class Iterator, class DifferenceType>
void advance(Iterator& x, DifferenceType n) const
{ x -= n; }
template <class Difference, class Iterator1, class Iterator2>
Difference distance(type<Difference>, const Iterator1& x,
const Iterator2& y) const
{ return x - y; }
template <class Iterator1, class Iterator2>
bool equal(const Iterator1& x, const Iterator2& y) const
{ return x == y; }
template <class Iterator1, class Iterator2>
bool less(const Iterator1& x, const Iterator2& y) const
{ return y < x; }
};
template <class Iterator, class ConstIterator,
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
class Traits = std::iterator_traits<Iterator>,
class ConstTraits = std::iterator_traits<ConstIterator>
#else
class Traits,
class ConstTraits
#endif
>
struct reverse_iterators
{
typedef iterator_adaptors<Iterator,ConstIterator,Traits,ConstTraits,
reverse_iterator_policies> Adaptor;
typedef typename Adaptor::iterator iterator;
typedef typename Adaptor::const_iterator const_iterator;
};
} // namespace boost
#endif

View File

@ -1,171 +0,0 @@
#ifndef BOOST_ITERATOR_TESTS_HPP
#define BOOST_ITERATOR_TESTS_HPP
// This is meant to be the beginnings of a comprehensive, generic
// test suite for STL concepts such as iterators and containers.
#include <assert.h>
namespace boost {
// use this for the value type
struct dummyT {
dummyT() { }
dummyT(int x) : m_x(x) { }
int foo() const { return m_x; }
bool operator==(const dummyT& d) const { return m_x == d.m_x; }
int m_x;
};
// Tests whether type Iterator satisfies the requirements for a
// TrivialIterator.
// Preconditions: i != j, *i == val
template <class Iterator, class T>
void trivial_iterator_test(Iterator i, Iterator j, T val)
{
Iterator k;
assert(i == i);
assert(j == j);
assert(i != j);
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
T v = *i;
#else
typename std::iterator_traits<Iterator>::value_type v = *i;
#endif
assert(v == val);
#if 0
// hmm, this will give a warning for transform_iterator... perhaps
// this should be separated out into a stand-alone test since there
// are several situations where it can't be used, like for
// integer_range::iterator.
assert(v == i->foo());
#endif
k = i;
assert(k == k);
assert(k == i);
assert(k != j);
assert(*k == val);
}
// Preconditions: i != j
template <class Iterator, class T>
void mutable_trivial_iterator_test(Iterator i, Iterator j, T val)
{
*i = val;
trivial_iterator_test(i, j, val);
}
// Preconditions: *i == v1, *++i == v2
template <class Iterator, class T>
void input_iterator_test(Iterator i, T v1, T 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);
}
// how to test output iterator?
template <class Iterator, class T>
void forward_iterator_test(Iterator i, T v1, T v2)
{
input_iterator_test(i, v1, v2);
}
// Preconditions: *i == v1, *++i == v2
template <class Iterator, class T>
void bidirectional_iterator_test(Iterator i, T v1, T v2)
{
input_iterator_test(i, v1, v2);
++i;
Iterator i1 = i, i2 = i;
assert(i == i1--);
assert(i != --i2);
trivial_iterator_test(i, i1, v2);
trivial_iterator_test(i, i2, v2);
--i;
assert(i == i1);
assert(i == i2);
--i1;
--i2;
trivial_iterator_test(i, i1, v1);
trivial_iterator_test(i, i2, v1);
}
// mutable_bidirectional_iterator_test
// Preconditions: [i,i+N) is a valid range
template <class Iterator, class TrueVals>
void random_access_iterator_test(Iterator i, int N, TrueVals vals)
{
bidirectional_iterator_test(i, vals[0], vals[1]);
Iterator j = i;
int c;
for (c = 0; c < N-1; ++c) {
assert(i == j + c);
assert(*i == vals[c]);
assert(*i == j[c]);
assert(*i == *(j + c));
assert(*i == *(c + j));
++i;
assert(i > j);
assert(i >= j);
assert(j <= i);
assert(j < i);
}
Iterator k = j + N - 1;
for (c = 0; c < N-1; ++c) {
assert(i == k - c);
assert(*i == vals[N - 1 - c]);
assert(*i == j[N - 1 - c]);
assert(*i == *(k - c));
assert(i > j);
assert(i >= j);
assert(j <= i);
assert(j < i);
--i;
}
}
// Precondition: i != j
template <class Iterator, class ConstIterator>
void const_nonconst_iterator_test(Iterator i, ConstIterator j)
{
assert(i != j);
assert(j != i);
ConstIterator k(i);
assert(k == i);
assert(i == k);
k = i;
assert(k == i);
assert(i == k);
}
} // namespace boost
#endif // BOOST_ITERATOR_TESTS_HPP