Compare commits

...

15 Commits

Author SHA1 Message Date
nobody
d944c6538f This commit was manufactured by cvs2svn to create tag
'Version_1_21_0'.

[SVN r9525]
2001-03-09 14:58:07 +00:00
Beman Dawes
feb370b201 1.21.0 run up including fixing broken links
[SVN r9523]
2001-03-09 14:36:41 +00:00
Dave Abrahams
d1b34e64d8 Fixes for validator.w3.org
[SVN r9518]
2001-03-09 03:28:13 +00:00
Dave Abrahams
b9a1eead40 Mostly clarification. Fix: changed "category" to "iterator_category" in one place.
[SVN r9517]
2001-03-09 03:10:32 +00:00
Jeremy Siek
1e4bfac98c added named template parameter to table of contents
[SVN r9510]
2001-03-08 21:36:09 +00:00
Jeremy Siek
3bb504fbf3 added revision history line
[SVN r9506]
2001-03-08 20:50:14 +00:00
Jeremy Siek
5029791c90 split off indirect and transform tests into separate files
[SVN r9505]
2001-03-08 20:49:05 +00:00
Beman Dawes
a1a68f0970 1.21.0 run up
[SVN r9502]
2001-03-08 20:35:52 +00:00
Jeremy Siek
f8543d79eb added more static asserts
[SVN r9500]
2001-03-08 20:02:00 +00:00
Jeremy Siek
f353415136 added docs for iterator_traits_generator
[SVN r9498]
2001-03-08 19:19:46 +00:00
Jeremy Siek
26240403b0 added a test to make sure that the type set by the generator is really the
type used


[SVN r9497]
2001-03-08 19:04:29 +00:00
Jeremy Siek
3a39729b58 new file
[SVN r9488]
2001-03-08 16:33:40 +00:00
Dave Abrahams
096c961d9a Patches for Intel C++
[SVN r9425]
2001-03-04 16:08:20 +00:00
Dave Abrahams
01fe04a6a2 Workaround for Borland
[SVN r9424]
2001-03-04 16:07:11 +00:00
John Maddock
7ea4014993 Misc fixes that missed the last commit..
[SVN r9402]
2001-03-04 11:08:29 +00:00
14 changed files with 407 additions and 187 deletions

View File

@@ -117,13 +117,14 @@ void call_traits_checker<T>::operator()(param_type p)
assert(t == c.value()); assert(t == c.value());
assert(t == c.get()); assert(t == c.get());
assert(t == c.const_get()); assert(t == c.const_get());
#ifndef __ICL
//cout << "typeof contained<" << typeid(T).name() << ">::v_ is: " << typeid(&contained<T>::v_).name() << endl; //cout << "typeof contained<" << typeid(T).name() << ">::v_ is: " << typeid(&contained<T>::v_).name() << endl;
cout << "typeof contained<" << typeid(T).name() << ">::value() is: " << typeid(&contained<T>::value).name() << endl; cout << "typeof contained<" << typeid(T).name() << ">::value() is: " << typeid(&contained<T>::value).name() << endl;
cout << "typeof contained<" << typeid(T).name() << ">::get() is: " << typeid(&contained<T>::get).name() << endl; cout << "typeof contained<" << typeid(T).name() << ">::get() is: " << typeid(&contained<T>::get).name() << endl;
cout << "typeof contained<" << typeid(T).name() << ">::const_get() is: " << typeid(&contained<T>::const_get).name() << endl; cout << "typeof contained<" << typeid(T).name() << ">::const_get() is: " << typeid(&contained<T>::const_get).name() << endl;
cout << "typeof contained<" << typeid(T).name() << ">::call() is: " << typeid(&contained<T>::call).name() << endl; cout << "typeof contained<" << typeid(T).name() << ">::call() is: " << typeid(&contained<T>::call).name() << endl;
cout << endl; cout << endl;
#endif
} }
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
@@ -373,3 +374,4 @@ unsigned int expected_failures = 0;
#endif #endif

View File

