Compare commits

...

9 Commits

Author SHA1 Message Date
72db1d978c This commit was manufactured by cvs2svn to create branch 'boostify'.
[SVN r8587]
2001-01-14 01:27:02 +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
5 changed files with 125 additions and 416 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

View File

@ -1,75 +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 += 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; }
inline bool operator<=(const self& x) const { return _i <= x._i; }
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;
};
template <class IntT>
inline int_iterator<IntT>
operator+(IntT n, int_iterator<IntT> t) { t += n; return t; }
#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,99 +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_
#include <boost/config.hpp>
#if 1
// Still evaluating whether VC++ can handle this.
#define BOOST_USE_ITERATOR_ADAPTORS
#endif
#ifdef BOOST_USE_ITERATOR_ADAPTORS
#include <boost/pending/iterator_adaptors.hpp>
#else
#include <boost/pending/detail/int_iterator.hpp>
#endif
namespace boost {
//=============================================================================
// Counting Iterator and Integer Range Class
#ifdef BOOST_USE_ITERATOR_ADAPTORS
template <class IntegerType>
struct counting_iterator_policies : public default_iterator_policies
{
const IntegerType&
dereference(type<const IntegerType&>, const IntegerType& i) const
{ return i; }
};
template <class IntegerType>
struct counting_iterator_traits {
typedef IntegerType value_type;
typedef const IntegerType& reference;
typedef value_type* pointer;
typedef std::ptrdiff_t difference_type;
typedef std::random_access_iterator_tag iterator_category;
};
#endif
template <class IntegerType>
struct integer_range {
#ifdef BOOST_USE_ITERATOR_ADAPTORS
typedef iterator_adaptor<IntegerType,
counting_iterator_policies<IntegerType>,
counting_iterator_traits<IntegerType> > iterator;
#else
typedef int_iterator<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;
};
template <class IntegerType>
inline integer_range<IntegerType>
make_integer_range(IntegerType first, IntegerType last)
{
return integer_range<IntegerType>(first, last);
}
} // namespace boost
#ifdef BOOST_USE_ITERATOR_ADAPTORS
#undef BOOST_USE_ITERATOR_ADAPTORS
#endif
#endif // BOOST_INTEGER_RANGE_HPP_

View File

@ -16,6 +16,7 @@
#include <boost/iterator.hpp>
#include <boost/utility.hpp>
#include <boost/compressed_pair.hpp>
#include <boost/concept_check.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
@ -31,6 +32,86 @@ namespace boost {
template <class T>
struct type {};
//============================================================================
// Concept checking classes that express the requirements for iterator
// policies and adapted types. These classes are mostly for
// documentation purposes, and are not used in this header file. They
// merely provide a more succinct statement of what is expected of the
// iterator policies.
template <class Policies, class Adapted, class Traits>
struct TrivialIteratorPoliciesConcept
{
typedef typename Traits::reference Reference;
void constraints() {
function_requires< AssignableConcept<Policies> >();
function_requires< DefaultConstructibleConcept<Policies> >();
function_requires< AssignableConcept<Adapted> >();
function_requires< DefaultConstructibleConcept<Adapted> >();
const_constraints();
}
void const_constraints() const {
Reference r = p.dereference(type<Reference>(), x);
b = p.equal(x, x);
}
Policies p;
Adapted x;
mutable bool b;
};
template <class Policies, class Adapted, class Traits>
struct ForwardIteratorPoliciesConcept
{
void constraints() {
function_requires<
TrivialIteratorPoliciesConcept<Policies, Adapted, Traits>
>();
p.increment(x);
}
Policies p;
Adapted x;
};
template <class Policies, class Adapted, class Traits>
struct BidirectionalIteratorPoliciesConcept
{
void constraints() {
function_requires<
ForwardIteratorPoliciesConcept<Policies, Adapted, Traits>
>();
p.decrement(x);
}
Policies p;
Adapted x;
};
template <class Policies, class Adapted, class Traits>
struct RandomAccessIteratorPoliciesConcept
{
typedef typename Traits::difference_type DifferenceType;
void constraints() {
function_requires<
BidirectionalIteratorPoliciesConcept<Policies, Adapted, Traits>
>();
p.advance(x, n);
const_constraints();
}
void const_constraints() const {
n = p.distance(type<DifferenceType>(), x, x);
b = p.less(x, x);
}
Policies p;
Adapted x;
mutable DifferenceType n;
mutable bool b;
};
//============================================================================
// Default policies for iterator adaptors. You can use this as a base
// class if you want to customize particular policies.
@ -132,6 +213,45 @@ inline bool operator<=(const iterator_comparisons<D1,Base1>& xb,
}
#endif
//============================================================================
// Some compilers (SGI MIPSpro 7.1.3.3) instantiate/compile member functions
// whether or not they are used. The following functions make sure that
// when the base iterators do not support particular operators, those
// operators do not get used.
namespace detail {
// Dummy version for iterators that don't support member access
template <class Iter, class Cat>
inline typename Iter::pointer
operator_arrow(const Iter&, Cat) {
typedef typename Iter::pointer Pointer;
return Pointer();
}
// Real version
template <class Iter>
inline typename Iter::pointer
operator_arrow(const Iter& i, std::forward_iterator_tag) {
return &(*i);
}
// Dummy version for iterators that don't support member access
template <class Iter, class Diff, class Cat>
inline void advance_impl(const Iter&, Diff, Cat) { }
// Real version
template <class Iter, class Diff>
inline typename Iter::pointer
advance_impl(const Iter& i, Diff n, std::random_access_iterator_tag) {
#ifdef __MWERKS__
i.policies().advance<Iter>(iter(), n);
#else
i.policies().advance(iter(), n);
#endif
}
} // namespace detail
//============================================================================
// iterator_adaptor - A generalized adaptor around an existing
// iterator, which is itself an iterator
@ -193,13 +313,13 @@ public:
#endif
pointer operator->() const
{ return &*this; }
{ return detail::operator_arrow(*this, iterator_category()); }
#ifdef _MSC_VER
# pragma warning(pop)
#endif
reference operator[](difference_type n)
reference operator[](difference_type n) const
{ return *(*this + n); }
Self& operator++() {
@ -227,20 +347,12 @@ public:
Self operator--(int) { Self tmp(*this); --*this; return tmp; }
Self& operator+=(difference_type n) {
#ifdef __MWERKS__
policies().advance<Iterator>(iter(), n);
#else
policies().advance(iter(), n);
#endif
detail::advance_impl(*this, n, iterator_category());
return *this;
}
Self& operator-=(difference_type n) {
#ifdef __MWERKS__
policies().advance<Iterator>(iter(), -n);
#else
policies().advance(iter(), -n);
#endif
detail::advance_impl(*this, -n, iterator_category());
return *this;
}
@ -256,6 +368,7 @@ public: // too many compilers have trouble when these are private.
const Iterator& iter() const { return m_iter_p.first(); }
};
template <class Iterator, class Policies, class Traits>
iterator_adaptor<Iterator,Policies,Traits>
operator-(iterator_adaptor<Iterator,Policies,Traits> p, const typename Traits::difference_type x)

View File

@ -1,172 +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]);
Iterator q = k - c;
assert(*i == *q);
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