mirror of
https://github.com/boostorg/iterator.git
synced 2025-07-31 05:17:20 +02:00
Join ralf_grosse_kunstleve with HEAD
[SVN r9444]
This commit is contained in:
@ -1,17 +1,28 @@
|
|||||||
#ifndef BOOST_ITERATOR_TESTS_HPP
|
#ifndef BOOST_ITERATOR_TESTS_HPP
|
||||||
#define BOOST_ITERATOR_TESTS_HPP
|
# define BOOST_ITERATOR_TESTS_HPP
|
||||||
|
|
||||||
// This is meant to be the beginnings of a comprehensive, generic
|
// This is meant to be the beginnings of a comprehensive, generic
|
||||||
// test suite for STL concepts such as iterators and containers.
|
// test suite for STL concepts such as iterators and containers.
|
||||||
|
//
|
||||||
|
// Revision History:
|
||||||
|
// 08 Feb 2001 Fixed bidirectional iterator test so that
|
||||||
|
// --i is no longer a precondition.
|
||||||
|
// (Jeremy Siek)
|
||||||
|
// 04 Feb 2001 Added lvalue test, corrected preconditions
|
||||||
|
// (David Abrahams)
|
||||||
|
|
||||||
#include <iterator>
|
# include <iterator>
|
||||||
#include <assert.h>
|
# include <assert.h>
|
||||||
|
# include <boost/type_traits.hpp>
|
||||||
|
# include <boost/static_assert.hpp>
|
||||||
|
# include <boost/concept_archetype.hpp> // for detail::dummy_constructor
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
|
|
||||||
// use this for the value type
|
// use this for the value type
|
||||||
struct dummyT {
|
struct dummyT {
|
||||||
dummyT() { }
|
dummyT() { }
|
||||||
|
dummyT(detail::dummy_constructor) { }
|
||||||
dummyT(int x) : m_x(x) { }
|
dummyT(int x) : m_x(x) { }
|
||||||
int foo() const { return m_x; }
|
int foo() const { return m_x; }
|
||||||
bool operator==(const dummyT& d) const { return m_x == d.m_x; }
|
bool operator==(const dummyT& d) const { return m_x == d.m_x; }
|
||||||
@ -83,17 +94,47 @@ void input_iterator_test(Iterator i, T v1, T v2)
|
|||||||
|
|
||||||
// how to test output iterator?
|
// how to test output iterator?
|
||||||
|
|
||||||
|
|
||||||
|
template <bool is_pointer> struct lvalue_test
|
||||||
|
{
|
||||||
|
template <class Iterator> static void check(Iterator)
|
||||||
|
{
|
||||||
|
# ifndef BOOST_NO_STD_ITERATOR_TRAITS
|
||||||
|
typedef typename std::iterator_traits<Iterator>::reference reference;
|
||||||
|
typedef typename std::iterator_traits<Iterator>::value_type value_type;
|
||||||
|
# else
|
||||||
|
typedef typename Iterator::reference reference;
|
||||||
|
typedef typename Iterator::value_type value_type;
|
||||||
|
# endif
|
||||||
|
BOOST_STATIC_ASSERT(boost::is_reference<reference>::value);
|
||||||
|
BOOST_STATIC_ASSERT((boost::is_same<reference,value_type&>::value
|
||||||
|
|| boost::is_same<reference,const value_type&>::value
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
# ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||||
|
template <> struct lvalue_test<true> {
|
||||||
|
template <class T> static void check(T) {}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
template <class Iterator, class T>
|
template <class Iterator, class T>
|
||||||
void forward_iterator_test(Iterator i, T v1, T v2)
|
void forward_iterator_test(Iterator i, T v1, T v2)
|
||||||
{
|
{
|
||||||
input_iterator_test(i, v1, v2);
|
input_iterator_test(i, v1, v2);
|
||||||
|
|
||||||
|
// borland doesn't allow non-type template parameters
|
||||||
|
# if !defined(__BORLANDC__) || (__BORLANDC__ > 0x551)
|
||||||
|
lvalue_test<(boost::is_pointer<Iterator>::value)>::check(i);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preconditions: *i == v1, *++i == v2
|
// Preconditions: *i == v1, *++i == v2
|
||||||
template <class Iterator, class T>
|
template <class Iterator, class T>
|
||||||
void bidirectional_iterator_test(Iterator i, T v1, T v2)
|
void bidirectional_iterator_test(Iterator i, T v1, T v2)
|
||||||
{
|
{
|
||||||
input_iterator_test(i, v1, v2);
|
forward_iterator_test(i, v1, v2);
|
||||||
++i;
|
++i;
|
||||||
|
|
||||||
Iterator i1 = i, i2 = i;
|
Iterator i1 = i, i2 = i;
|
||||||
@ -107,8 +148,8 @@ void bidirectional_iterator_test(Iterator i, T v1, T v2)
|
|||||||
--i;
|
--i;
|
||||||
assert(i == i1);
|
assert(i == i1);
|
||||||
assert(i == i2);
|
assert(i == i2);
|
||||||
--i1;
|
++i1;
|
||||||
--i2;
|
++i2;
|
||||||
|
|
||||||
trivial_iterator_test(i, i1, v1);
|
trivial_iterator_test(i, i1, v1);
|
||||||
trivial_iterator_test(i, i2, v1);
|
trivial_iterator_test(i, i2, v1);
|
||||||
|
Reference in New Issue
Block a user