@@ -308,7 +308,7 @@ implementation, the <tt>difference_type</tt> for any variable-length signed
integer type <tt>T</tt> is <tt>T</tt> itself. integer type <tt>T</tt> is <tt>T</tt> itself.
<hr> <hr>
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->26 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14386" --></p> <p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->28 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14390" --></p>
<p><EFBFBD> Copyright Jeremy Siek 2000. Permission to copy, use, <p><EFBFBD> Copyright Jeremy Siek 2000. Permission to copy, use,
modify, sell and distribute this document is granted provided this copyright modify, sell and distribute this document is granted provided this copyright
notice appears in all copies. This document is provided &quot;as is&quot; notice appears in all copies. This document is provided &quot;as is&quot;

View File

@@ -168,8 +168,8 @@ this parameter is the appropriate type.<br>
The filter iterator adaptor (the type The filter iterator adaptor (the type
<tt>filter_iterator_generator<...>::type</tt>) may be a model of <a <tt>filter_iterator_generator<...>::type</tt>) may be a model of <a
href="www.sgi.com/tech/stl/InputIterator.html">InputIterator</a> or <a href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a> or <a
href="www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a> href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>
depending on the adapted iterator type. depending on the adapted iterator type.
@@ -261,7 +261,7 @@ default).
<hr> <hr>
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->18 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14389" --></p> <p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->09 Mar 2001<!--webbot bot="Timestamp" endspan i-checksum="14894" --></p>
<p><EFBFBD> Copyright Jeremy Siek 2000. Permission to copy, use, <p><EFBFBD> Copyright Jeremy Siek 2000. Permission to copy, use,
modify, sell and distribute this document is granted provided this copyright modify, sell and distribute this document is granted provided this copyright
notice appears in all copies. This document is provided &quot;as is&quot; notice appears in all copies. This document is provided &quot;as is&quot;

View File

@@ -422,7 +422,7 @@ a,b,c,d,e,f,g,
<hr> <hr>
<p>Revised <p>Revised
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->18 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14389" --> <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->28 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14390" -->
<p>&copy; Copyright Jeremy Siek and David Abrahams 2001. Permission to <p>&copy; Copyright Jeremy Siek and David Abrahams 2001. Permission to

151
indirect_iterator_test.cpp Normal file
View File

@@ -0,0 +1,151 @@
// (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.
// Revision History
// 08 Mar 2001 Jeremy Siek
// Moved test of indirect iterator into its own file. It to
// to be in iterator_adaptor_test.cpp.
#include <boost/config.hpp>
#include <iostream>
#include <algorithm>
#include <boost/iterator_adaptors.hpp>
#include <boost/pending/iterator_tests.hpp>
#include <boost/concept_archetype.hpp>
#include <stdlib.h>
#include <deque>
#include <set>
struct my_iterator_tag : public std::random_access_iterator_tag { };
using boost::dummyT;
typedef std::deque<int> storage;
typedef std::deque<int*> pointer_deque;
typedef std::set<storage::iterator> iterator_set;
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
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
, int
#endif
> IndirectDeque;
IndirectDeque::iterator db(ptr_deque.begin());
IndirectDeque::iterator de(ptr_deque.end());
assert(static_cast<std::size_t>(de - db) == store.size());
assert(db + store.size() == de);
IndirectDeque::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);
// Borland C++ is getting very confused about the typedef's here
typedef boost::indirect_iterator_generator<
iterator_set::iterator
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
, int
#endif
>::type indirect_set_iterator;
typedef boost::indirect_iterator_generator<
iterator_set::iterator,
const int
>::type const_indirect_set_iterator;
indirect_set_iterator sb(iter_set.begin());
indirect_set_iterator se(iter_set.end());
const_indirect_set_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
main()
{
dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),
dummyT(3), dummyT(4), dummyT(5) };
const int N = sizeof(array)/sizeof(dummyT);
// Test indirect_iterator_generator
{
dummyT* ptr[N];
for (int k = 0; k < N; ++k)
ptr[k] = array + k;
typedef boost::indirect_iterator_generator<dummyT**
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
, dummyT
#endif
>::type indirect_iterator;
typedef boost::indirect_iterator_generator<dummyT**, const dummyT>::type const_indirect_iterator;
indirect_iterator i(ptr);
boost::random_access_iterator_test(i, N, array);
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
boost::random_access_iterator_test(boost::make_indirect_iterator(ptr), N, array);
#endif
// check operator->
assert((*i).m_x == i->foo());
const_indirect_iterator j(ptr);
boost::random_access_iterator_test(j, N, array);
dummyT*const* const_ptr = ptr;
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
boost::random_access_iterator_test(boost::make_indirect_iterator(const_ptr), N, array);
#endif
boost::const_nonconst_iterator_test(i, ++j);
more_indirect_iterator_tests();
}
std::cout << "test successful " << std::endl;
return 0;
}

