forked from boostorg/utility
Join ralf_grosse_kunstleve with HEAD
[SVN r9444]
This commit is contained in:
@ -6,9 +6,24 @@
|
|||||||
// See http://www.boost.org for most recent version including documentation.
|
// See http://www.boost.org for most recent version including documentation.
|
||||||
//
|
//
|
||||||
// Revision History
|
// Revision History
|
||||||
|
// 16 Feb 2001 Added a missing const. Made the tests run (somewhat) with
|
||||||
|
// plain MSVC again. (David Abrahams)
|
||||||
|
// 11 Feb 2001 #if 0'd out use of counting_iterator on non-numeric types in
|
||||||
|
// MSVC without STLport, so that the other tests may proceed
|
||||||
|
// (David Abrahams)
|
||||||
|
// 04 Feb 2001 Added use of iterator_tests.hpp (David Abrahams)
|
||||||
|
// 28 Jan 2001 Removed not_an_iterator detritus (David Abrahams)
|
||||||
// 24 Jan 2001 Initial revision (David Abrahams)
|
// 24 Jan 2001 Initial revision (David Abrahams)
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#ifdef BOOST_MSVC
|
||||||
|
# pragma warning(disable:4786) // identifier truncated in debug info
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <boost/pending/iterator_tests.hpp>
|
||||||
#include <boost/counting_iterator.hpp>
|
#include <boost/counting_iterator.hpp>
|
||||||
#include <boost/detail/iterator.hpp>
|
#include <boost/detail/iterator.hpp>
|
||||||
|
#include <iostream>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -37,8 +52,6 @@ template <class T> struct is_numeric
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct not_an_iterator_tag {};
|
|
||||||
|
|
||||||
// Special tests for RandomAccess CountingIterators.
|
// Special tests for RandomAccess CountingIterators.
|
||||||
template <class CountingIterator>
|
template <class CountingIterator>
|
||||||
void category_test(
|
void category_test(
|
||||||
@ -65,12 +78,39 @@ void category_test(
|
|||||||
|
|
||||||
// Show that values outside the range can't be found
|
// Show that values outside the range can't be found
|
||||||
assert(!std::binary_search(start, boost::prior(finish), *finish));
|
assert(!std::binary_search(start, boost::prior(finish), *finish));
|
||||||
|
|
||||||
|
// Do the generic random_access_iterator_test
|
||||||
|
typedef typename CountingIterator::value_type value_type;
|
||||||
|
std::vector<value_type> v;
|
||||||
|
for (value_type z = *start; z != *finish; ++z)
|
||||||
|
v.push_back(z);
|
||||||
|
if (v.size() >= 2)
|
||||||
|
{
|
||||||
|
// Note that this test requires a that the first argument is
|
||||||
|
// dereferenceable /and/ a valid iterator prior to the first argument
|
||||||
|
boost::random_access_iterator_test(start + 1, v.size() - 1, v.begin() + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we'll have to skip those.
|
// Special tests for bidirectional CountingIterators
|
||||||
template <class CountingIterator>
|
template <class CountingIterator>
|
||||||
void category_test(CountingIterator, CountingIterator, std::forward_iterator_tag)
|
void category_test(CountingIterator start, CountingIterator finish, std::bidirectional_iterator_tag)
|
||||||
{
|
{
|
||||||
|
if (finish != start
|
||||||
|
&& finish != boost::next(start)
|
||||||
|
&& finish != boost::next(boost::next(start)))
|
||||||
|
{
|
||||||
|
// Note that this test requires a that the first argument is
|
||||||
|
// dereferenceable /and/ a valid iterator prior to the first argument
|
||||||
|
boost::bidirectional_iterator_test(boost::next(start), boost::next(*start), boost::next(boost::next(*start)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class CountingIterator>
|
||||||
|
void category_test(CountingIterator start, CountingIterator finish, std::forward_iterator_tag)
|
||||||
|
{
|
||||||
|
if (finish != start && finish != boost::next(start))
|
||||||
|
boost::forward_iterator_test(start, *start, boost::next(*start));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class CountingIterator>
|
template <class CountingIterator>
|
||||||
@ -97,7 +137,7 @@ void test_aux(CountingIterator start, CountingIterator finish)
|
|||||||
template <class Incrementable>
|
template <class Incrementable>
|
||||||
void test(Incrementable start, Incrementable finish)
|
void test(Incrementable start, Incrementable finish)
|
||||||
{
|
{
|
||||||
test_aux(boost::counting_iterator(start), boost::counting_iterator(finish));
|
test_aux(boost::make_counting_iterator(start), boost::make_counting_iterator(finish));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Integer>
|
template <class Integer>
|
||||||
@ -121,10 +161,66 @@ void test_container(Container* = 0) // default arg works around MSVC bug
|
|||||||
|
|
||||||
test(start, finish);
|
test(start, finish);
|
||||||
|
|
||||||
test(static_cast<typename Container::const_iterator>(start),
|
typedef typename Container::const_iterator const_iterator;
|
||||||
static_cast<typename Container::const_iterator>(finish));
|
test(const_iterator(start), const_iterator(finish));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class my_int1 {
|
||||||
|
public:
|
||||||
|
my_int1() { }
|
||||||
|
my_int1(int x) : m_int(x) { }
|
||||||
|
my_int1& operator++() { ++m_int; return *this; }
|
||||||
|
bool operator==(const my_int1& x) const { return m_int == x.m_int; }
|
||||||
|
private:
|
||||||
|
int m_int;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
template <>
|
||||||
|
struct counting_iterator_traits<my_int1> {
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
typedef std::forward_iterator_tag iterator_category;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class my_int2 {
|
||||||
|
public:
|
||||||
|
typedef void value_type;
|
||||||
|
typedef void pointer;
|
||||||
|
typedef void reference;
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
typedef std::bidirectional_iterator_tag iterator_category;
|
||||||
|
|
||||||
|
my_int2() { }
|
||||||
|
my_int2(int x) : m_int(x) { }
|
||||||
|
my_int2& operator++() { ++m_int; return *this; }
|
||||||
|
my_int2& operator--() { --m_int; return *this; }
|
||||||
|
bool operator==(const my_int2& x) const { return m_int == x.m_int; }
|
||||||
|
private:
|
||||||
|
int m_int;
|
||||||
|
};
|
||||||
|
|
||||||
|
class my_int3 {
|
||||||
|
public:
|
||||||
|
typedef void value_type;
|
||||||
|
typedef void pointer;
|
||||||
|
typedef void reference;
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
typedef std::random_access_iterator_tag iterator_category;
|
||||||
|
|
||||||
|
my_int3() { }
|
||||||
|
my_int3(int x) : m_int(x) { }
|
||||||
|
my_int3& operator++() { ++m_int; return *this; }
|
||||||
|
my_int3& operator+=(std::ptrdiff_t n) { m_int += n; return *this; }
|
||||||
|
std::ptrdiff_t operator-(const my_int3& x) const { return m_int - x.m_int; }
|
||||||
|
my_int3& operator--() { --m_int; return *this; }
|
||||||
|
bool operator==(const my_int3& x) const { return m_int == x.m_int; }
|
||||||
|
bool operator!=(const my_int3& x) const { return m_int != x.m_int; }
|
||||||
|
bool operator<(const my_int3& x) const { return m_int < x.m_int; }
|
||||||
|
private:
|
||||||
|
int m_int;
|
||||||
|
};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Test the built-in integer types.
|
// Test the built-in integer types.
|
||||||
@ -142,14 +238,26 @@ int main()
|
|||||||
test_integer<long long>();
|
test_integer<long long>();
|
||||||
test_integer<unsigned long long>();
|
test_integer<unsigned long long>();
|
||||||
#endif
|
#endif
|
||||||
// Some tests on container iterators, to prove we handle a few different categories
|
|
||||||
|
// wrapping an iterator or non-built-in integer type causes an INTERNAL
|
||||||
|
// COMPILER ERROR in MSVC without STLport. I'm clueless as to why.
|
||||||
|
#if !defined(BOOST_MSVC) || defined(__SGI_STL_PORT)
|
||||||
|
// Test user-defined type.
|
||||||
|
test_integer<my_int1>();
|
||||||
|
test_integer<my_int2>();
|
||||||
|
test_integer<my_int3>();
|
||||||
|
|
||||||
|
// Some tests on container iterators, to prove we handle a few different categories
|
||||||
test_container<std::vector<int> >();
|
test_container<std::vector<int> >();
|
||||||
test_container<std::list<int> >();
|
test_container<std::list<int> >();
|
||||||
#ifndef BOOST_NO_SLIST
|
# ifndef BOOST_NO_SLIST
|
||||||
test_container<BOOST_STD_EXTENSION_NAMESPACE::slist<int> >();
|
test_container<BOOST_STD_EXTENSION_NAMESPACE::slist<int> >();
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
// Also prove that we can handle raw pointers.
|
// Also prove that we can handle raw pointers.
|
||||||
int array[2000];
|
int array[2000];
|
||||||
test(boost::counting_iterator(array), boost::counting_iterator(array+2000-1));
|
test(boost::make_counting_iterator(array), boost::make_counting_iterator(array+2000-1));
|
||||||
|
#endif
|
||||||
|
std::cout << "test successful " << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -11,15 +11,15 @@
|
|||||||
// Revision History
|
// Revision History
|
||||||
// 21 Jan 01 Initial version (Jeremy Siek)
|
// 21 Jan 01 Initial version (Jeremy Siek)
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
|
#include <list>
|
||||||
#include <boost/pending/iterator_adaptors.hpp>
|
#include <boost/pending/iterator_adaptors.hpp>
|
||||||
#include <boost/detail/iterator.hpp>
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
typedef boost::iterator_adaptor<int*, boost::default_iterator_policies,
|
typedef boost::iterator_adaptor<std::list<int>::iterator,
|
||||||
boost::iterator<std::bidirectional_iterator_tag, int> > adaptor_type;
|
boost::default_iterator_policies,
|
||||||
|
int,int&,int*,std::bidirectional_iterator_tag> adaptor_type;
|
||||||
|
|
||||||
adaptor_type i;
|
adaptor_type i;
|
||||||
i += 4;
|
i += 4;
|
||||||
|
@ -11,16 +11,16 @@
|
|||||||
// Revision History
|
// Revision History
|
||||||
// 21 Jan 01 Initial version (Jeremy Siek)
|
// 21 Jan 01 Initial version (Jeremy Siek)
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <boost/config.hpp>
|
|
||||||
#include <boost/pending/iterator_adaptors.hpp>
|
#include <boost/pending/iterator_adaptors.hpp>
|
||||||
#include <boost/detail/iterator.hpp>
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
typedef boost::iterator_adaptor<int*, boost::default_iterator_policies,
|
typedef boost::iterator_adaptor<std::istream_iterator<int>,
|
||||||
boost::iterator<std::input_iterator_tag, int> > adaptor_type;
|
boost::default_iterator_policies,
|
||||||
|
int,int&,int*,std::input_iterator_tag> adaptor_type;
|
||||||
|
|
||||||
adaptor_type iter;
|
adaptor_type iter;
|
||||||
--iter;
|
--iter;
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
// Test boost/pending/iterator_adaptors.hpp
|
|
||||||
|
|
||||||
// (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.
|
|
||||||
|
|
||||||
// See http://www.boost.org for most recent version including documentation.
|
|
||||||
|
|
||||||
// Revision History
|
|
||||||
// 21 Jan 01 Initial version (Jeremy Siek)
|
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <boost/config.hpp>
|
|
||||||
#include <boost/pending/iterator_adaptors.hpp>
|
|
||||||
#include <boost/detail/iterator.hpp>
|
|
||||||
|
|
||||||
class foo {
|
|
||||||
public:
|
|
||||||
void bar() { }
|
|
||||||
};
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
typedef boost::iterator_adaptor<foo*, boost::default_iterator_policies,
|
|
||||||
boost::iterator<std::input_iterator_tag, foo> > adaptor_type;
|
|
||||||
|
|
||||||
adaptor_type i;
|
|
||||||
i->bar();
|
|
||||||
return 0;
|
|
||||||
}
|
|
Reference in New Issue
Block a user