Compare commits

...

6 Commits

Author SHA1 Message Date
671474e521 This commit was manufactured by cvs2svn to create tag
'Version_1_20_1'.

[SVN r8548]
2001-01-10 18:29:12 +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
3 changed files with 89 additions and 7 deletions

View File

@ -35,14 +35,14 @@ namespace boost {
template <class IntegerType>
struct counting_iterator_policies : public default_iterator_policies
{
const IntegerType&
dereference(type<const IntegerType&>, const IntegerType& i) const
IntegerType
dereference(type<IntegerType>, const IntegerType& i) const
{ return i; }
};
template <class IntegerType>
struct counting_iterator_traits {
typedef IntegerType value_type;
typedef const IntegerType& reference;
typedef IntegerType reference;
typedef value_type* pointer;
typedef std::ptrdiff_t difference_type;
typedef std::random_access_iterator_tag iterator_category;

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.
@ -199,7 +280,7 @@ public:
# pragma warning(pop)
#endif
reference operator[](difference_type n)
reference operator[](difference_type n) const
{ return *(*this + n); }
Self& operator++() {

View File

@ -4,6 +4,7 @@
// This is meant to be the beginnings of a comprehensive, generic
// test suite for STL concepts such as iterators and containers.
#include <iterator>
#include <assert.h>
namespace boost {
@ -22,7 +23,7 @@ struct dummyT {
// TrivialIterator.
// Preconditions: i != j, *i == val
template <class Iterator, class T>
void trivial_iterator_test(Iterator i, Iterator j, T val)
void trivial_iterator_test(const Iterator i, const Iterator j, T val)
{
Iterator k;
assert(i == i);
@ -51,7 +52,7 @@ void trivial_iterator_test(Iterator i, Iterator j, T val)
// Preconditions: i != j
template <class Iterator, class T>
void mutable_trivial_iterator_test(Iterator i, Iterator j, T val)
void mutable_trivial_iterator_test(const Iterator i, const Iterator j, T val)
{
*i = val;
trivial_iterator_test(i, j, val);
@ -120,7 +121,7 @@ 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;
const Iterator j = i;
int c;
for (c = 0; c < N-1; ++c) {