mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 02:44:10 +00:00
Removed now-defaulted template arguments where possible
Updated names to correspond to new generator naming convention. Added a trivial test for make_transform_iterator(). Gave traits for const iterators a mutable value_type, per std. Resurrected my original tests for indirect iterators. [SVN r8995]
This commit is contained in:
parent
087069d215
commit
c503a274b5
@ -9,6 +9,12 @@
|
|||||||
// 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
|
||||||
|
// 06 Feb 01 Removed now-defaulted template arguments where possible
|
||||||
|
// Updated names to correspond to new generator naming convention.
|
||||||
|
// Added a trivial test for make_transform_iterator().
|
||||||
|
// Gave traits for const iterators a mutable value_type, per std.
|
||||||
|
// Resurrected my original tests for indirect iterators.
|
||||||
|
// (David Abrahams)
|
||||||
// 04 Feb 01 Fix for compilers without standard iterator_traits
|
// 04 Feb 01 Fix for compilers without standard iterator_traits
|
||||||
// (David Abrahams)
|
// (David Abrahams)
|
||||||
// 13 Jun 00 Added const version of the iterator tests (Jeremy Siek)
|
// 13 Jun 00 Added const version of the iterator tests (Jeremy Siek)
|
||||||
@ -22,6 +28,10 @@
|
|||||||
#include <boost/iterator_adaptors.hpp>
|
#include <boost/iterator_adaptors.hpp>
|
||||||
#include <boost/pending/iterator_tests.hpp>
|
#include <boost/pending/iterator_tests.hpp>
|
||||||
#include <boost/pending/integer_range.hpp>
|
#include <boost/pending/integer_range.hpp>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <deque>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
struct my_iterator_tag : public std::random_access_iterator_tag { };
|
struct my_iterator_tag : public std::random_access_iterator_tag { };
|
||||||
|
|
||||||
@ -44,7 +54,7 @@ struct my_const_iter_traits {
|
|||||||
typedef std::ptrdiff_t difference_type;
|
typedef std::ptrdiff_t difference_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef boost::iterator_adaptors
|
typedef boost::iterator_adaptor_pair_generator
|
||||||
<dummyT*, const dummyT*,
|
<dummyT*, const dummyT*,
|
||||||
my_iter_traits, my_const_iter_traits> My;
|
my_iter_traits, my_const_iter_traits> My;
|
||||||
|
|
||||||
@ -79,6 +89,86 @@ struct one_or_four {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef std::vector<int> storage;
|
||||||
|
typedef std::deque<int*> pointer_deque;
|
||||||
|
typedef std::set<storage::iterator> iterator_set;
|
||||||
|
|
||||||
|
void indirect_deque_tests(const storage& store, pointer_deque& ptr_deque)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void more_indirect_iterator_tests()
|
||||||
|
{
|
||||||
|
// For some reason all heck breaks loose in the compiler under these conditions.
|
||||||
|
#if !defined(BOOST_MSVC) || !defined(__STL_DEBUG)
|
||||||
|
storage store(1000);
|
||||||
|
std::generate(store.begin(), store.end(), rand);
|
||||||
|
|
||||||
|
pointer_deque ptr_deque;
|
||||||
|
iterator_set iter_set;
|
||||||
|
|
||||||
|
for (storage::iterator p = store.begin(); p != store.end(); ++p)
|
||||||
|
{
|
||||||
|
ptr_deque.push_back(&*p);
|
||||||
|
iter_set.insert(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef boost::indirect_iterator_pair_generator<
|
||||||
|
pointer_deque::iterator,
|
||||||
|
const int*
|
||||||
|
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||||
|
, boost::iterator<std::random_access_iterator_tag,int,std::ptrdiff_t,const int*,const int&>
|
||||||
|
, int*
|
||||||
|
, boost::iterator<std::random_access_iterator_tag,int>
|
||||||
|
#endif
|
||||||
|
> indirect_deque;
|
||||||
|
|
||||||
|
indirect_deque::iterator db(ptr_deque.begin());
|
||||||
|
indirect_deque::iterator de(ptr_deque.end());
|
||||||
|
assert(static_cast<std::size_t>(de - db) == store.size());
|
||||||
|
assert(db + store.size() == de);
|
||||||
|
indirect_deque::const_iterator dci(db);
|
||||||
|
assert(db == dci);
|
||||||
|
assert(dci == db);
|
||||||
|
assert(dci != de);
|
||||||
|
assert(dci < de);
|
||||||
|
assert(dci <= de);
|
||||||
|
assert(de >= dci);
|
||||||
|
assert(de > dci);
|
||||||
|
dci = de;
|
||||||
|
assert(dci == de);
|
||||||
|
|
||||||
|
boost::random_access_iterator_test(db + 1, store.size() - 1, boost::next(store.begin()));
|
||||||
|
|
||||||
|
*db = 999;
|
||||||
|
assert(store.front() == 999);
|
||||||
|
|
||||||
|
typedef boost::indirect_iterator_pair_generator<
|
||||||
|
iterator_set::iterator,
|
||||||
|
storage::const_iterator
|
||||||
|
# ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||||
|
, boost::iterator<std::random_access_iterator_tag,int,std::ptrdiff_t,const int*,const int&>
|
||||||
|
, storage::iterator
|
||||||
|
, boost::iterator<std::random_access_iterator_tag,int>
|
||||||
|
# endif
|
||||||
|
> indirect_set;
|
||||||
|
indirect_set::iterator sb(iter_set.begin());
|
||||||
|
indirect_set::iterator se(iter_set.end());
|
||||||
|
indirect_set::const_iterator sci(iter_set.begin());
|
||||||
|
assert(sci == sb);
|
||||||
|
assert(sci != se);
|
||||||
|
sci = se;
|
||||||
|
assert(sci == se);
|
||||||
|
|
||||||
|
*boost::prior(se) = 888;
|
||||||
|
assert(store.back() == 888);
|
||||||
|
assert(std::equal(sb, se, store.begin()));
|
||||||
|
|
||||||
|
boost::bidirectional_iterator_test(boost::next(sb), store[1], store[2]);
|
||||||
|
assert(std::equal(db, de, store.begin()));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
@ -98,7 +188,7 @@ main()
|
|||||||
int*, int&>
|
int*, int&>
|
||||||
> >();
|
> >();
|
||||||
|
|
||||||
// Test the iterator_adaptors
|
// Test the iterator_adaptor_pair_generator
|
||||||
{
|
{
|
||||||
My::iterator i = array;
|
My::iterator i = array;
|
||||||
boost::random_access_iterator_test(i, N, array);
|
boost::random_access_iterator_test(i, N, array);
|
||||||
@ -117,20 +207,24 @@ main()
|
|||||||
for (int k2 = 0; k2 < N; ++k2)
|
for (int k2 = 0; k2 < N; ++k2)
|
||||||
x[k2] = x[k2] * 2;
|
x[k2] = x[k2] * 2;
|
||||||
|
|
||||||
boost::transform_iterator<mult_functor, int*,
|
boost::transform_iterator_generator<mult_functor, int*>::type
|
||||||
boost::iterator<std::random_access_iterator_tag,int> >::type
|
|
||||||
i(y, mult_functor(2));
|
i(y, mult_functor(2));
|
||||||
boost::input_iterator_test(i, x[0], x[1]);
|
boost::input_iterator_test(i, x[0], x[1]);
|
||||||
|
boost::input_iterator_test(boost::make_transform_iterator(&y[0], mult_functor(2)), x[0], x[1]);
|
||||||
}
|
}
|
||||||
// Test indirect_iterators
|
|
||||||
|
// Test indirect_iterator_pair_generator
|
||||||
{
|
{
|
||||||
dummyT* ptr[N];
|
dummyT* ptr[N];
|
||||||
for (int k = 0; k < N; ++k)
|
for (int k = 0; k < N; ++k)
|
||||||
ptr[k] = array + k;
|
ptr[k] = array + k;
|
||||||
typedef boost::indirect_iterators<dummyT**, dummyT*, const dummyT*,
|
|
||||||
boost::iterator<std::random_access_iterator_tag, dummyT*>,
|
typedef boost::indirect_iterator_pair_generator<dummyT**, const dummyT*
|
||||||
boost::iterator<std::random_access_iterator_tag, dummyT>,
|
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||||
boost::iterator<std::random_access_iterator_tag, const dummyT>
|
, boost::iterator<std::random_access_iterator_tag,dummyT,std::ptrdiff_t,const dummyT*,const dummyT&>
|
||||||
|
, dummyT*
|
||||||
|
, boost::iterator<std::random_access_iterator_tag,dummyT>
|
||||||
|
#endif
|
||||||
> Indirect;
|
> Indirect;
|
||||||
Indirect::iterator i = ptr;
|
Indirect::iterator i = ptr;
|
||||||
boost::random_access_iterator_test(i, N, array);
|
boost::random_access_iterator_test(i, N, array);
|
||||||
@ -138,19 +232,21 @@ main()
|
|||||||
Indirect::const_iterator j = ptr;
|
Indirect::const_iterator j = ptr;
|
||||||
boost::random_access_iterator_test(j, N, array);
|
boost::random_access_iterator_test(j, N, array);
|
||||||
|
|
||||||
boost::const_nonconst_iterator_test(i, ++j);
|
boost::const_nonconst_iterator_test(i, ++j);
|
||||||
|
|
||||||
|
|
||||||
|
more_indirect_iterator_tests();
|
||||||
}
|
}
|
||||||
// Test projection_iterators
|
|
||||||
|
// Test projection_iterator_pair_generator
|
||||||
{
|
{
|
||||||
typedef std::pair<dummyT,dummyT> Pair;
|
typedef std::pair<dummyT,dummyT> Pair;
|
||||||
Pair pair_array[N];
|
Pair pair_array[N];
|
||||||
for (int k = 0; k < N; ++k)
|
for (int k = 0; k < N; ++k)
|
||||||
pair_array[k].first = array[k];
|
pair_array[k].first = array[k];
|
||||||
|
|
||||||
typedef boost::projection_iterators<select1st_<Pair>,
|
typedef boost::projection_iterator_pair_generator<select1st_<Pair>,
|
||||||
Pair*, const Pair*,
|
Pair*, const Pair*
|
||||||
boost::iterator<std::random_access_iterator_tag, Pair>,
|
|
||||||
boost::iterator<std::random_access_iterator_tag, const Pair>
|
|
||||||
> Projection;
|
> Projection;
|
||||||
|
|
||||||
Projection::iterator i = pair_array;
|
Projection::iterator i = pair_array;
|
||||||
@ -161,13 +257,13 @@ main()
|
|||||||
|
|
||||||
boost::const_nonconst_iterator_test(i, ++j);
|
boost::const_nonconst_iterator_test(i, ++j);
|
||||||
}
|
}
|
||||||
// Test reverse_iterators
|
// Test reverse_iterator_pair_generator
|
||||||
{
|
{
|
||||||
dummyT reversed[N];
|
dummyT reversed[N];
|
||||||
std::copy(array, array + N, reversed);
|
std::copy(array, array + N, reversed);
|
||||||
std::reverse(reversed, reversed + N);
|
std::reverse(reversed, reversed + N);
|
||||||
|
|
||||||
typedef boost::reverse_iterators<dummyT*, const dummyT*,
|
typedef boost::reverse_iterator_pair_generator<dummyT*, const dummyT*,
|
||||||
boost::iterator<std::random_access_iterator_tag,dummyT>,
|
boost::iterator<std::random_access_iterator_tag,dummyT>,
|
||||||
boost::iterator<std::random_access_iterator_tag,const dummyT>
|
boost::iterator<std::random_access_iterator_tag,const dummyT>
|
||||||
> Reverse;
|
> Reverse;
|
||||||
@ -189,7 +285,7 @@ main()
|
|||||||
|
|
||||||
// Test filter iterator
|
// Test filter iterator
|
||||||
{
|
{
|
||||||
typedef boost::filter_iterator<one_or_four, dummyT*,
|
typedef boost::filter_iterator_generator<one_or_four, dummyT*,
|
||||||
boost::iterator<std::forward_iterator_tag, dummyT, std::ptrdiff_t,
|
boost::iterator<std::forward_iterator_tag, dummyT, std::ptrdiff_t,
|
||||||
dummyT*, dummyT&> >::type FilterIter;
|
dummyT*, dummyT&> >::type FilterIter;
|
||||||
FilterIter i(array);
|
FilterIter i(array);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user