61
iter_traits_gen_test.cpp Normal file
View File

@@ -0,0 +1,61 @@
// (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.
// 8 Mar 2001 Jeremy Siek
// Initial checkin.
#include <boost/iterator_adaptors.hpp>
#include <boost/pending/iterator_tests.hpp>
#include <boost/static_assert.hpp>
class bar { };
void foo(bar) { }
int
main()
{
using boost::dummyT;
dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),
dummyT(3), dummyT(4), dummyT(5) };
typedef boost::iterator_adaptor<dummyT*,
boost::default_iterator_policies, dummyT> my_iter;
my_iter mi(array);
{
typedef boost::iterator_adaptor<my_iter, boost::default_iterator_policies,
boost::iterator_traits_generator
::reference<dummyT>
::iterator_category<std::input_iterator_tag> > iter_type;
BOOST_STATIC_ASSERT((boost::is_same<iter_type::iterator_category*,
std::input_iterator_tag*>::value));
BOOST_STATIC_ASSERT(( ! boost::is_convertible<iter_type::iterator_category*,
std::forward_iterator_tag*>::value));
iter_type i(mi);
boost::input_iterator_test(i, dummyT(0), dummyT(1));
}
{
typedef boost::iterator_adaptor<dummyT*,
boost::default_iterator_policies,
boost::iterator_traits_generator
::value_type<dummyT>
::reference<const dummyT&>
::pointer<const dummyT*>
::iterator_category<std::forward_iterator_tag>
::difference_type<std::ptrdiff_t> > adaptor_type;
adaptor_type i(array);
boost::input_iterator_test(i, dummyT(0), dummyT(1));
int zero = 0;
if (zero) // don't do this, just make sure it compiles
assert((*i).m_x == i->foo());
}
return 0;
}

View File

@@ -1,4 +1,4 @@
// Demonstrate and test boost/operators.hpp on std::iterators -------------// // Test boost/iterator_adaptors.hpp
// (C) Copyright Jeremy Siek 1999. Permission to copy, use, modify, // (C) Copyright Jeremy Siek 1999. Permission to copy, use, modify,
// sell and distribute this software is granted provided this // sell and distribute this software is granted provided this
@@ -9,6 +9,8 @@
// 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
// 08 Mar 01 Moved indirect and transform tests to separate files.
// (Jeremy Siek)
// 19 Feb 01 Take adavantage of improved iterator_traits to do more tests // 19 Feb 01 Take adavantage of improved iterator_traits to do more tests
// on MSVC. Hack around an MSVC-with-STLport internal compiler // on MSVC. Hack around an MSVC-with-STLport internal compiler
// error. (David Abrahams) // error. (David Abrahams)
@@ -59,28 +61,6 @@ struct my_iterator_tag : public std::random_access_iterator_tag { };
using boost::dummyT; using boost::dummyT;
struct my_iter_traits {
typedef dummyT value_type;
typedef dummyT* pointer;
typedef dummyT& reference;
typedef my_iterator_tag iterator_category;
typedef std::ptrdiff_t difference_type;
};
struct my_const_iter_traits {
typedef dummyT value_type;
typedef const dummyT* pointer;
typedef const dummyT& reference;
typedef my_iterator_tag iterator_category;
typedef std::ptrdiff_t difference_type;
};
typedef boost::iterator_adaptor<dummyT*,
boost::default_iterator_policies, dummyT> my_iterator;
typedef boost::iterator_adaptor<const dummyT*,
boost::default_iterator_policies, const dummyT> const_my_iterator;
struct mult_functor { struct mult_functor {
typedef int result_type; typedef int result_type;
@@ -117,78 +97,6 @@ typedef std::deque<int> storage;
typedef std::deque<int*> pointer_deque; typedef std::deque<int*> pointer_deque;
typedef std::set<storage::iterator> iterator_set; typedef std::set<storage::iterator> iterator_set;
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
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
, int
#endif
> IndirectDeque;
IndirectDeque::iterator db(ptr_deque.begin());
IndirectDeque::iterator de(ptr_deque.end());
assert(static_cast<std::size_t>(de - db) == store.size());
assert(db + store.size() == de);
IndirectDeque::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_generator<
iterator_set::iterator
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
, int
#endif
>::type indirect_set_iterator;
typedef boost::indirect_iterator_generator<
iterator_set::iterator,
const int
>::type const_indirect_set_iterator;
indirect_set_iterator sb(iter_set.begin());
indirect_set_iterator se(iter_set.end());
const_indirect_set_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()
{ {
@@ -210,67 +118,14 @@ main()
// Test the iterator_adaptor // Test the iterator_adaptor
{ {
my_iterator i(array); boost::iterator_adaptor<dummyT*, boost::default_iterator_policies, dummyT> i(array);
boost::random_access_iterator_test(i, N, array); boost::random_access_iterator_test(i, N, array);
const_my_iterator j(array); boost::iterator_adaptor<const dummyT*, boost::default_iterator_policies, const dummyT> j(array);
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);
} }
// Test transform_iterator
{
int x[N], y[N];
for (int k = 0; k < N; ++k)
x[k] = k;
std::copy(x, x + N, y);
for (int k2 = 0; k2 < N; ++k2)
x[k2] = x[k2] * 2;
boost::transform_iterator_generator<mult_functor, int*>::type
i(y, mult_functor(2));
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_iterator_generator
{
dummyT* ptr[N];
for (int k = 0; k < N; ++k)
ptr[k] = array + k;
typedef boost::indirect_iterator_generator<dummyT**
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
, dummyT
#endif
>::type indirect_iterator;
typedef boost::indirect_iterator_generator<dummyT**, const dummyT>::type const_indirect_iterator;
indirect_iterator i(ptr);
boost::random_access_iterator_test(i, N, array);
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
boost::random_access_iterator_test(boost::make_indirect_iterator(ptr), N, array);
#endif
// check operator->
assert((*i).m_x == i->foo());
const_indirect_iterator j(ptr);
boost::random_access_iterator_test(j, N, array);
dummyT*const* const_ptr = ptr;
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
boost::random_access_iterator_test(boost::make_indirect_iterator(const_ptr), N, array);
#endif
boost::const_nonconst_iterator_test(i, ++j);
more_indirect_iterator_tests();
}
// Test projection_iterator_pair_generator // Test projection_iterator_pair_generator
{ {
typedef std::pair<dummyT,dummyT> Pair; typedef std::pair<dummyT,dummyT> Pair;
@@ -376,23 +231,33 @@ main()
// Test filter iterator // Test filter iterator
{ {
// Using typedefs for filter_gen::type and filter_gen::policies_type // Using typedefs for filter_gen::type confused Borland terribly.
// confused Borland terribly.
typedef boost::detail::non_bidirectional_category<dummyT*>::type category; typedef boost::detail::non_bidirectional_category<dummyT*>::type category;
typedef ::boost::filter_iterator_generator<one_or_four, dummyT* typedef boost::filter_iterator_generator<one_or_four, dummyT*
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
, dummyT , dummyT
#endif #endif
>::type filter_iter; >::type filter_iter;
#if defined(__BORLANDC__)
// Borland is choking on accessing the policies_type explicitly
// from the filter_iter.
boost::forward_iterator_test(make_filter_iterator(array, array+N,
one_or_four()),
dummyT(1), dummyT(4));
#else
filter_iter i(array, filter_iter::policies_type(one_or_four(), array + N)); filter_iter i(array, filter_iter::policies_type(one_or_four(), array + N));
boost::forward_iterator_test(i, dummyT(1), dummyT(4)); boost::forward_iterator_test(i, dummyT(1), dummyT(4));
#endif
#if !defined(__BORLANDC__)
//
enum { is_forward = boost::is_same< enum { is_forward = boost::is_same<
filter_iter::iterator_category, filter_iter::iterator_category,
std::forward_iterator_tag>::value }; std::forward_iterator_tag>::value };
BOOST_STATIC_ASSERT(is_forward); BOOST_STATIC_ASSERT(is_forward);
#endif
// On compilers not supporting partial specialization, we can do more type // On compilers not supporting partial specialization, we can do more type
// deduction with deque iterators than with pointers... unless the library // deduction with deque iterators than with pointers... unless the library
@@ -433,12 +298,24 @@ main()
// check operator-> with a forward iterator // check operator-> with a forward iterator
{ {
boost::forward_iterator_archetype<dummyT> forward_iter; boost::forward_iterator_archetype<dummyT> forward_iter;
#if defined(__BORLANDC__)
typedef boost::iterator_adaptor<boost::forward_iterator_archetype<dummyT>, typedef boost::iterator_adaptor<boost::forward_iterator_archetype<dummyT>,
boost::default_iterator_policies, boost::default_iterator_policies,
dummyT, const dummyT&, const dummyT*, dummyT, const dummyT&, const dummyT*,
std::forward_iterator_tag, std::ptrdiff_t> adaptor_type; std::forward_iterator_tag, std::ptrdiff_t> adaptor_type;
#else
typedef boost::iterator_adaptor<boost::forward_iterator_archetype<dummyT>,
boost::default_iterator_policies,
boost::iterator_traits_generator
::value_type<dummyT>
::reference<const dummyT&>
::pointer<const dummyT*>
::iterator_category<std::forward_iterator_tag>
::difference_type<std::ptrdiff_t> > adaptor_type;
#endif
adaptor_type i(forward_iter); adaptor_type i(forward_iter);
if (0) // don't do this, just make sure it compiles int zero = 0;
if (zero) // don't do this, just make sure it compiles
assert((*i).m_x == i->foo()); assert((*i).m_x == i->foo());
} }
// check operator-> with an input iterator // check operator-> with an input iterator
@@ -449,10 +326,10 @@ main()
dummyT, const dummyT&, const dummyT*, dummyT, const dummyT&, const dummyT*,
std::input_iterator_tag, std::ptrdiff_t> adaptor_type; std::input_iterator_tag, std::ptrdiff_t> adaptor_type;
adaptor_type i(input_iter); adaptor_type i(input_iter);
if (0) // don't do this, just make sure it compiles int zero = 0;
if (zero) // don't do this, just make sure it compiles
assert((*i).m_x == i->foo()); assert((*i).m_x == i->foo());
} }
std::cout << "test successful " << std::endl; std::cout << "test successful " << std::endl;
return 0; return 0;
} }

View File

@@ -44,6 +44,8 @@
<li><a href="#template_parameters">Template Parameters</a> <li><a href="#template_parameters">Template Parameters</a>
<li><a href="#named_template_parameters">Named Template Parameters</a>
<li><a href="#policies">The Policies Class</a> <li><a href="#policies">The Policies Class</a>
<li><a href="#additional_members">Additional Class Members</a> <li><a href="#additional_members">Additional Class Members</a>
@@ -63,7 +65,7 @@
</ul> </ul>
<li> <li>
Specialized Iterator Adaptors <a name="specialized_adaptors">Specialized Iterator Adaptors</a>
<ul> <ul>
<li><a href="indirect_iterator.htm">Indirect Iterator Adaptor</a> <li><a href="indirect_iterator.htm">Indirect Iterator Adaptor</a>
@@ -129,11 +131,11 @@
<p><tt>iterator_adaptor</tt> is declared like this: <p><tt>iterator_adaptor</tt> is declared like this:
<pre> <pre>
template &lt;class Base, class Policies, template &lt;class Base, class Policies,
class Value = typename std::iterator_traits&lt;Base&gt;::value_type, class ValueOrNamedParams = typename std::iterator_traits&lt;Base&gt;::value_type,
class Reference = <i>...(see below)</i>, class ReferenceOrNamedParams = <i>...(see below)</i>,
class Pointer = <i>...(see below)</i>, class PointerOrNamedParams = <i>...(see below)</i>,
class Category = typename std::iterator_traits&lt;Base&gt;::iterator_category, class CategoryOrNamedParams = typename std::iterator_traits&lt;Base&gt;::iterator_category,
class Distance = typename std::iterator_traits&lt;Base&gt;::difference_type&gt; class DistanceOrNamedParams = typename std::iterator_traits&lt;Base&gt;::difference_type&gt;
struct iterator_adaptor; struct iterator_adaptor;
</pre> </pre>
@@ -203,27 +205,99 @@ struct iterator_adaptor;
<td>The <tt>difference_type</tt> for the resulting iterator.<br> <td>The <tt>difference_type</tt> for the resulting iterator.<br>
<b>Default:</b> <b>Default:</b>
<tt>std::iterator_traits&lt;BaseType&gt;::difference_type</tt> <tt>std::iterator_traits&lt;BaseType&gt;::difference_type</tt>
<tr>
<td><tt>NamedParams</tt>
<td>A list of named template parameters generated using the
<a href="#iterator_traits_generator">
<tt>iterator_traits_generator</tt></a> class (see below).
</table> </table>
<h3><a name="named_template_parameters">Named Template Parameters</a></h3>
With seven template parameters, providing arguments for
<tt>iterator_adaptor</tt> in the correct order can be challenging.
Also, often times one would like to specify the sixth or seventh
template parameter, but use the defaults for the third through
fifth. As a solution to these problems we provide a mechanism for
naming the last five template parameters, and providing them in
any order through the <tt>iterator_traits_generator</tt> class.
<blockquote>
<pre>
<a name="iterator_traits_generator">class iterator_traits_generator</a>
{
public:
template &lt;class Value&gt;
struct value_type : public <i>recursive magic</i> { };
template &lt;class Reference&gt;
struct reference : public <i>recursive magic</i> { };
template &lt;class Pointer&gt;
struct pointer : public <i>recursive magic</i> { };
template &lt;class Distance&gt;
struct difference_type : public <i>recursive magic</i> { };
template &lt;class Category&gt;
struct iterator_category : public <i>recursive magic</i> { };
};
</pre>
</blockquote>
The <tt>iterator_traits_generator</tt> is used to create a list of
of template arguments. For example, suppose you want to set the
<tt>Reference</tt> and <tt>Category</tt> parameters, and use the
defaults for the rest. Then you can use the traits generator as
follows:
<blockquote>
<pre>
iterator_traits_generator::reference&lt;foo&gt;::category&lt;std::input_iterator_tag&gt;
</pre>
</blockquote>
This generated type can then be passed into the <tt>iterator_adaptor</tt>
class to replace any of the last five parameters. If you use the traits
generator in the <i>i</i>th parameter position, then the parameters <i>i</i>
through 7 will use the types specified in the generator. For example, the
following adapts <tt>foo_iterator</tt> to create an <a href=
"http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</a> with
<tt>reference</tt> type <tt>foo</tt>, and whose other traits are determined
according to the defaults described <a href="#template_parameters">above</a>.
<blockquote>
<pre>
iterator_adaptor&lt;foo_iterator, foo_policies,
iterator_traits_generator
::reference&lt;foo&gt;
::iterator_category&lt;std::input_iterator_tag&gt;
&gt;
</pre>
</blockquote>
<h3><a name="policies">The Policies Class</a></h3> <h3><a name="policies">The Policies Class</a></h3>
<p>The main task in using <tt>iterator_adaptor</tt> is creating an <p>The main task in using <tt>iterator_adaptor</tt> is creating an
appropriate <tt>Policies</tt> class. The <tt>Policies</tt> class will appropriate <tt>Policies</tt> class. The <tt>Policies</tt> class will become
become the functional heart of the iterator adaptor, supplying the core the functional heart of the resulting iterator, supplying the core
iterator operations that will determine how your new adaptor class will operations that determine its behavior. The <tt>iterator_adaptor</tt>
behave. The <tt>iterator_adaptor</tt> template defines all of the operators template defines all of the operators required of a <a href=
required of a <a href=
"http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access "http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access
Iterator</a>. Your <tt>Policies</tt> class must implement three, four, or Iterator</a> by dispatching to a <tt>Policies</tt> object. Your
seven of the core iterator operations below depending on the iterator <tt>Policies</tt> class must implement a subset of the core iterator
categories you want it to support.<br> operations below corresponding to the iterator categories you want it to
support.<br>
<br> <br>
<table border="1" summary="iterator_adaptor Policies operations"> <table border="1" summary="iterator_adaptor Policies operations">
<caption> <caption>
<b>Core Iterator Operations</b><br> <b>Core Iterator Operations</b><br>
<tt>T</tt>: iterator type; <tt>p</tt>: object of type T; <tt>n</tt>: <tt>T::size_type</tt>; <tt>x</tt>: <tt>T::difference_type</tt>; <tt>p1</tt>, <tt>p2</tt>: iterators <tt>T</tt>: adapted iterator type; <tt>p</tt>: object of type T; <tt>n</tt>: <tt>T::size_type</tt>; <tt>x</tt>: <tt>T::difference_type</tt>; <tt>p1</tt>, <tt>p2</tt>: iterators
</caption> </caption>
<tr> <tr>
@@ -366,7 +440,8 @@ struct <a name="default_iterator_policies">default_iterator_policies</a>
range of iterators. If we had used concrete types above, we'd have tied the range of iterators. If we had used concrete types above, we'd have tied the
usefulness of <tt>default_iterator_policies</tt> to a particular range of usefulness of <tt>default_iterator_policies</tt> to a particular range of
adapted iterators. If you follow the same pattern with your adapted iterators. If you follow the same pattern with your
<tt>Policies</tt> classes, you may achieve the same sort of reusability. <tt>Policies</tt> classes, you can use them to generate more specialized
adaptors along the lines of <a href="#specialized_adaptors">those supplied by this library</a>.
<h3><a name="additional_members">Additional Members</a></h3> <h3><a name="additional_members">Additional Members</a></h3>
In addition to all of the member functions required of a <a href= In addition to all of the member functions required of a <a href=
@@ -757,7 +832,7 @@ bool operator==(const iterator_adaptor&lt;B1,P,V1,R1,P1,C,D&gt;&amp;,
<hr> <hr>
<p>Revised <p>Revised
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->27 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14388" --> <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->09 Mar 2001<!--webbot bot="Timestamp" endspan i-checksum="14894" -->
<p>&copy; Copyright Dave Abrahams and Jeremy Siek 2001. Permission to copy, <p>&copy; Copyright Dave Abrahams and Jeremy Siek 2001. Permission to copy,
@@ -784,6 +859,5 @@ bool operator==(const iterator_adaptor&lt;B1,P,V1,R1,P1,C,D&gt;&amp;,
<!-- LocalWords: iostream hpp sizeof InputIterator constness ConstIterator <!-- LocalWords: iostream hpp sizeof InputIterator constness ConstIterator
David Abrahams David Abrahams
--> -->
</body>
</html> </html>

View File

@@ -7,6 +7,7 @@
// 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
// 04 Mar 2001 Patches for Intel C++ (Dave Abrahams)
// 19 Feb 2001 Take advantage of improved iterator_traits to do more tests // 19 Feb 2001 Take advantage of improved iterator_traits to do more tests
// on MSVC. Reordered some #ifdefs for coherency. // on MSVC. Reordered some #ifdefs for coherency.
// (David Abrahams) // (David Abrahams)
@@ -153,7 +154,7 @@ input_iterator_test<std::istream_iterator<int>, int, std::ptrdiff_t, int*, int&,
typedef ::std::char_traits<char>::off_type distance; typedef ::std::char_traits<char>::off_type distance;
non_pointer_test<std::ostream_iterator<int>,int, non_pointer_test<std::ostream_iterator<int>,int,
distance,int*,int&,std::output_iterator_tag> ostream_iterator_test; distance,int*,int&,std::output_iterator_tag> ostream_iterator_test;
#elif defined(BOOST_MSVC) && !defined(__SGI_STL_PORT) #elif defined(BOOST_MSVC_STD_ITERATOR)
non_pointer_test<std::ostream_iterator<int>, non_pointer_test<std::ostream_iterator<int>,
int, void, void, void, std::output_iterator_tag> int, void, void, void, std::output_iterator_tag>
ostream_iterator_test; ostream_iterator_test;

View File

@@ -371,7 +371,7 @@ Betty
</pre> </pre>
<hr> <hr>
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->16 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14385" --></p> <p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->28 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14390" --></p>
<p><EFBFBD> Copyright Jeremy Siek 2000. Permission to copy, use, <p><EFBFBD> Copyright Jeremy Siek 2000. Permission to copy, use,
modify, sell and distribute this document is granted provided this copyright modify, sell and distribute this document is granted provided this copyright
notice appears in all copies. This document is provided &quot;as is&quot; notice appears in all copies. This document is provided &quot;as is&quot;

View File

@@ -312,7 +312,7 @@ simply use <tt>reverse_iterator_generator</tt> twice!<br><br>
<p>Revised <p>Revised
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->26 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14386" --> <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->28 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14390" -->
<p>&copy; Copyright Jeremy Siek 2000. Permission to copy, use, modify, sell <p>&copy; Copyright Jeremy Siek 2000. Permission to copy, use, modify, sell

View File

@@ -133,7 +133,7 @@ its argument.</TD>
The transform iterator adaptor (the type The transform iterator adaptor (the type
<tt>transform_iterator_generator<...>::type</tt>) is a model of <a <tt>transform_iterator_generator<...>::type</tt>) is a model of <a
href="www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a><a href="#1">[1]</a>. href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a><a href="#1">[1]</a>.
<h3>Members</h3> <h3>Members</h3>
@@ -203,7 +203,7 @@ iterator always returns by-value.
<hr> <hr>
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->16 Feb 2001<!--webbot bot="Timestamp" endspan i-checksum="14385" --></p> <p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->09 Mar 2001<!--webbot bot="Timestamp" endspan i-checksum="14894" --></p>
<p><EFBFBD> Copyright Jeremy Siek 2000. Permission to copy, use, <p><EFBFBD> Copyright Jeremy Siek 2000. Permission to copy, use,
modify, sell and distribute this document is granted provided this copyright modify, sell and distribute this document is granted provided this copyright
notice appears in all copies. This document is provided &quot;as is&quot; notice appears in all copies. This document is provided &quot;as is&quot;

View File

@@ -0,0 +1,54 @@
// (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.
// Revision History
// 08 Mar 2001 Jeremy Siek
// Moved test of transform iterator into its own file. It to
// to be in iterator_adaptor_test.cpp.
#include <boost/config.hpp>
#include <iostream>
#include <algorithm>
#include <boost/iterator_adaptors.hpp>
#include <boost/pending/iterator_tests.hpp>
struct mult_functor {
typedef int result_type;
typedef int argument_type;
// Functors used with transform_iterator must be
// DefaultConstructible, as the transform_iterator must be
// DefaultConstructible to satisfy the requirements for
// TrivialIterator.
mult_functor() { }
mult_functor(int aa) : a(aa) { }
int operator()(int b) const { return a * b; }
int a;
};
int
main()
{
const int N = 10;
// Borland is getting confused about typedef's and constructors here
// Test transform_iterator
{
int x[N], y[N];
for (int k = 0; k < N; ++k)
x[k] = k;
std::copy(x, x + N, y);
for (int k2 = 0; k2 < N; ++k2)
x[k2] = x[k2] * 2;
boost::transform_iterator_generator<mult_functor, int*>::type i(y, mult_functor(2));
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]);
}
std::cout << "test successful " << std::endl;
return 0;
}

View File

@@ -93,7 +93,7 @@ destructor declarations. He says &quot;Probably this concern is misplaced, becau
noncopyable will be used mostly for classes which own resources and thus have non-trivial destruction semantics.&quot;</p> noncopyable will be used mostly for classes which own resources and thus have non-trivial destruction semantics.&quot;</p>
<hr> <hr>
<p>Revised&nbsp; <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan <p>Revised&nbsp; <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan
-->16 February, 2001<!--webbot bot="Timestamp" endspan i-checksum="40407" -->28 February, 2001<!--webbot bot="Timestamp" endspan i-checksum="40412"
--> -->
</p> </p>
<p><EFBFBD> Copyright boost.org 1999. Permission to copy, use, modify, sell and <p><EFBFBD> Copyright boost.org 1999. Permission to copy, use, modify, sell and