forked from boostorg/iterator
Compare commits
315 Commits
svn-branch
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
d67deb0f0d | |||
700db48ac7 | |||
2241bb1ae3 | |||
539add7de6 | |||
edb7528136 | |||
254186d6bd | |||
aa62f4f9c7 | |||
f0bc339d55 | |||
2721c3c97e | |||
f49f68c8fe | |||
02f606816d | |||
1ffc31cc37 | |||
0acc6c38ef | |||
da1e5aa3e8 | |||
db0bc36f58 | |||
99bafe363c | |||
b310ccda97 | |||
2a9c00f5b2 | |||
020d0b8f99 | |||
d21781d8d1 | |||
bed1d7fa7a | |||
0c3a68530e | |||
d3daa47561 | |||
62c993978a | |||
74f41dcb5b | |||
c8d1461340 | |||
13dcd5590f | |||
7f125cacb9 | |||
8cf04e1c7b | |||
0122a0c8ec | |||
09549783cc | |||
273c1d784c | |||
a99ab81803 | |||
0cb4ce54ef | |||
0670e05297 | |||
b353d45f2d | |||
19d339c916 | |||
506517191c | |||
b502873f00 | |||
b838d27aa3 | |||
17c373ded3 | |||
09e1cb9a38 | |||
58288cfb48 | |||
cd730895ca | |||
2d2a84f8c4 | |||
4871736269 | |||
fec82e2de8 | |||
a5b14e1a4f | |||
8480d452a9 | |||
5f870d780d | |||
010f715950 | |||
020f2ab867 | |||
2071230859 | |||
413d0b01cf | |||
4abd97910d | |||
564ed3ed88 | |||
c90814e515 | |||
576395a469 | |||
f75a60e074 | |||
3e5f366f4f | |||
a456f8d969 | |||
cfe17e7fe5 | |||
99891db75c | |||
287c7ed0e7 | |||
8bd881070c | |||
9cce6e8052 | |||
b6068667c9 | |||
309f741588 | |||
858e0e0c0b | |||
01fd0c92e3 | |||
23dcc53fed | |||
08cd7bf6e7 | |||
35c14adc12 | |||
3b992521af | |||
646e78dc14 | |||
4a7f6afd6a | |||
8294e14664 | |||
1102c88de7 | |||
c98620a552 | |||
24fcaed649 | |||
2c1eadfea3 | |||
ffe87e904f | |||
fbd5da7237 | |||
ecccc89a70 | |||
2bacc663b1 | |||
c5dc0fbf0e | |||
f358cf3bf4 | |||
6b00e8e0ca | |||
5abf4d7556 | |||
8ca421c140 | |||
1e3da4b77f | |||
7c784ad112 | |||
f72d264b6b | |||
c6526fc609 | |||
3741fa77d2 | |||
ca70d5dee8 | |||
85ad1f59da | |||
73e6736566 | |||
c08cc33394 | |||
8c3ed628dc | |||
792acdb408 | |||
c3fd7076c1 | |||
33f630beca | |||
f1f6262be7 | |||
42147b9e86 | |||
2854c5c761 | |||
731576fbfe | |||
36329b053d | |||
3b93bb25ff | |||
2496402a8c | |||
8a0e9a4fe5 | |||
5049bcdce5 | |||
1c77a5a4ab | |||
9c42ccb0bd | |||
dd50d3f2ab | |||
5f3b97ceff | |||
2d1e40bd20 | |||
a0bb423311 | |||
0f8c236e9d | |||
736044938d | |||
983ba32def | |||
d2dae62215 | |||
9540444061 | |||
482c0cf52b | |||
849f01a0d1 | |||
11770763df | |||
df66940f0f | |||
80f6a13e79 | |||
0f8aa07e5c | |||
6b77e7f8bd | |||
838decca95 | |||
e6c5b80afd | |||
e7b5604ec5 | |||
ea3baba376 | |||
c6a5b7c292 | |||
45e90e0134 | |||
18b1414d6c | |||
7facdd8590 | |||
6cf1230c13 | |||
d70b0d3f05 | |||
527b5e3caa | |||
4e1b53ed36 | |||
eb69638be1 | |||
a5c4497c01 | |||
1033aeb186 | |||
e5d502d2f8 | |||
55e4fe2ab7 | |||
8e2d210d42 | |||
ec8d069057 | |||
2edb688882 | |||
3403cbbae6 | |||
b52b9325ba | |||
1e3b131a84 | |||
250a374e07 | |||
f618d71c0e | |||
3d37ba5120 | |||
e785cc70d1 | |||
3bf52ec2f2 | |||
19dbb5304c | |||
4d13c285ea | |||
08ce6903ce | |||
75e76eb637 | |||
954d12a04d | |||
bcc0e80439 | |||
436f7411f8 | |||
21381f3fa7 | |||
db9d88ad7b | |||
6085e03da0 | |||
b2407b0191 | |||
8181625365 | |||
24052c3dff | |||
c15707fd70 | |||
b4f1b069be | |||
129815f3dd | |||
a7eaa017b1 | |||
6e326921f9 | |||
4a3fd9984d | |||
0074f50573 | |||
ba8dc44eac | |||
b0d3d34fcd | |||
7f0ed4f5be | |||
7fc54ec2d8 | |||
f0add8a043 | |||
5b608e114b | |||
06e1fa88b9 | |||
a6b2a098c1 | |||
4f0684ffac | |||
fbfcf97e18 | |||
45b6a92f61 | |||
c6814925ac | |||
6c114a539d | |||
b6c82968b8 | |||
2271aceab8 | |||
0db07e9455 | |||
f158591054 | |||
1b210355bf | |||
075c341a37 | |||
bab25c04db | |||
2a60dfa087 | |||
ef69c73e89 | |||
bf9534e1ee | |||
0e11bd6a0c | |||
ff10cfd5dc | |||
400f35cbb0 | |||
59340bca4c | |||
6c62f31f0a | |||
dd5fb425fa | |||
c903cf4801 | |||
1c26f7dd43 | |||
c546a3e875 | |||
2183de96a1 | |||
fb1fc6f909 | |||
20b31d1cca | |||
f716d705c5 | |||
1fca93be10 | |||
f96a2b3d81 | |||
a7edd713d8 | |||
bca1c2dea5 | |||
dfad37d0f9 | |||
3376955b80 | |||
e98b130d77 | |||
a450053b0a | |||
0b5b315a7f | |||
5cc31f6539 | |||
f0248daa1e | |||
798562e75b | |||
68e7d3f0d5 | |||
e9bb297ed2 | |||
d5e525dd19 | |||
c326818764 | |||
57ec457f32 | |||
c04b13641f | |||
0bf570c98d | |||
28dfcbd6b0 | |||
9338b11799 | |||
ad5defc9af | |||
81242ad5ae | |||
8997a587e9 | |||
83de27a445 | |||
44d7dfeb9b | |||
84f22cde8d | |||
9387c05d12 | |||
66feb45676 | |||
bdbfcd308e | |||
44757cfcc1 | |||
c1be620888 | |||
36d9a73a60 | |||
f14701232a | |||
296ce3aa89 | |||
1f7c08615f | |||
1b29ec1741 | |||
593311f43e | |||
fe52e0d665 | |||
52e34b2e26 | |||
8cfa950f10 | |||
cc282d81c0 | |||
8c01469b3c | |||
a6ffdb8ebf | |||
2ad29da3b5 | |||
459387273b | |||
09ea8d27e2 | |||
ca1ee306b7 | |||
b63814d3f2 | |||
dfc09c4b26 | |||
f6715137cf | |||
f18906ac6b | |||
522195fd64 | |||
bdc1304326 | |||
633bb0762e | |||
b0b5699a01 | |||
943d2c872b | |||
4ec68b7a0e | |||
e295f71a85 | |||
a8a68dbb7b | |||
8d5717081e | |||
76880f6ce2 | |||
50e645261c | |||
f25ff7a1a4 | |||
104faa5ab3 | |||
4cc5f9a4d6 | |||
7946d32cef | |||
69d8856572 | |||
c055f1afae | |||
cb34b65f3f | |||
f8cd96cb2e | |||
fed5967d9d | |||
81870ac8b6 | |||
6ef3e5d1c7 | |||
dfa751077a | |||
14134e4610 | |||
c7bec1cf56 | |||
e888f18b5a | |||
15abd4c56e | |||
17026cc30d | |||
1c39976ccd | |||
361f62d022 | |||
ebb09db44e | |||
50fe1b062b | |||
30ca43dd08 | |||
ac0c6461fb | |||
d85b8db0aa | |||
a3856b5c60 | |||
20e2818844 | |||
d68ac3db4c | |||
5efcabf3bd | |||
9ac583096c | |||
1710c484b3 | |||
f6cbffeda0 | |||
50ab635593 | |||
d958a5bc82 | |||
5339d7a9d4 | |||
fd29e538ed | |||
1c41a7d0ec | |||
85873e924a | |||
d9b4e41d5a |
57
include/boost/function_output_iterator.hpp
Normal file
57
include/boost/function_output_iterator.hpp
Normal file
@ -0,0 +1,57 @@
|
||||
// (C) Copyright Jeremy Siek 2001. 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:
|
||||
|
||||
// 27 Feb 2001 Jeremy Siek
|
||||
// Initial checkin.
|
||||
|
||||
#ifndef BOOST_FUNCTION_OUTPUT_ITERATOR_HPP
|
||||
#define BOOST_FUNCTION_OUTPUT_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace boost {
|
||||
|
||||
template <class UnaryFunction>
|
||||
class function_output_iterator {
|
||||
typedef function_output_iterator self;
|
||||
public:
|
||||
typedef std::output_iterator_tag iterator_category;
|
||||
typedef void value_type;
|
||||
typedef void difference_type;
|
||||
typedef void pointer;
|
||||
typedef void reference;
|
||||
|
||||
explicit function_output_iterator() {}
|
||||
|
||||
explicit function_output_iterator(const UnaryFunction& f)
|
||||
: m_f(f) {}
|
||||
|
||||
struct output_proxy {
|
||||
output_proxy(UnaryFunction& f) : m_f(f) { }
|
||||
template <class T> output_proxy& operator=(const T& value) {
|
||||
m_f(value);
|
||||
return *this;
|
||||
}
|
||||
UnaryFunction& m_f;
|
||||
};
|
||||
output_proxy operator*() { return output_proxy(m_f); }
|
||||
self& operator++() { return *this; }
|
||||
self& operator++(int) { return *this; }
|
||||
private:
|
||||
UnaryFunction m_f;
|
||||
};
|
||||
|
||||
template <class UnaryFunction>
|
||||
inline function_output_iterator<UnaryFunction>
|
||||
make_function_output_iterator(const UnaryFunction& f = UnaryFunction()) {
|
||||
return function_output_iterator<UnaryFunction>(f);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_FUNCTION_OUTPUT_ITERATOR_HPP
|
426
include/boost/half_open_range.hpp
Normal file
426
include/boost/half_open_range.hpp
Normal file
@ -0,0 +1,426 @@
|
||||
// (C) Copyright Jeremy Siek and David Abrahams 2000-2001. 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:
|
||||
// 11 Feb 2001 Use new iterator_adaptor interface, Fixes for Borland.
|
||||
// (Dave Abrahams)
|
||||
// 04 Feb 2001 Support for user-defined iterator categories (Dave Abrahams)
|
||||
// 30 Jan 2001 Initial Checkin (Dave Abrahams)
|
||||
|
||||
#ifndef BOOST_HALF_OPEN_RANGE_HPP_
|
||||
# define BOOST_HALF_OPEN_RANGE_HPP_
|
||||
|
||||
# include <boost/counting_iterator.hpp>
|
||||
# include <functional>
|
||||
# include <cassert>
|
||||
# include <boost/operators.hpp>
|
||||
# include <string>
|
||||
# include <stdexcept>
|
||||
# include <iterator>
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace detail {
|
||||
|
||||
// Template class choose_finish -- allows us to maintain the invariant that
|
||||
// start() <= finish() on half_open_range specializations that support random
|
||||
// access.
|
||||
#ifdef __MWERKS__
|
||||
template <class T>
|
||||
const T& choose_finish(const T&, const T& finish, std::input_iterator_tag)
|
||||
{
|
||||
return finish;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
const T& choose_finish(const T&, const T& finish, std::output_iterator_tag)
|
||||
{
|
||||
return finish;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
const T& choose_finish(const T& start, const T& finish, std::random_access_iterator_tag)
|
||||
{
|
||||
return finish < start ? start : finish;
|
||||
}
|
||||
#else
|
||||
template <bool is_random_access> struct finish_chooser;
|
||||
|
||||
template <>
|
||||
struct finish_chooser<false>
|
||||
{
|
||||
template <class T>
|
||||
struct rebind
|
||||
{
|
||||
static T choose(const T&, const T& finish)
|
||||
{ return finish; }
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct finish_chooser<true>
|
||||
{
|
||||
template <class T>
|
||||
struct rebind
|
||||
{
|
||||
static T choose(const T& start, const T& finish)
|
||||
{ return finish < start ? start : finish; }
|
||||
};
|
||||
};
|
||||
|
||||
template <class Category, class Incrementable>
|
||||
struct choose_finish
|
||||
{
|
||||
static const Incrementable choose(const Incrementable& start, const Incrementable& finish)
|
||||
{
|
||||
return finish_chooser<(
|
||||
::boost::is_convertible<Category*,std::random_access_iterator_tag*>::value
|
||||
)>::template rebind<Incrementable>::choose(start, finish);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class Incrementable>
|
||||
struct half_open_range
|
||||
{
|
||||
typedef typename counting_iterator_generator<Incrementable>::type iterator;
|
||||
|
||||
private: // utility type definitions
|
||||
// Using iter_t prevents compiler confusion with boost::iterator
|
||||
typedef typename counting_iterator_generator<Incrementable>::type iter_t;
|
||||
|
||||
typedef std::less<Incrementable> less_value;
|
||||
typedef typename iter_t::iterator_category category;
|
||||
typedef half_open_range<Incrementable> self;
|
||||
|
||||
public:
|
||||
typedef iter_t const_iterator;
|
||||
typedef typename iterator::value_type value_type;
|
||||
typedef typename iterator::difference_type difference_type;
|
||||
typedef typename iterator::reference reference;
|
||||
typedef typename iterator::reference const_reference;
|
||||
typedef typename iterator::pointer pointer;
|
||||
typedef typename iterator::pointer const_pointer;
|
||||
|
||||
// It would be nice to select an unsigned type, but this is appropriate
|
||||
// since the library makes an attempt to select a difference_type which can
|
||||
// hold the difference between any two iterators.
|
||||
typedef typename iterator::difference_type size_type;
|
||||
|
||||
half_open_range(Incrementable start, Incrementable finish)
|
||||
: m_start(start),
|
||||
m_finish(
|
||||
#ifndef __MWERKS__
|
||||
detail::choose_finish<category,Incrementable>::choose(start, finish)
|
||||
#else
|
||||
detail::choose_finish(start, finish, category())
|
||||
#endif
|
||||
)
|
||||
{}
|
||||
|
||||
// Implicit conversion from std::pair<Incrementable,Incrementable> allows us
|
||||
// to accept the results of std::equal_range(), for example.
|
||||
half_open_range(const std::pair<Incrementable,Incrementable>& x)
|
||||
: m_start(x.first),
|
||||
m_finish(
|
||||
#ifndef __MWERKS__
|
||||
detail::choose_finish<category,Incrementable>::choose(x.first, x.second)
|
||||
#else
|
||||
detail::choose_finish(x.first, x.second, category())
|
||||
#endif
|
||||
)
|
||||
{}
|
||||
|
||||
half_open_range& operator=(const self& x)
|
||||
{
|
||||
m_start = x.m_start;
|
||||
m_finish = x.m_finish;
|
||||
return *this;
|
||||
}
|
||||
|
||||
half_open_range& operator=(const std::pair<Incrementable,Incrementable>& x)
|
||||
{
|
||||
m_start = x.first;
|
||||
m_finish =
|
||||
#ifndef __MWERKS__
|
||||
detail::choose_finish<category,Incrementable>::choose(x.first, x.second);
|
||||
#else
|
||||
detail::choose_finish(x.first, x.second, category();
|
||||
#endif
|
||||
}
|
||||
|
||||
iterator begin() const { return iterator(m_start); }
|
||||
iterator end() const { return iterator(m_finish); }
|
||||
|
||||
Incrementable front() const { assert(!this->empty()); return m_start; }
|
||||
Incrementable back() const { assert(!this->empty()); return boost::prior(m_finish); }
|
||||
|
||||
Incrementable start() const { return m_start; }
|
||||
Incrementable finish() const { return m_finish; }
|
||||
|
||||
size_type size() const { return boost::detail::distance(begin(), end()); }
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return m_finish == m_start;
|
||||
}
|
||||
|
||||
void swap(half_open_range& x) {
|
||||
std::swap(m_start, x.m_start);
|
||||
std::swap(m_finish, x.m_finish);
|
||||
}
|
||||
|
||||
public: // functions requiring random access elements
|
||||
|
||||
// REQUIRES: x is reachable from this->front()
|
||||
bool contains(const value_type& x) const
|
||||
{
|
||||
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
|
||||
return !less_value()(x, m_start) && less_value()(x, m_finish);
|
||||
}
|
||||
|
||||
bool contains(const half_open_range& x) const
|
||||
{
|
||||
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
|
||||
return x.empty() || !less_value()(x.m_start, m_start) && !less_value()(m_finish, x.m_finish);
|
||||
}
|
||||
|
||||
bool intersects(const half_open_range& x) const
|
||||
{
|
||||
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
|
||||
return less_value()(
|
||||
less_value()(this->m_start, x.m_start) ? x.m_start : this->m_start,
|
||||
less_value()(this->m_finish, x.m_finish) ? this->m_finish : x.m_finish);
|
||||
}
|
||||
|
||||
half_open_range& operator&=(const half_open_range& x)
|
||||
{
|
||||
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
|
||||
|
||||
if (less_value()(this->m_start, x.m_start))
|
||||
this->m_start = x.m_start;
|
||||
|
||||
if (less_value()(x.m_finish, this->m_finish))
|
||||
this->m_finish = x.m_finish;
|
||||
|
||||
if (less_value()(this->m_finish, this->m_start))
|
||||
this->m_start = this->m_finish;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
half_open_range& operator|=(const half_open_range& x)
|
||||
{
|
||||
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
|
||||
|
||||
if (!x.empty())
|
||||
{
|
||||
if (this->empty())
|
||||
{
|
||||
*this = x;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (less_value()(x.m_start, this->m_start))
|
||||
this->m_start = x.m_start;
|
||||
|
||||
if (less_value()(this->m_finish, x.m_finish))
|
||||
this->m_finish = x.m_finish;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// REQUIRES: x is reachable from this->front()
|
||||
const_iterator find(const value_type& x) const
|
||||
{
|
||||
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
|
||||
|
||||
return const_iterator(this->contains(x) ? x : m_finish);
|
||||
}
|
||||
|
||||
// REQUIRES: index >= 0 && index < size()
|
||||
value_type operator[](size_type index) const
|
||||
{
|
||||
assert(index >= 0 && index < size());
|
||||
return m_start + index;
|
||||
}
|
||||
|
||||
value_type at(size_type index) const
|
||||
{
|
||||
if (index < 0 || index >= size())
|
||||
throw std::out_of_range(std::string("half_open_range"));
|
||||
return m_start + index;
|
||||
}
|
||||
|
||||
private: // data members
|
||||
Incrementable m_start, m_finish;
|
||||
};
|
||||
|
||||
template <class Incrementable>
|
||||
half_open_range<Incrementable> operator|(
|
||||
half_open_range<Incrementable> x,
|
||||
const half_open_range<Incrementable>& y)
|
||||
{
|
||||
return x |= y;
|
||||
}
|
||||
|
||||
template <class Incrementable>
|
||||
half_open_range<Incrementable> operator&(
|
||||
half_open_range<Incrementable> x,
|
||||
const half_open_range<Incrementable>& y)
|
||||
{
|
||||
return x &= y;
|
||||
}
|
||||
|
||||
template <class Incrementable>
|
||||
inline bool operator==(
|
||||
const half_open_range<Incrementable>& x,
|
||||
const half_open_range<Incrementable>& y)
|
||||
{
|
||||
const bool y_empty = y.empty();
|
||||
return x.empty() ? y_empty : !y_empty && x.start() == y.start() && x.finish() == y.finish();
|
||||
}
|
||||
|
||||
template <class Incrementable>
|
||||
inline bool operator!=(
|
||||
const half_open_range<Incrementable>& x,
|
||||
const half_open_range<Incrementable>& y)
|
||||
{
|
||||
return !(x == y);
|
||||
}
|
||||
|
||||
template <class Incrementable>
|
||||
inline half_open_range<Incrementable>
|
||||
make_half_open_range(Incrementable first, Incrementable last)
|
||||
{
|
||||
return half_open_range<Incrementable>(first, last);
|
||||
}
|
||||
|
||||
template <class Incrementable>
|
||||
bool intersects(
|
||||
const half_open_range<Incrementable>& x,
|
||||
const half_open_range<Incrementable>& y)
|
||||
{
|
||||
return x.intersects(y);
|
||||
}
|
||||
|
||||
template <class Incrementable>
|
||||
bool contains(
|
||||
const half_open_range<Incrementable>& x,
|
||||
const half_open_range<Incrementable>& y)
|
||||
{
|
||||
return x.contains(y);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
namespace std {
|
||||
template <class Incrementable> struct less<boost::half_open_range<Incrementable> >
|
||||
: binary_function<
|
||||
boost::half_open_range<Incrementable>,
|
||||
boost::half_open_range<Incrementable>,bool>
|
||||
{
|
||||
bool operator()(
|
||||
const boost::half_open_range<Incrementable>& x,
|
||||
const boost::half_open_range<Incrementable>& y) const
|
||||
{
|
||||
less<Incrementable> cmp;
|
||||
return !y.empty() && (
|
||||
cmp(x.start(), y.start())
|
||||
|| !cmp(y.start(), x.start())
|
||||
&& cmp(x.finish(), y.finish()));
|
||||
}
|
||||
};
|
||||
|
||||
template <class Incrementable> struct less_equal<boost::half_open_range<Incrementable> >
|
||||
: binary_function<
|
||||
boost::half_open_range<Incrementable>,
|
||||
boost::half_open_range<Incrementable>,bool>
|
||||
{
|
||||
bool operator()(
|
||||
const boost::half_open_range<Incrementable>& x,
|
||||
const boost::half_open_range<Incrementable>& y) const
|
||||
{
|
||||
typedef boost::half_open_range<Incrementable> range;
|
||||
less<range> cmp;
|
||||
return !cmp(y,x);
|
||||
}
|
||||
};
|
||||
template <class Incrementable> struct greater<boost::half_open_range<Incrementable> >
|
||||
: binary_function<
|
||||
boost::half_open_range<Incrementable>,
|
||||
boost::half_open_range<Incrementable>,bool>
|
||||
{
|
||||
bool operator()(
|
||||
const boost::half_open_range<Incrementable>& x,
|
||||
const boost::half_open_range<Incrementable>& y) const
|
||||
{
|
||||
typedef boost::half_open_range<Incrementable> range;
|
||||
less<range> cmp;
|
||||
return cmp(y,x);
|
||||
}
|
||||
};
|
||||
|
||||
template <class Incrementable> struct greater_equal<boost::half_open_range<Incrementable> >
|
||||
: binary_function<
|
||||
boost::half_open_range<Incrementable>,
|
||||
boost::half_open_range<Incrementable>,bool>
|
||||
{
|
||||
bool operator()(
|
||||
const boost::half_open_range<Incrementable>& x,
|
||||
const boost::half_open_range<Incrementable>& y) const
|
||||
{
|
||||
typedef boost::half_open_range<Incrementable> range;
|
||||
less<range> cmp;
|
||||
return !cmp(x,y);
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#else
|
||||
|
||||
namespace boost {
|
||||
// Can't partially specialize std::less et al, so we must provide the operators
|
||||
template <class Incrementable>
|
||||
bool operator<(const half_open_range<Incrementable>& x,
|
||||
const half_open_range<Incrementable>& y)
|
||||
{
|
||||
return !y.empty() && (
|
||||
x.empty() || std::less<Incrementable>()(x.start(), y.start())
|
||||
|| !std::less<Incrementable>()(y.start(), x.start())
|
||||
&& std::less<Incrementable>()(x.finish(), y.finish()));
|
||||
}
|
||||
|
||||
template <class Incrementable>
|
||||
bool operator>(const half_open_range<Incrementable>& x,
|
||||
const half_open_range<Incrementable>& y)
|
||||
{
|
||||
return y < x;
|
||||
}
|
||||
|
||||
template <class Incrementable>
|
||||
bool operator<=(const half_open_range<Incrementable>& x,
|
||||
const half_open_range<Incrementable>& y)
|
||||
{
|
||||
return !(y < x);
|
||||
}
|
||||
|
||||
template <class Incrementable>
|
||||
bool operator>=(const half_open_range<Incrementable>& x,
|
||||
const half_open_range<Incrementable>& y)
|
||||
{
|
||||
return !(x < y);
|
||||
}
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // BOOST_HALF_OPEN_RANGE_HPP_
|
60
include/boost/iterator.hpp
Normal file
60
include/boost/iterator.hpp
Normal file
@ -0,0 +1,60 @@
|
||||
// interator.hpp workarounds for non-conforming standard libraries ---------//
|
||||
|
||||
// (C) Copyright Boost.org 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.
|
||||
|
||||
// See http://www.boost.org/libs/utility for documentation.
|
||||
|
||||
// Revision History
|
||||
// 12 Jan 01 added <cstddef> for std::ptrdiff_t (Jens Maurer)
|
||||
// 28 Jun 00 Workarounds to deal with known MSVC bugs (David Abrahams)
|
||||
// 26 Jun 00 Initial version (Jeremy Siek)
|
||||
|
||||
#ifndef BOOST_ITERATOR_HPP
|
||||
#define BOOST_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <cstddef> // std::ptrdiff_t
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
# if defined(BOOST_NO_STD_ITERATOR) && !defined(BOOST_MSVC_STD_ITERATOR)
|
||||
template <class Category, class T,
|
||||
class Distance = std::ptrdiff_t,
|
||||
class Pointer = T*, class Reference = T&>
|
||||
struct iterator
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef Distance difference_type;
|
||||
typedef Pointer pointer;
|
||||
typedef Reference reference;
|
||||
typedef Category iterator_category;
|
||||
};
|
||||
# else
|
||||
|
||||
// declare iterator_base in namespace detail to work around MSVC bugs which
|
||||
// prevent derivation from an identically-named class in a different namespace.
|
||||
namespace detail {
|
||||
template <class Category, class T, class Distance, class Pointer, class Reference>
|
||||
# if !defined(BOOST_MSVC_STD_ITERATOR)
|
||||
struct iterator_base : std::iterator<Category, T, Distance, Pointer, Reference> {};
|
||||
# else
|
||||
struct iterator_base : std::iterator<Category, T, Distance>
|
||||
{
|
||||
typedef Reference reference;
|
||||
typedef Pointer pointer;
|
||||
typedef Distance difference_type;
|
||||
};
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class Category, class T, class Distance = std::ptrdiff_t,
|
||||
class Pointer = T*, class Reference = T&>
|
||||
struct iterator : detail::iterator_base<Category, T, Distance, Pointer, Reference> {};
|
||||
# endif
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ITERATOR_HPP
|
@ -34,20 +34,11 @@ namespace detail
|
||||
|
||||
# ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||
|
||||
# if defined(BOOST_HAS_LONG_LONG)
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
std::numeric_limits<T>::is_specialized
|
||||
| boost::is_same<T,long long>::value
|
||||
| boost::is_same<T,unsigned long long>::value
|
||||
));
|
||||
# else
|
||||
BOOST_STATIC_CONSTANT(bool, value = std::numeric_limits<T>::is_specialized);
|
||||
# endif
|
||||
|
||||
# else
|
||||
|
||||
# if !defined(__BORLANDC__)
|
||||
# if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
boost::is_convertible<int,T>::value
|
||||
@ -64,6 +55,21 @@ namespace detail
|
||||
struct is_numeric
|
||||
: mpl::bool_<(::boost::detail::is_numeric_impl<T>::value)>
|
||||
{};
|
||||
|
||||
# if defined(BOOST_HAS_LONG_LONG)
|
||||
template <>
|
||||
struct is_numeric<long long>
|
||||
: mpl::true_ {};
|
||||
|
||||
template <>
|
||||
struct is_numeric<unsigned long long>
|
||||
: mpl::true_ {};
|
||||
# endif
|
||||
|
||||
// Some compilers fail to have a numeric_limits specialization
|
||||
template <>
|
||||
struct is_numeric<wchar_t>
|
||||
: mpl::true_ {};
|
||||
|
||||
template <class T>
|
||||
struct numeric_difference
|
||||
@ -121,7 +127,7 @@ namespace detail
|
||||
{
|
||||
static Difference distance(Incrementable1 x, Incrementable2 y)
|
||||
{
|
||||
return boost::detail::distance(x, y);
|
||||
return y - x;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -79,55 +79,17 @@
|
||||
|
||||
#endif
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \
|
||||
|| BOOST_WORKAROUND(__GNUC__, <= 2 && __GNUC_MINOR__ <= 95) \
|
||||
|| BOOST_WORKAROUND(__MWERKS__, <= 0x3000) \
|
||||
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
# define BOOST_NO_SFINAE // "Substitution Failure Is Not An Error not implemented"
|
||||
|
||||
# if 0 // test code
|
||||
template <bool x>
|
||||
struct bar
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct bar<false>
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
struct foo : bar<(sizeof(T) == 1)>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
char* f(int, typename foo<T>::type = 0) { return 0; }
|
||||
|
||||
template <class T>
|
||||
int f(...) { return 0; }
|
||||
|
||||
char* x = f<char>(0);
|
||||
int y = f<char[2]>(0);
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
#if BOOST_WORKAROUND(__MWERKS__, <=0x2407)
|
||||
# define BOOST_NO_IS_CONVERTIBLE // "is_convertible doesn't work for simple types"
|
||||
#endif
|
||||
|
||||
#if BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(3)) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
#if BOOST_WORKAROUND(__GNUC__, == 2) \
|
||||
|| BOOST_WORKAROUND(__GNUC__, == 3) && BOOST_WORKAROUND(__GNUC_MINOR__, < 4) && !defined(__EDG_VERSION__) \
|
||||
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
# define BOOST_NO_IS_CONVERTIBLE_TEMPLATE // The following program fails to compile:
|
||||
|
||||
# if 0 // test code
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
template <class T>
|
||||
struct foo
|
||||
{
|
||||
@ -160,4 +122,16 @@
|
||||
# define BOOST_ARG_DEPENDENT_TYPENAME
|
||||
# endif
|
||||
|
||||
// no include guard multiple inclusion intended
|
||||
# if BOOST_WORKAROUND(__GNUC__, == 2) && BOOST_WORKAROUND(__GNUC_MINOR__, BOOST_TESTED_AT(95)) \
|
||||
|| BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
|
||||
// GCC-2.95 eagerly instantiates templated constructors and conversion
|
||||
// operators in convertibility checks, causing premature errors.
|
||||
//
|
||||
// Borland's problems are harder to diagnose due to lack of an
|
||||
// instantiation stack backtrace. They may be due in part to the fact
|
||||
// that it drops cv-qualification willy-nilly in templates.
|
||||
# define BOOST_NO_ONE_WAY_ITERATOR_INTEROP
|
||||
# endif
|
||||
|
||||
// no include guard; multiple inclusion intended
|
||||
|
@ -13,12 +13,12 @@
|
||||
// 23/02/03 thw
|
||||
//
|
||||
|
||||
#undef BOOST_NO_SFINAE
|
||||
#undef BOOST_NO_IS_CONVERTIBLE
|
||||
#undef BOOST_NO_IS_CONVERTIBLE_TEMPLATE
|
||||
#undef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
|
||||
#undef BOOST_ARG_DEPENDENT_TYPENAME
|
||||
#undef BOOST_NO_LVALUE_RETURN_DETECTION
|
||||
#undef BOOST_NO_ONE_WAY_ITERATOR_INTEROP
|
||||
|
||||
#ifdef BOOST_ITERATOR_CONFIG_DEF
|
||||
# undef BOOST_ITERATOR_CONFIG_DEF
|
||||
|
@ -104,18 +104,11 @@ struct iterator_facade_default_category
|
||||
mpl::and_<
|
||||
is_convertible<Traversal, single_pass_traversal_tag>
|
||||
|
||||
, mpl::or_< // check for readability
|
||||
is_same<ValueParam,use_default>
|
||||
, is_convertible<Reference, ValueParam>
|
||||
>
|
||||
// check for readability
|
||||
, is_convertible<Reference, ValueParam>
|
||||
>
|
||||
, mpl::if_<
|
||||
iterator_writability_disabled<ValueParam,Reference>
|
||||
, std::input_iterator_tag
|
||||
, input_output_iterator_tag
|
||||
>
|
||||
|
||||
, mpl::identity<std::output_iterator_tag>
|
||||
, mpl::identity<std::input_iterator_tag>
|
||||
, mpl::identity<Traversal>
|
||||
>
|
||||
>
|
||||
{
|
||||
@ -167,7 +160,9 @@ struct iterator_category_with_traversal
|
||||
BOOST_STATIC_ASSERT(is_iterator_category<Category>::value);
|
||||
BOOST_STATIC_ASSERT(!is_iterator_category<Traversal>::value);
|
||||
BOOST_STATIC_ASSERT(!is_iterator_traversal<Category>::value);
|
||||
# if !BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
|
||||
BOOST_STATIC_ASSERT(is_iterator_traversal<Traversal>::value);
|
||||
# endif
|
||||
# endif
|
||||
};
|
||||
|
||||
|
@ -21,7 +21,13 @@ namespace boost { namespace detail {
|
||||
//
|
||||
//
|
||||
template <bool GreaterEqual, bool LessEqual>
|
||||
struct minimum_category_impl;
|
||||
struct minimum_category_impl
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
|
||||
{
|
||||
typedef void type;
|
||||
}
|
||||
# endif
|
||||
;
|
||||
|
||||
template <class T1, class T2>
|
||||
struct error_not_related_by_convertibility;
|
||||
@ -67,8 +73,14 @@ template <class T1 = mpl::_1, class T2 = mpl::_2>
|
||||
struct minimum_category
|
||||
{
|
||||
typedef minimum_category_impl<
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) // ETI workaround
|
||||
is_same<T2,int>::value ||
|
||||
# endif
|
||||
::boost::is_convertible<T1,T2>::value
|
||||
, ::boost::is_convertible<T2,T1>::value
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) // ETI workaround
|
||||
|| is_same<T1,int>::value
|
||||
# endif
|
||||
> outer;
|
||||
|
||||
typedef typename outer::template apply<T1,T2> inner;
|
||||
@ -85,7 +97,7 @@ struct minimum_category<mpl::_1,mpl::_2>
|
||||
{};
|
||||
};
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) // ETI workaround
|
||||
template <>
|
||||
struct minimum_category<int,int>
|
||||
{
|
||||
|
@ -12,11 +12,15 @@
|
||||
#include <boost/iterator.hpp>
|
||||
#include <boost/iterator/iterator_adaptor.hpp>
|
||||
|
||||
#include <boost/iterator/iterator_traits.hpp>
|
||||
|
||||
#include <boost/type_traits/remove_cv.hpp>
|
||||
#include <boost/pointee.hpp>
|
||||
#include <boost/indirect_reference.hpp>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
|
||||
#include <boost/python/detail/indirect_traits.hpp>
|
||||
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/add_reference.hpp>
|
||||
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
#include <boost/mpl/apply_if.hpp>
|
||||
@ -37,116 +41,8 @@ namespace boost
|
||||
template <class Iter, class Value, class Category, class Reference, class Difference>
|
||||
class indirect_iterator;
|
||||
|
||||
template <class T>
|
||||
struct referent;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
struct unspecified {};
|
||||
|
||||
//
|
||||
// Detection for whether a type has a nested `element_type'
|
||||
// typedef. Used to detect smart pointers. For compilers not
|
||||
// supporting mpl's has_xxx, we supply specializations. However, we
|
||||
// really ought to have a specializable is_pointer template which
|
||||
// can be used instead with something like
|
||||
// boost/python/pointee.hpp to find the value_type.
|
||||
//
|
||||
# ifndef BOOST_MPL_NO_AUX_HAS_XXX
|
||||
namespace aux
|
||||
{
|
||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(element_type)
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct has_element_type
|
||||
: mpl::bool_<
|
||||
mpl::if_<
|
||||
is_class<T>
|
||||
, ::boost::detail::aux::has_element_type<T>
|
||||
, mpl::false_
|
||||
>::type::value
|
||||
>
|
||||
{
|
||||
};
|
||||
# else
|
||||
template <class T>
|
||||
struct has_element_type
|
||||
: mpl::false_ {};
|
||||
|
||||
template <class T>
|
||||
struct has_element_type<boost::shared_ptr<T> >
|
||||
: mpl::true_ {};
|
||||
|
||||
template <class T>
|
||||
struct has_element_type<boost::scoped_ptr<T> >
|
||||
: mpl::true_ {};
|
||||
|
||||
template <class T>
|
||||
struct has_element_type<std::auto_ptr<T> >
|
||||
: mpl::true_ {};
|
||||
# endif
|
||||
|
||||
// Metafunction accessing the nested ::element_type
|
||||
template <class T>
|
||||
struct element_type
|
||||
: mpl::identity<typename T::element_type>
|
||||
{};
|
||||
|
||||
template <class T>
|
||||
struct iterator_is_mutable
|
||||
: mpl::not_<
|
||||
boost::python::detail::is_reference_to_const<
|
||||
typename iterator_reference<T>::type
|
||||
>
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct not_int_impl
|
||||
{
|
||||
template <class U>
|
||||
struct apply {
|
||||
typedef T type;
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct not_int_impl<int> {};
|
||||
|
||||
template <class T, class U>
|
||||
struct not_int
|
||||
: not_int_impl<T>::template apply<U> {};
|
||||
|
||||
|
||||
template <class Dereferenceable>
|
||||
struct class_has_element_type
|
||||
: mpl::and_<
|
||||
is_class<Dereferenceable>
|
||||
, has_element_type<Dereferenceable>
|
||||
>
|
||||
{};
|
||||
|
||||
// If the Value parameter is unspecified, we use this metafunction
|
||||
// to deduce the default types
|
||||
template <class Dereferenceable>
|
||||
struct default_indirect_value
|
||||
{
|
||||
typedef typename remove_cv<
|
||||
typename referent<Dereferenceable>::type
|
||||
>::type referent_t;
|
||||
|
||||
typedef typename mpl::if_<
|
||||
mpl::or_<
|
||||
class_has_element_type<Dereferenceable>
|
||||
, iterator_is_mutable<Dereferenceable>
|
||||
>
|
||||
, referent_t
|
||||
, referent_t const
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <class Iter, class Value, class Category, class Reference, class Difference>
|
||||
struct indirect_base
|
||||
{
|
||||
@ -156,10 +52,17 @@ namespace boost
|
||||
indirect_iterator<Iter, Value, Category, Reference, Difference>
|
||||
, Iter
|
||||
, typename ia_dflt_help<
|
||||
Value, default_indirect_value<dereferenceable>
|
||||
Value, pointee<dereferenceable>
|
||||
>::type
|
||||
, Category
|
||||
, Reference
|
||||
, typename ia_dflt_help<
|
||||
Reference
|
||||
, mpl::apply_if<
|
||||
is_same<Value,use_default>
|
||||
, indirect_reference<dereferenceable>
|
||||
, add_reference<Value>
|
||||
>
|
||||
>::type
|
||||
, Difference
|
||||
> type;
|
||||
};
|
||||
@ -168,19 +71,6 @@ namespace boost
|
||||
struct indirect_base<int, int, int, int, int> {};
|
||||
} // namespace detail
|
||||
|
||||
// User-specializable metafunction which returns the referent of a
|
||||
// dereferenceable type. The default implementation returns
|
||||
// Dereferenceable::element_type if such a member exists (thus
|
||||
// handling the boost smart pointers and auto_ptr), and
|
||||
// iterator_traits<Dereferenceable>::value_type otherwise.
|
||||
template <class Dereferenceable>
|
||||
struct referent
|
||||
: mpl::apply_if<
|
||||
detail::class_has_element_type<Dereferenceable>
|
||||
, detail::element_type<Dereferenceable>
|
||||
, iterator_value<Dereferenceable>
|
||||
>
|
||||
{};
|
||||
|
||||
template <
|
||||
class Iterator
|
||||
|
@ -21,8 +21,6 @@
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/mpl/or.hpp>
|
||||
|
||||
#include <boost/python/detail/is_xxx.hpp>
|
||||
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
|
||||
@ -249,22 +247,25 @@ namespace boost
|
||||
{
|
||||
friend class iterator_core_access;
|
||||
|
||||
protected:
|
||||
typedef typename detail::iterator_adaptor_base<
|
||||
Derived, Base, Value, Traversal, Reference, Difference
|
||||
>::type super_t;
|
||||
|
||||
public:
|
||||
iterator_adaptor() {}
|
||||
|
||||
explicit iterator_adaptor(Base iter)
|
||||
explicit iterator_adaptor(Base const &iter)
|
||||
: m_iterator(iter)
|
||||
{
|
||||
}
|
||||
|
||||
Base base() const
|
||||
Base const& base() const
|
||||
{ return m_iterator; }
|
||||
|
||||
protected:
|
||||
// for convenience in derived classes
|
||||
typedef iterator_adaptor<Derived,Base,Value,Traversal,Reference,Difference> iterator_adaptor_;
|
||||
|
||||
//
|
||||
// lvalue access to the Base object for Derived
|
||||
//
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/type_traits/remove_cv.hpp>
|
||||
|
||||
#include <boost/concept_archetype.hpp>
|
||||
|
||||
#include <boost/mpl/aux_/msvc_eti_base.hpp>
|
||||
#include <boost/mpl/bitand.hpp>
|
||||
#include <boost/mpl/int.hpp>
|
||||
@ -80,26 +82,26 @@ namespace detail
|
||||
template <class T>
|
||||
struct assign_proxy
|
||||
{
|
||||
assign_proxy& operator=(T);
|
||||
assign_proxy& operator=(T) { return *this; }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct read_proxy
|
||||
{
|
||||
operator T();
|
||||
operator T() { return static_object<T>::get(); }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct read_write_proxy
|
||||
: assign_proxy<T>
|
||||
, read_proxy<T>
|
||||
: read_proxy<T> // Use to inherit from assign_proxy, but that doesn't work. -JGS
|
||||
{
|
||||
read_write_proxy& operator=(T) { return *this; }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct arrow_proxy
|
||||
{
|
||||
T const* operator->() const;
|
||||
T const* operator->() const { return 0; }
|
||||
};
|
||||
|
||||
struct no_operator_brackets {};
|
||||
@ -107,13 +109,13 @@ namespace detail
|
||||
template <class ValueType>
|
||||
struct readable_operator_brackets
|
||||
{
|
||||
read_proxy<ValueType> operator[](std::ptrdiff_t n) const;
|
||||
read_proxy<ValueType> operator[](std::ptrdiff_t n) const { return read_proxy<ValueType>(); }
|
||||
};
|
||||
|
||||
template <class ValueType>
|
||||
struct writable_operator_brackets
|
||||
{
|
||||
read_write_proxy<ValueType> operator[](std::ptrdiff_t n) const;
|
||||
read_write_proxy<ValueType> operator[](std::ptrdiff_t n) const { return read_write_proxy<ValueType>(); }
|
||||
};
|
||||
|
||||
template <class Value, class AccessCategory, class TraversalCategory>
|
||||
@ -147,12 +149,26 @@ namespace detail
|
||||
template <class Derived,class Value> struct archetype;
|
||||
};
|
||||
|
||||
// Constructor argument for those iterators that
|
||||
// are not default constructible
|
||||
struct ctor_arg {};
|
||||
|
||||
template <class Derived, class Value, class TraversalCategory>
|
||||
struct traversal_archetype_
|
||||
: mpl::aux::msvc_eti_base<
|
||||
typename traversal_archetype_impl<TraversalCategory>::template archetype<Derived,Value>
|
||||
>::type
|
||||
{};
|
||||
{
|
||||
typedef typename
|
||||
traversal_archetype_impl<TraversalCategory>::template archetype<Derived,Value>
|
||||
base;
|
||||
|
||||
traversal_archetype_() {}
|
||||
|
||||
traversal_archetype_(ctor_arg arg)
|
||||
: base(arg)
|
||||
{}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct traversal_archetype_impl<incrementable_traversal_tag>
|
||||
@ -160,10 +176,13 @@ namespace detail
|
||||
template<class Derived, class Value>
|
||||
struct archetype
|
||||
{
|
||||
typedef void difference_type;
|
||||
explicit archetype(ctor_arg) {}
|
||||
|
||||
Derived& operator++();
|
||||
Derived operator++(int) const;
|
||||
struct bogus { }; // This use to be void, but that causes trouble for iterator_facade. Need more research. -JGS
|
||||
typedef bogus difference_type;
|
||||
|
||||
Derived& operator++() { return (Derived&)static_object<Derived>::get(); }
|
||||
Derived operator++(int) const { return (Derived&)static_object<Derived>::get(); }
|
||||
};
|
||||
};
|
||||
|
||||
@ -175,18 +194,21 @@ namespace detail
|
||||
: public equality_comparable< traversal_archetype_<Derived, Value, single_pass_traversal_tag> >,
|
||||
public traversal_archetype_<Derived, Value, incrementable_traversal_tag>
|
||||
{
|
||||
explicit archetype(ctor_arg arg)
|
||||
: traversal_archetype_<Derived, Value, incrementable_traversal_tag>(arg)
|
||||
{}
|
||||
};
|
||||
};
|
||||
|
||||
template <class Derived, class Value>
|
||||
bool operator==(traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&,
|
||||
traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&);
|
||||
traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&) { return true; }
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
// doesn't seem to pick up != from equality_comparable
|
||||
template <class Derived, class Value>
|
||||
bool operator!=(traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&,
|
||||
traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&);
|
||||
traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&) { return true; }
|
||||
#endif
|
||||
template <>
|
||||
struct traversal_archetype_impl<forward_traversal_tag>
|
||||
@ -195,6 +217,9 @@ namespace detail
|
||||
struct archetype
|
||||
: public traversal_archetype_<Derived, Value, single_pass_traversal_tag>
|
||||
{
|
||||
archetype()
|
||||
: traversal_archetype_<Derived, Value, single_pass_traversal_tag>(ctor_arg())
|
||||
{}
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
};
|
||||
};
|
||||
@ -206,8 +231,8 @@ namespace detail
|
||||
struct archetype
|
||||
: public traversal_archetype_<Derived, Value, forward_traversal_tag>
|
||||
{
|
||||
Derived& operator--();
|
||||
Derived operator--(int) const;
|
||||
Derived& operator--() { return static_object<Derived>::get(); }
|
||||
Derived operator--(int) const { return static_object<Derived>::get(); }
|
||||
};
|
||||
};
|
||||
|
||||
@ -219,30 +244,34 @@ namespace detail
|
||||
: public partially_ordered<traversal_archetype_<Derived, Value, random_access_traversal_tag> >,
|
||||
public traversal_archetype_<Derived, Value, bidirectional_traversal_tag>
|
||||
{
|
||||
Derived& operator+=(std::ptrdiff_t);
|
||||
Derived& operator-=(std::ptrdiff_t);
|
||||
Derived& operator+=(std::ptrdiff_t) { return static_object<Derived>::get(); }
|
||||
Derived& operator-=(std::ptrdiff_t) { return static_object<Derived>::get(); }
|
||||
};
|
||||
};
|
||||
|
||||
template <class Derived, class Value>
|
||||
Derived& operator+(traversal_archetype_<Derived, Value, random_access_traversal_tag> const&,
|
||||
std::ptrdiff_t);
|
||||
std::ptrdiff_t) { return static_object<Derived>::get(); }
|
||||
|
||||
template <class Derived, class Value>
|
||||
Derived& operator+(std::ptrdiff_t,
|
||||
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&);
|
||||
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&)
|
||||
{ return static_object<Derived>::get(); }
|
||||
|
||||
template <class Derived, class Value>
|
||||
Derived& operator-(traversal_archetype_<Derived, Value, random_access_traversal_tag> const&,
|
||||
std::ptrdiff_t);
|
||||
std::ptrdiff_t)
|
||||
{ return static_object<Derived>::get(); }
|
||||
|
||||
template <class Derived, class Value>
|
||||
std::ptrdiff_t operator-(traversal_archetype_<Derived, Value, random_access_traversal_tag> const&,
|
||||
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&);
|
||||
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&)
|
||||
{ return 0; }
|
||||
|
||||
template <class Derived, class Value>
|
||||
bool operator<(traversal_archetype_<Derived, Value, random_access_traversal_tag> const&,
|
||||
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&);
|
||||
traversal_archetype_<Derived, Value, random_access_traversal_tag> const&)
|
||||
{ return true; }
|
||||
|
||||
struct bogus_type;
|
||||
|
||||
@ -286,9 +315,9 @@ struct iterator_access_archetype_impl<
|
||||
typedef Value reference;
|
||||
typedef Value* pointer;
|
||||
|
||||
value_type operator*() const;
|
||||
value_type operator*() const { return static_object<value_type>::get(); }
|
||||
|
||||
detail::arrow_proxy<Value> operator->() const;
|
||||
detail::arrow_proxy<Value> operator->() const { return detail::arrow_proxy<Value>(); }
|
||||
};
|
||||
};
|
||||
|
||||
@ -307,7 +336,7 @@ struct iterator_access_archetype_impl<
|
||||
typedef void reference;
|
||||
typedef void pointer;
|
||||
|
||||
detail::assign_proxy<Value> operator*() const;
|
||||
detail::assign_proxy<Value> operator*() const { return detail::assign_proxy<Value>(); }
|
||||
};
|
||||
};
|
||||
|
||||
@ -324,7 +353,7 @@ struct iterator_access_archetype_impl<
|
||||
{
|
||||
typedef detail::read_write_proxy<Value> reference;
|
||||
|
||||
detail::read_write_proxy<Value> operator*() const;
|
||||
detail::read_write_proxy<Value> operator*() const { return detail::read_write_proxy<Value>(); }
|
||||
};
|
||||
};
|
||||
|
||||
@ -339,8 +368,8 @@ struct iterator_access_archetype_impl<iterator_archetypes::readable_lvalue_itera
|
||||
{
|
||||
typedef Value& reference;
|
||||
|
||||
Value& operator*() const;
|
||||
Value* operator->() const;
|
||||
Value& operator*() const { return static_object<Value>::get(); }
|
||||
Value* operator->() const { return 0; }
|
||||
};
|
||||
};
|
||||
|
||||
@ -443,13 +472,27 @@ struct iterator_archetype
|
||||
typedef typename base::iterator_category iterator_category;
|
||||
# endif
|
||||
|
||||
iterator_archetype();
|
||||
iterator_archetype(iterator_archetype const&);
|
||||
iterator_archetype() { }
|
||||
iterator_archetype(iterator_archetype const& x)
|
||||
: detail::iterator_archetype_base<
|
||||
Value
|
||||
, AccessCategory
|
||||
, TraversalCategory
|
||||
>(x)
|
||||
{}
|
||||
|
||||
iterator_archetype& operator=(iterator_archetype const&);
|
||||
iterator_archetype& operator=(iterator_archetype const&)
|
||||
{ return *this; }
|
||||
|
||||
# if 0
|
||||
// Optional conversion from mutable
|
||||
// iterator_archetype(iterator_archetype<typename detail::convertible_type<Value>::type, AccessCategory, TraversalCategory> const&);
|
||||
iterator_archetype(
|
||||
iterator_archetype<
|
||||
typename detail::convertible_type<Value>::type
|
||||
, AccessCategory
|
||||
, TraversalCategory> const&
|
||||
);
|
||||
# endif
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
@ -27,19 +27,43 @@ namespace boost {
|
||||
//
|
||||
// Traversal Categories
|
||||
//
|
||||
struct incrementable_traversal_tag {};
|
||||
|
||||
struct no_traversal_tag {};
|
||||
|
||||
struct incrementable_traversal_tag
|
||||
: no_traversal_tag
|
||||
{
|
||||
// incrementable_traversal_tag() {}
|
||||
// incrementable_traversal_tag(std::output_iterator_tag const&) {};
|
||||
};
|
||||
|
||||
struct single_pass_traversal_tag
|
||||
: incrementable_traversal_tag {};
|
||||
: incrementable_traversal_tag
|
||||
{
|
||||
// single_pass_traversal_tag() {}
|
||||
// single_pass_traversal_tag(std::input_iterator_tag const&) {};
|
||||
};
|
||||
|
||||
struct forward_traversal_tag
|
||||
: single_pass_traversal_tag {};
|
||||
: single_pass_traversal_tag
|
||||
{
|
||||
// forward_traversal_tag() {}
|
||||
// forward_traversal_tag(std::forward_iterator_tag const&) {};
|
||||
};
|
||||
|
||||
struct bidirectional_traversal_tag
|
||||
: forward_traversal_tag {};
|
||||
: forward_traversal_tag
|
||||
{
|
||||
// bidirectional_traversal_tag() {};
|
||||
// bidirectional_traversal_tag(std::bidirectional_iterator_tag const&) {};
|
||||
};
|
||||
|
||||
struct random_access_traversal_tag
|
||||
: bidirectional_traversal_tag {};
|
||||
: bidirectional_traversal_tag
|
||||
{
|
||||
// random_access_traversal_tag() {};
|
||||
// random_access_traversal_tag(std::random_access_iterator_tag const&) {};
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
@ -58,17 +59,13 @@ namespace boost_concepts {
|
||||
template <typename Iterator>
|
||||
class ReadableIteratorConcept {
|
||||
public:
|
||||
typedef BOOST_DEDUCED_TYPENAME ::boost::detail::iterator_traits<Iterator>::value_type value_type;
|
||||
typedef BOOST_DEDUCED_TYPENAME ::boost::detail::iterator_traits<Iterator>::reference reference;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::value_type value_type;
|
||||
|
||||
void constraints() {
|
||||
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
|
||||
boost::function_requires< boost::EqualityComparableConcept<Iterator> >();
|
||||
boost::function_requires<
|
||||
boost::DefaultConstructibleConcept<Iterator> >();
|
||||
boost::function_requires< boost::AssignableConcept<Iterator> >();
|
||||
boost::function_requires< boost::CopyConstructibleConcept<Iterator> >();
|
||||
|
||||
reference r = *i; // or perhaps read(x)
|
||||
value_type v(r);
|
||||
value_type v = *i;
|
||||
boost::ignore_unused_variable_warning(v);
|
||||
}
|
||||
Iterator i;
|
||||
@ -76,18 +73,14 @@ namespace boost_concepts {
|
||||
|
||||
template <
|
||||
typename Iterator
|
||||
, typename ValueType = typename boost::detail::iterator_traits<Iterator>::value_type
|
||||
, typename ValueType = BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::value_type
|
||||
>
|
||||
class WritableIteratorConcept {
|
||||
public:
|
||||
|
||||
void constraints() {
|
||||
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
|
||||
boost::function_requires< boost::EqualityComparableConcept<Iterator> >();
|
||||
boost::function_requires<
|
||||
boost::DefaultConstructibleConcept<Iterator> >();
|
||||
|
||||
*i = v; // a good alternative could be something like write(x, v)
|
||||
boost::function_requires< boost::CopyConstructibleConcept<Iterator> >();
|
||||
*i = v;
|
||||
}
|
||||
ValueType v;
|
||||
Iterator i;
|
||||
@ -105,47 +98,18 @@ namespace boost_concepts {
|
||||
};
|
||||
|
||||
template <typename Iterator>
|
||||
class ReadableLvalueIteratorConcept
|
||||
class LvalueIteratorConcept
|
||||
{
|
||||
public:
|
||||
typedef typename boost::detail::iterator_traits<Iterator>::value_type value_type;
|
||||
typedef typename boost::detail::iterator_traits<Iterator>::reference reference;
|
||||
|
||||
void constraints()
|
||||
{
|
||||
boost::function_requires< ReadableIteratorConcept<Iterator> >();
|
||||
|
||||
typedef boost::mpl::or_<
|
||||
boost::is_same<reference, value_type&>
|
||||
, boost::is_same<reference, value_type const&>
|
||||
> correct_reference;
|
||||
|
||||
BOOST_STATIC_ASSERT(correct_reference::value);
|
||||
|
||||
reference v = *i;
|
||||
boost::ignore_unused_variable_warning(v);
|
||||
}
|
||||
value_type& r = const_cast<value_type&>(*i);
|
||||
boost::ignore_unused_variable_warning(r);
|
||||
}
|
||||
Iterator i;
|
||||
};
|
||||
|
||||
template <typename Iterator>
|
||||
class WritableLvalueIteratorConcept {
|
||||
public:
|
||||
typedef typename boost::detail::iterator_traits<Iterator>::value_type value_type;
|
||||
typedef typename boost::detail::iterator_traits<Iterator>::reference reference;
|
||||
|
||||
void constraints() {
|
||||
boost::function_requires<
|
||||
ReadableLvalueIteratorConcept<Iterator> >();
|
||||
boost::function_requires<
|
||||
WritableIteratorConcept<Iterator, value_type> >();
|
||||
boost::function_requires<
|
||||
SwappableIteratorConcept<Iterator> >();
|
||||
|
||||
|
||||
BOOST_STATIC_ASSERT((boost::is_same<reference, value_type&>::value));
|
||||
}
|
||||
};
|
||||
|
||||
//===========================================================================
|
||||
// Iterator Traversal Concepts
|
||||
@ -156,9 +120,8 @@ namespace boost_concepts {
|
||||
typedef typename boost::iterator_traversal<Iterator>::type traversal_category;
|
||||
|
||||
void constraints() {
|
||||
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
|
||||
boost::function_requires<
|
||||
boost::DefaultConstructibleConcept<Iterator> >();
|
||||
boost::function_requires< boost::AssignableConcept<Iterator> >();
|
||||
boost::function_requires< boost::CopyConstructibleConcept<Iterator> >();
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
(boost::is_convertible<
|
||||
@ -200,6 +163,8 @@ namespace boost_concepts {
|
||||
|
||||
void constraints() {
|
||||
boost::function_requires< SinglePassIteratorConcept<Iterator> >();
|
||||
boost::function_requires<
|
||||
boost::DefaultConstructibleConcept<Iterator> >();
|
||||
|
||||
typedef boost::mpl::and_<
|
||||
boost::is_integral<difference_type>,
|
||||
@ -268,109 +233,73 @@ namespace boost_concepts {
|
||||
//===========================================================================
|
||||
// Iterator Interoperability Concept
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template <typename TraversalTag>
|
||||
struct Operations;
|
||||
|
||||
template <>
|
||||
struct Operations<boost::incrementable_traversal_tag>
|
||||
namespace detail
|
||||
{
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
static void constraints(Iterator1 const& i1, Iterator2 const& i2)
|
||||
{
|
||||
// no interoperability constraints
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Operations<boost::single_pass_traversal_tag>
|
||||
{
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
static void constraints(Iterator1 const& i1, Iterator2 const& i2)
|
||||
{
|
||||
Operations<boost::incrementable_traversal_tag>::constraints(i1, i2);
|
||||
i1 == i2;
|
||||
i1 != i2;
|
||||
|
||||
i2 == i1;
|
||||
i2 != i1;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Operations<boost::forward_traversal_tag>
|
||||
{
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
static void constraints(Iterator1 const& i1, Iterator2 const& i2)
|
||||
{
|
||||
Operations<boost::single_pass_traversal_tag>::constraints(i1, i2);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Operations<boost::bidirectional_traversal_tag>
|
||||
{
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
static void constraints(Iterator1 const& i1, Iterator2 const& i2)
|
||||
{
|
||||
Operations<boost::forward_traversal_tag>::constraints(i1, i2);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Operations<boost::random_access_traversal_tag>
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
void interop_single_pass_constraints(Iterator1 const& i1, Iterator2 const& i2)
|
||||
{
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
static void constraints(Iterator1 const& i1, Iterator2 const& i2)
|
||||
{
|
||||
Operations<boost::bidirectional_traversal_tag>::constraints(i1, i2);
|
||||
|
||||
i1 < i2;
|
||||
i1 <= i2;
|
||||
i1 > i2;
|
||||
i1 >= i2;
|
||||
i1 - i2;
|
||||
|
||||
i2 < i1;
|
||||
i2 <= i1;
|
||||
i2 > i1;
|
||||
i2 >= i1;
|
||||
i2 - i1;
|
||||
}
|
||||
};
|
||||
bool b;
|
||||
b = i1 == i2;
|
||||
b = i1 != i2;
|
||||
|
||||
b = i2 == i1;
|
||||
b = i2 != i1;
|
||||
}
|
||||
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
void interop_rand_access_constraints(Iterator1 const& i1, Iterator2 const& i2,
|
||||
boost::random_access_traversal_tag, boost::random_access_traversal_tag)
|
||||
{
|
||||
bool b;
|
||||
typename boost::detail::iterator_traits<Iterator2>::difference_type n;
|
||||
b = i1 < i2;
|
||||
b = i1 <= i2;
|
||||
b = i1 > i2;
|
||||
b = i1 >= i2;
|
||||
n = i1 - i2;
|
||||
|
||||
b = i2 < i1;
|
||||
b = i2 <= i1;
|
||||
b = i2 > i1;
|
||||
b = i2 >= i1;
|
||||
n = i2 - i1;
|
||||
}
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
void interop_rand_access_constraints(Iterator1 const& i1, Iterator2 const& i2,
|
||||
boost::single_pass_traversal_tag, boost::single_pass_traversal_tag)
|
||||
{ }
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename Iterator, typename ConstIterator>
|
||||
class InteroperableConcept
|
||||
class InteroperableIteratorConcept
|
||||
{
|
||||
public:
|
||||
typedef typename boost::iterator_traversal<Iterator>::type traversal_category;
|
||||
typedef typename boost::detail::iterator_traits<Iterator>::difference_type
|
||||
difference_type;
|
||||
typedef typename boost::detail::pure_traversal_tag<
|
||||
typename boost::iterator_traversal<
|
||||
Iterator
|
||||
>::type
|
||||
>::type traversal_category;
|
||||
|
||||
typedef typename boost::iterator_traversal<ConstIterator>::type
|
||||
const_traversal_category;
|
||||
typedef typename boost::detail::iterator_traits<ConstIterator>::difference_type
|
||||
const_difference_type;
|
||||
typedef typename boost::detail::pure_traversal_tag<
|
||||
typename boost::iterator_traversal<
|
||||
ConstIterator
|
||||
>::type
|
||||
>::type const_traversal_category;
|
||||
|
||||
void constraints() {
|
||||
BOOST_STATIC_ASSERT((boost::is_same< difference_type,
|
||||
const_difference_type>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same< traversal_category,
|
||||
const_traversal_category>::value));
|
||||
|
||||
// ToDo check what the std really requires
|
||||
|
||||
// detail::Operations<traversal_category>::constraints(i, ci);
|
||||
void constraints()
|
||||
{
|
||||
boost::function_requires< SinglePassIteratorConcept<Iterator> >();
|
||||
boost::function_requires< SinglePassIteratorConcept<ConstIterator> >();
|
||||
|
||||
ci = i;
|
||||
detail::interop_single_pass_constraints(i, ci);
|
||||
detail::interop_rand_access_constraints(i, ci, traversal_category(), const_traversal_category());
|
||||
|
||||
}
|
||||
Iterator i;
|
||||
ConstIterator ci;
|
||||
ci = i;
|
||||
}
|
||||
Iterator i;
|
||||
ConstIterator ci;
|
||||
};
|
||||
|
||||
} // namespace boost_concepts
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include <boost/iterator.hpp>
|
||||
#include <boost/iterator/interoperable.hpp>
|
||||
#include <boost/iterator/iterator_traits.hpp>
|
||||
|
||||
#include <boost/iterator/detail/facade_iterator_category.hpp>
|
||||
#include <boost/iterator/detail/enable_if.hpp>
|
||||
@ -21,10 +22,18 @@
|
||||
#include <boost/type_traits/add_const.hpp>
|
||||
#include <boost/type_traits/add_pointer.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#include <boost/type_traits/is_pod.hpp>
|
||||
|
||||
#include <boost/mpl/apply_if.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/or.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/mpl/always.hpp>
|
||||
#include <boost/mpl/apply.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
|
||||
#include <boost/iterator/detail/config_def.hpp> // this goes last
|
||||
|
||||
@ -36,19 +45,27 @@ namespace boost
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// A binary metafunction class that always returns bool. VC6
|
||||
// ICEs on mpl::always<bool>, probably because of the default
|
||||
// parameters.
|
||||
struct always_bool2
|
||||
{
|
||||
template <class T, class U>
|
||||
struct apply
|
||||
{
|
||||
typedef bool type;
|
||||
};
|
||||
};
|
||||
|
||||
//
|
||||
// enable if for use in operator implementation.
|
||||
//
|
||||
// enable_if_interoperable falls back to always enabled for compilers
|
||||
// that don't support enable_if or is_convertible.
|
||||
//
|
||||
template <
|
||||
class Facade1
|
||||
, class Facade2
|
||||
, class Return
|
||||
>
|
||||
struct enable_if_interoperable
|
||||
#ifndef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
|
||||
: ::boost::iterators::enable_if<
|
||||
mpl::or_<
|
||||
is_convertible<Facade1, Facade2>
|
||||
@ -56,11 +73,7 @@ namespace boost
|
||||
>
|
||||
, Return
|
||||
>
|
||||
#endif
|
||||
{
|
||||
#ifdef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
|
||||
typedef Return type;
|
||||
#endif
|
||||
};
|
||||
|
||||
//
|
||||
@ -92,25 +105,178 @@ namespace boost
|
||||
|| BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, BOOST_TESTED_AT(310))) \
|
||||
|| BOOST_WORKAROUND(BOOST_RWSTD_VER, BOOST_TESTED_AT(0x20101)) \
|
||||
|| BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, <= 310)
|
||||
|
||||
|
||||
// To interoperate with some broken library/compiler
|
||||
// combinations, user-defined iterators must be derived from
|
||||
// std::iterator. It is possible to implement a standard
|
||||
// library for broken compilers without this limitation.
|
||||
# define BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE 1
|
||||
|
||||
|
||||
typedef
|
||||
iterator<iterator_category, value_type, Difference, pointer, Reference>
|
||||
base;
|
||||
# endif
|
||||
# endif
|
||||
};
|
||||
|
||||
// iterators whose dereference operators reference the same value
|
||||
// for all iterators into the same sequence (like many input
|
||||
// iterators) need help with their postfix ++: the referenced
|
||||
// value must be read and stored away before the increment occurs
|
||||
// so that *a++ yields the originally referenced element and not
|
||||
// the next one.
|
||||
template <class Iterator>
|
||||
class postfix_increment_proxy
|
||||
{
|
||||
typedef typename iterator_value<Iterator>::type value_type;
|
||||
public:
|
||||
explicit postfix_increment_proxy(Iterator const& x)
|
||||
: stored_value(*x)
|
||||
{}
|
||||
|
||||
// Returning a mutable reference allows nonsense like
|
||||
// (*r++).mutate(), but it imposes fewer assumptions about the
|
||||
// behavior of the value_type. In particular, recall taht
|
||||
// (*r).mutate() is legal if operator* returns by value.
|
||||
value_type&
|
||||
operator*() const
|
||||
{
|
||||
return this->stored_value;
|
||||
}
|
||||
private:
|
||||
mutable value_type stored_value;
|
||||
};
|
||||
|
||||
//
|
||||
// In general, we can't determine that such an iterator isn't
|
||||
// writable -- we also need to store a copy of the old iterator so
|
||||
// that it can be written into.
|
||||
template <class Iterator>
|
||||
class writable_postfix_increment_proxy
|
||||
{
|
||||
typedef typename iterator_value<Iterator>::type value_type;
|
||||
public:
|
||||
explicit writable_postfix_increment_proxy(Iterator const& x)
|
||||
: stored_value(*x)
|
||||
, stored_iterator(x)
|
||||
{}
|
||||
|
||||
// Dereferencing must return a proxy so that both *r++ = o and
|
||||
// value_type(*r++) can work. In this case, *r is the same as
|
||||
// *r++, and the conversion operator below is used to ensure
|
||||
// readability.
|
||||
writable_postfix_increment_proxy const&
|
||||
operator*() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Provides readability of *r++
|
||||
operator value_type&() const
|
||||
{
|
||||
return stored_value;
|
||||
}
|
||||
|
||||
// Provides writability of *r++
|
||||
template <class T>
|
||||
T const& operator=(T const& x) const
|
||||
{
|
||||
*this->stored_iterator = x;
|
||||
return x;
|
||||
}
|
||||
|
||||
// This overload just in case only non-const objects are writable
|
||||
template <class T>
|
||||
T& operator=(T& x) const
|
||||
{
|
||||
*this->stored_iterator = x;
|
||||
return x;
|
||||
}
|
||||
private:
|
||||
mutable value_type stored_value;
|
||||
Iterator stored_iterator;
|
||||
};
|
||||
|
||||
# ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
template <class Reference, class Value>
|
||||
struct is_non_proxy_reference_impl
|
||||
{
|
||||
static Reference r;
|
||||
|
||||
template <class R>
|
||||
static typename mpl::if_<
|
||||
is_convertible<
|
||||
R const volatile*
|
||||
, Value const volatile*
|
||||
>
|
||||
, char[1]
|
||||
, char[2]
|
||||
>::type& helper(R const&);
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, value = sizeof(helper(r)) == 1);
|
||||
};
|
||||
|
||||
template <class Reference, class Value>
|
||||
struct is_non_proxy_reference
|
||||
: mpl::bool_<
|
||||
is_non_proxy_reference_impl<Reference, Value>::value
|
||||
>
|
||||
{};
|
||||
# else
|
||||
template <class Reference, class Value>
|
||||
struct is_non_proxy_reference
|
||||
: is_convertible<
|
||||
typename remove_reference<Reference>::type
|
||||
const volatile*
|
||||
, Value const volatile*
|
||||
>
|
||||
{};
|
||||
# endif
|
||||
|
||||
// A metafunction to choose the result type of postfix ++
|
||||
//
|
||||
// Because the C++98 input iterator requirements say that *r++ has
|
||||
// type T (value_type), implementations of some standard
|
||||
// algorithms like lexicographical_compare may use constructions
|
||||
// like:
|
||||
//
|
||||
// *r++ < *s++
|
||||
//
|
||||
// If *r++ returns a proxy (as required if r is writable but not
|
||||
// multipass), this sort of expression will fail unless the proxy
|
||||
// supports the operator<. Since there are any number of such
|
||||
// operations, we're not going to try to support them. Therefore,
|
||||
// even if r++ returns a proxy, *r++ will only return a proxy if
|
||||
// *r also returns a proxy.
|
||||
template <class Iterator, class Value, class Reference, class CategoryOrTraversal>
|
||||
struct postfix_increment_result
|
||||
: mpl::apply_if<
|
||||
mpl::and_<
|
||||
// A proxy is only needed for readable iterators
|
||||
is_convertible<Reference,Value>
|
||||
|
||||
// No multipass iterator can have values that disappear
|
||||
// before positions can be re-visited
|
||||
, mpl::not_<
|
||||
is_convertible<
|
||||
typename iterator_category_to_traversal<CategoryOrTraversal>::type
|
||||
, forward_traversal_tag
|
||||
>
|
||||
>
|
||||
>
|
||||
, mpl::if_<
|
||||
is_non_proxy_reference<Reference,Value>
|
||||
, postfix_increment_proxy<Iterator>
|
||||
, writable_postfix_increment_proxy<Iterator>
|
||||
>
|
||||
, mpl::identity<Iterator>
|
||||
>
|
||||
{};
|
||||
|
||||
// operator->() needs special support for input iterators to strictly meet the
|
||||
// standard's requirements. If *i is not a reference type, we must still
|
||||
// produce a (constant) lvalue to which a pointer can be formed. We do that by
|
||||
// returning an instantiation of this special proxy class template.
|
||||
|
||||
template <class T>
|
||||
struct operator_arrow_proxy
|
||||
{
|
||||
@ -125,7 +291,7 @@ namespace boost
|
||||
// A metafunction that gets the result type for operator->. Also
|
||||
// has a static function make() which builds the result from a
|
||||
// Reference
|
||||
template <class Value, class Reference, class Pointer>
|
||||
template <class ValueType, class Reference, class Pointer>
|
||||
struct operator_arrow_result
|
||||
{
|
||||
// CWPro8.3 won't accept "operator_arrow_result::type", and we
|
||||
@ -134,15 +300,15 @@ namespace boost
|
||||
typedef typename mpl::if_<
|
||||
is_reference<Reference>
|
||||
, Pointer
|
||||
, operator_arrow_proxy<Value>
|
||||
, operator_arrow_proxy<ValueType>
|
||||
>::type type;
|
||||
|
||||
|
||||
static type make(Reference x)
|
||||
{
|
||||
return type(&x);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
|
||||
// Deal with ETI
|
||||
template<>
|
||||
@ -152,13 +318,14 @@ namespace boost
|
||||
};
|
||||
# endif
|
||||
|
||||
//
|
||||
// Iterator is actually an iterator_facade, so we do not have to
|
||||
// go through iterator_traits to access the traits.
|
||||
//
|
||||
// A proxy return type for operator[], needed to deal with
|
||||
// iterators that may invalidate referents upon destruction.
|
||||
// Consider the temporary iterator in *(a + n)
|
||||
template <class Iterator>
|
||||
class operator_brackets_proxy
|
||||
{
|
||||
// Iterator is actually an iterator_facade, so we do not have to
|
||||
// go through iterator_traits to access the traits.
|
||||
typedef typename Iterator::reference reference;
|
||||
typedef typename Iterator::value_type value_type;
|
||||
|
||||
@ -177,48 +344,98 @@ namespace boost
|
||||
*m_iter = val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
Iterator m_iter;
|
||||
};
|
||||
|
||||
// A metafunction that determines whether operator[] must return a
|
||||
// proxy, or whether it can simply return a copy of the value_type.
|
||||
template <class ValueType, class Reference>
|
||||
struct use_operator_brackets_proxy
|
||||
: mpl::not_<
|
||||
mpl::and_<
|
||||
// Really we want an is_copy_constructible trait here,
|
||||
// but is_POD will have to suffice in the meantime.
|
||||
boost::is_POD<ValueType>
|
||||
, iterator_writability_disabled<ValueType,Reference>
|
||||
>
|
||||
>
|
||||
{};
|
||||
|
||||
template <class Iterator, class Value, class Reference>
|
||||
struct operator_brackets_result
|
||||
{
|
||||
typedef typename mpl::if_<
|
||||
iterator_writability_disabled<Value,Reference>
|
||||
, Value
|
||||
use_operator_brackets_proxy<Value,Reference>
|
||||
, operator_brackets_proxy<Iterator>
|
||||
, Value
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <class Iterator>
|
||||
operator_brackets_proxy<Iterator> make_operator_brackets_result(Iterator const& iter, mpl::false_)
|
||||
operator_brackets_proxy<Iterator> make_operator_brackets_result(Iterator const& iter, mpl::true_)
|
||||
{
|
||||
return operator_brackets_proxy<Iterator>(iter);
|
||||
}
|
||||
|
||||
template <class Iterator>
|
||||
typename Iterator::value_type make_operator_brackets_result(Iterator const& iter, mpl::true_)
|
||||
typename Iterator::value_type make_operator_brackets_result(Iterator const& iter, mpl::false_)
|
||||
{
|
||||
return *iter;
|
||||
}
|
||||
|
||||
struct choose_difference_type
|
||||
{
|
||||
template <class I1, class I2>
|
||||
struct apply
|
||||
:
|
||||
# ifdef BOOST_NO_ONE_WAY_ITERATOR_INTEROP
|
||||
iterator_difference<I1>
|
||||
# elif BOOST_WORKAROUND(BOOST_MSVC, == 1200)
|
||||
mpl::if_<
|
||||
is_convertible<I2,I1>
|
||||
, typename I1::difference_type
|
||||
, typename I2::difference_type
|
||||
>
|
||||
# else
|
||||
mpl::apply_if<
|
||||
is_convertible<I2,I1>
|
||||
, iterator_difference<I1>
|
||||
, iterator_difference<I2>
|
||||
>
|
||||
# endif
|
||||
{};
|
||||
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
|
||||
// Macros which describe the declarations of binary operators
|
||||
# ifdef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY
|
||||
# define BOOST_ITERATOR_FACADE_INTEROP_HEAD(prefix, op, result_type) \
|
||||
template < \
|
||||
class Derived1, class V1, class TC1, class R1, class D1 \
|
||||
, class Derived2, class V2, class TC2, class R2, class D2 \
|
||||
> \
|
||||
prefix typename mpl::apply2<result_type,Derived1,Derived2>::type \
|
||||
operator op( \
|
||||
iterator_facade<Derived1, V1, TC1, R1, D1> const& lhs \
|
||||
, iterator_facade<Derived2, V2, TC2, R2, D2> const& rhs)
|
||||
# else
|
||||
# define BOOST_ITERATOR_FACADE_INTEROP_HEAD(prefix, op, result_type) \
|
||||
template < \
|
||||
class Derived1, class V1, class TC1, class R1, class D1 \
|
||||
, class Derived2, class V2, class TC2, class R2, class D2 \
|
||||
> \
|
||||
prefix typename detail::enable_if_interoperable< \
|
||||
Derived1, Derived2, result_type \
|
||||
Derived1, Derived2 \
|
||||
, typename mpl::apply2<result_type,Derived1,Derived2>::type \
|
||||
>::type \
|
||||
operator op( \
|
||||
iterator_facade<Derived1, V1, TC1, R1, D1> const& lhs \
|
||||
, iterator_facade<Derived2, V2, TC2, R2, D2> const& rhs)
|
||||
# endif
|
||||
|
||||
# define BOOST_ITERATOR_FACADE_PLUS_HEAD(prefix,args) \
|
||||
template <class Derived, class V, class TC, class R, class D> \
|
||||
@ -244,8 +461,8 @@ namespace boost
|
||||
|
||||
template <class I, class V, class TC, class R, class D> friend class iterator_facade;
|
||||
|
||||
# define BOOST_ITERATOR_FACADE_RELATION(op) \
|
||||
BOOST_ITERATOR_FACADE_INTEROP_HEAD(friend,op, bool);
|
||||
# define BOOST_ITERATOR_FACADE_RELATION(op) \
|
||||
BOOST_ITERATOR_FACADE_INTEROP_HEAD(friend,op, detail::always_bool2);
|
||||
|
||||
BOOST_ITERATOR_FACADE_RELATION(==)
|
||||
BOOST_ITERATOR_FACADE_RELATION(!=)
|
||||
@ -257,7 +474,7 @@ namespace boost
|
||||
# undef BOOST_ITERATOR_FACADE_RELATION
|
||||
|
||||
BOOST_ITERATOR_FACADE_INTEROP_HEAD(
|
||||
friend, -, typename Derived1::difference_type)
|
||||
friend, -, detail::choose_difference_type)
|
||||
;
|
||||
|
||||
BOOST_ITERATOR_FACADE_PLUS_HEAD(
|
||||
@ -268,14 +485,14 @@ namespace boost
|
||||
;
|
||||
|
||||
BOOST_ITERATOR_FACADE_PLUS_HEAD(
|
||||
friend
|
||||
friend
|
||||
, (typename Derived::difference_type
|
||||
, iterator_facade<Derived, V, TC, R, D> const&)
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
# endif
|
||||
|
||||
|
||||
template <class Facade>
|
||||
static typename Facade::reference dereference(Facade const& f)
|
||||
{
|
||||
@ -295,11 +512,17 @@ namespace boost
|
||||
}
|
||||
|
||||
template <class Facade1, class Facade2>
|
||||
static bool equal(Facade1 const& f1, Facade2 const& f2)
|
||||
static bool equal(Facade1 const& f1, Facade2 const& f2, mpl::true_)
|
||||
{
|
||||
return f1.equal(f2);
|
||||
}
|
||||
|
||||
template <class Facade1, class Facade2>
|
||||
static bool equal(Facade1 const& f1, Facade2 const& f2, mpl::false_)
|
||||
{
|
||||
return f2.equal(f1);
|
||||
}
|
||||
|
||||
template <class Facade>
|
||||
static void advance(Facade& f, typename Facade::difference_type n)
|
||||
{
|
||||
@ -307,10 +530,32 @@ namespace boost
|
||||
}
|
||||
|
||||
template <class Facade1, class Facade2>
|
||||
static typename Facade1::difference_type distance_to(
|
||||
Facade1 const& f1, Facade2 const& f2)
|
||||
static typename Facade1::difference_type distance_from(
|
||||
Facade1 const& f1, Facade2 const& f2, mpl::true_)
|
||||
{
|
||||
return f1.distance_to(f2);
|
||||
return -f1.distance_to(f2);
|
||||
}
|
||||
|
||||
template <class Facade1, class Facade2>
|
||||
static typename Facade2::difference_type distance_from(
|
||||
Facade1 const& f1, Facade2 const& f2, mpl::false_)
|
||||
{
|
||||
return f2.distance_to(f1);
|
||||
}
|
||||
|
||||
//
|
||||
// Curiously Recurring Template interface.
|
||||
//
|
||||
template <class I, class V, class TC, class R, class D>
|
||||
static I& derived(iterator_facade<I,V,TC,R,D>& facade)
|
||||
{
|
||||
return *static_cast<I*>(&facade);
|
||||
}
|
||||
|
||||
template <class I, class V, class TC, class R, class D>
|
||||
static I const& derived(iterator_facade<I,V,TC,R,D> const& facade)
|
||||
{
|
||||
return *static_cast<I const*>(&facade);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -335,27 +580,29 @@ namespace boost
|
||||
Value, CategoryOrTraversal, Reference, Difference
|
||||
>::base
|
||||
# undef BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE
|
||||
# endif
|
||||
# endif
|
||||
{
|
||||
private:
|
||||
//
|
||||
// Curiously Recurring Template interface.
|
||||
//
|
||||
typedef Derived derived_t;
|
||||
|
||||
Derived& derived()
|
||||
{
|
||||
return static_cast<Derived&>(*this);
|
||||
return *static_cast<Derived*>(this);
|
||||
}
|
||||
|
||||
Derived const& derived() const
|
||||
Derived const& derived() const
|
||||
{
|
||||
return static_cast<Derived const&>(*this);
|
||||
return *static_cast<Derived const*>(this);
|
||||
}
|
||||
|
||||
typedef detail::iterator_facade_types<
|
||||
Value, CategoryOrTraversal, Reference, Difference
|
||||
> associated_types;
|
||||
|
||||
protected:
|
||||
// For use by derived classes
|
||||
typedef iterator_facade<Derived,Value,Reference,Difference> iterator_facade_;
|
||||
|
||||
public:
|
||||
|
||||
@ -384,15 +631,14 @@ namespace boost
|
||||
>::make(*this->derived());
|
||||
}
|
||||
|
||||
typename detail::operator_brackets_result<Derived,Value,Reference>::type
|
||||
typename detail::operator_brackets_result<Derived,Value,reference>::type
|
||||
operator[](difference_type n) const
|
||||
{
|
||||
typedef detail::iterator_writability_disabled<Value,Reference>
|
||||
not_writable;
|
||||
typedef detail::use_operator_brackets_proxy<Value,Reference> use_proxy;
|
||||
|
||||
return detail::make_operator_brackets_result<Derived>(
|
||||
this->derived() + n
|
||||
, not_writable()
|
||||
, use_proxy()
|
||||
);
|
||||
}
|
||||
|
||||
@ -402,38 +648,42 @@ namespace boost
|
||||
return this->derived();
|
||||
}
|
||||
|
||||
Derived operator++(int)
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
|
||||
typename detail::postfix_increment_result<Derived,Value,Reference,CategoryOrTraversal>::type
|
||||
operator++(int)
|
||||
{
|
||||
Derived tmp(this->derived());
|
||||
typename detail::postfix_increment_result<Derived,Value,Reference,CategoryOrTraversal>::type
|
||||
tmp(this->derived());
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
Derived& operator--()
|
||||
{
|
||||
iterator_core_access::decrement(this->derived());
|
||||
return this->derived();
|
||||
}
|
||||
|
||||
|
||||
Derived operator--(int)
|
||||
{
|
||||
Derived tmp(this->derived());
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
Derived& operator+=(difference_type n)
|
||||
{
|
||||
iterator_core_access::advance(this->derived(), n);
|
||||
return this->derived();
|
||||
}
|
||||
|
||||
|
||||
Derived& operator-=(difference_type n)
|
||||
{
|
||||
iterator_core_access::advance(this->derived(), -n);
|
||||
return this->derived();
|
||||
}
|
||||
|
||||
|
||||
Derived operator-(difference_type x) const
|
||||
{
|
||||
Derived result(this->derived());
|
||||
@ -450,11 +700,29 @@ namespace boost
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
};
|
||||
|
||||
# if !BOOST_WORKAROUND(BOOST_MSVC, == 1200)
|
||||
template <class I, class V, class TC, class R, class D>
|
||||
typename detail::postfix_increment_result<I,V,R,TC>::type
|
||||
operator++(
|
||||
iterator_facade<I,V,TC,R,D>& i
|
||||
, int
|
||||
)
|
||||
{
|
||||
typename detail::postfix_increment_result<I,V,R,TC>::type
|
||||
tmp(*static_cast<I*>(&i));
|
||||
|
||||
++i;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
# endif
|
||||
|
||||
|
||||
//
|
||||
// Operator implementation. The library supplied operators
|
||||
// Comparison operator implementation. The library supplied operators
|
||||
// enables the user to provide fully interoperable constant/mutable
|
||||
// iterator types. I.e. the library provides all operators
|
||||
// for all mutable/constant iterator combinations.
|
||||
@ -463,12 +731,12 @@ namespace boost
|
||||
// iterators is not required by the standard for container iterators.
|
||||
// All the standard asks for is a conversion mutable -> constant.
|
||||
// Most standard library implementations nowadays provide fully interoperable
|
||||
// iterator implementations, but there are still heavily used implementations
|
||||
// that do not provide them. (Actually it's even worse, they do not provide
|
||||
// iterator implementations, but there are still heavily used implementations
|
||||
// that do not provide them. (Actually it's even worse, they do not provide
|
||||
// them for only a few iterators.)
|
||||
//
|
||||
// ?? Maybe a BOOST_ITERATOR_NO_FULL_INTEROPERABILITY macro should
|
||||
// enable the user to turn off mixed type operators
|
||||
// enable the user to turn off mixed type operators
|
||||
//
|
||||
// The library takes care to provide only the right operator overloads.
|
||||
// I.e.
|
||||
@ -486,7 +754,7 @@ namespace boost
|
||||
// deficiencies result in less strict error checking and more obscure
|
||||
// error messages, functionality is not affected.
|
||||
//
|
||||
// For full operation compiler support for "Substitution Failure Is Not An Error"
|
||||
// For full operation compiler support for "Substitution Failure Is Not An Error"
|
||||
// (aka. enable_if) and boost::is_convertible is required.
|
||||
//
|
||||
// The following problems occur if support is lacking.
|
||||
@ -505,7 +773,7 @@ namespace boost
|
||||
// // false overloads from the templated conversion constructor
|
||||
// // of AdaptorA.
|
||||
//
|
||||
// a1 == a2;
|
||||
// a1 == a2;
|
||||
// ----------------
|
||||
//
|
||||
// AdaptorA<Iterator> a;
|
||||
@ -520,23 +788,30 @@ namespace boost
|
||||
// ----------------
|
||||
//
|
||||
|
||||
# define BOOST_ITERATOR_FACADE_INTEROP(op, result_type, condition, return_prefix, base_op) \
|
||||
BOOST_ITERATOR_FACADE_INTEROP_HEAD(inline, op, result_type) \
|
||||
{ \
|
||||
/* For those compilers that do not support enable_if */ \
|
||||
BOOST_STATIC_ASSERT(( \
|
||||
is_interoperable< Derived1, Derived2 >::value \
|
||||
&& condition \
|
||||
)); \
|
||||
return_prefix iterator_core_access::base_op( \
|
||||
static_cast<Derived2 const&>(rhs), static_cast<Derived1 const&>(lhs)); \
|
||||
}
|
||||
# ifdef BOOST_NO_ONE_WAY_ITERATOR_INTEROP
|
||||
# define BOOST_ITERATOR_CONVERTIBLE(a,b) mpl::true_()
|
||||
# else
|
||||
# define BOOST_ITERATOR_CONVERTIBLE(a,b) is_convertible<a,b>()
|
||||
# endif
|
||||
|
||||
# define BOOST_ITERATOR_FACADE_INTEROP(op, result_type, return_prefix, base_op) \
|
||||
BOOST_ITERATOR_FACADE_INTEROP_HEAD(inline, op, result_type) \
|
||||
{ \
|
||||
/* For those compilers that do not support enable_if */ \
|
||||
BOOST_STATIC_ASSERT(( \
|
||||
is_interoperable< Derived1, Derived2 >::value \
|
||||
)); \
|
||||
return_prefix iterator_core_access::base_op( \
|
||||
static_cast<Derived1 const&>(lhs) \
|
||||
, static_cast<Derived2 const&>(rhs) \
|
||||
, BOOST_ITERATOR_CONVERTIBLE(Derived2,Derived1) \
|
||||
); \
|
||||
}
|
||||
|
||||
# define BOOST_ITERATOR_FACADE_RELATION(op, return_prefix, base_op) \
|
||||
BOOST_ITERATOR_FACADE_INTEROP( \
|
||||
op \
|
||||
, bool \
|
||||
, true \
|
||||
, detail::always_bool2 \
|
||||
, return_prefix \
|
||||
, base_op \
|
||||
)
|
||||
@ -544,25 +819,22 @@ namespace boost
|
||||
BOOST_ITERATOR_FACADE_RELATION(==, return, equal)
|
||||
BOOST_ITERATOR_FACADE_RELATION(!=, return !, equal)
|
||||
|
||||
BOOST_ITERATOR_FACADE_RELATION(<, return 0 >, distance_to)
|
||||
BOOST_ITERATOR_FACADE_RELATION(>, return 0 <, distance_to)
|
||||
BOOST_ITERATOR_FACADE_RELATION(<=, return 0 >=, distance_to)
|
||||
BOOST_ITERATOR_FACADE_RELATION(>=, return 0 <=, distance_to)
|
||||
BOOST_ITERATOR_FACADE_RELATION(<, return 0 >, distance_from)
|
||||
BOOST_ITERATOR_FACADE_RELATION(>, return 0 <, distance_from)
|
||||
BOOST_ITERATOR_FACADE_RELATION(<=, return 0 >=, distance_from)
|
||||
BOOST_ITERATOR_FACADE_RELATION(>=, return 0 <=, distance_from)
|
||||
# undef BOOST_ITERATOR_FACADE_RELATION
|
||||
|
||||
// operator- requires an additional part in the static assertion
|
||||
BOOST_ITERATOR_FACADE_INTEROP(
|
||||
-
|
||||
, typename Derived1::difference_type
|
||||
, (is_same<
|
||||
BOOST_DEDUCED_TYPENAME Derived1::difference_type
|
||||
, BOOST_DEDUCED_TYPENAME Derived2::difference_type
|
||||
>::value)
|
||||
, detail::choose_difference_type
|
||||
, return
|
||||
, distance_to )
|
||||
, distance_from
|
||||
)
|
||||
# undef BOOST_ITERATOR_FACADE_INTEROP
|
||||
# undef BOOST_ITERATOR_FACADE_INTEROP_HEAD
|
||||
|
||||
|
||||
# define BOOST_ITERATOR_FACADE_PLUS(args) \
|
||||
BOOST_ITERATOR_FACADE_PLUS_HEAD(inline, args) \
|
||||
{ \
|
||||
@ -581,7 +853,7 @@ BOOST_ITERATOR_FACADE_PLUS((
|
||||
))
|
||||
# undef BOOST_ITERATOR_FACADE_PLUS
|
||||
# undef BOOST_ITERATOR_FACADE_PLUS_HEAD
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/iterator/detail/config_undef.hpp>
|
||||
|
@ -28,9 +28,36 @@
|
||||
# include <boost/iterator/is_lvalue_iterator.hpp>
|
||||
|
||||
# include <boost/iterator/detail/config_def.hpp>
|
||||
# include <boost/detail/is_incrementable.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
|
||||
// Do separate tests for *i++ so we can treat, e.g., smart pointers,
|
||||
// as readable and/or writable iterators.
|
||||
template <class Iterator, class T>
|
||||
void readable_iterator_traversal_test(Iterator i1, T v, mpl::true_)
|
||||
{
|
||||
T v2 = *i1++;
|
||||
assert(v == v2);
|
||||
}
|
||||
|
||||
template <class Iterator, class T>
|
||||
void readable_iterator_traversal_test(const Iterator i1, T v, mpl::false_)
|
||||
{}
|
||||
|
||||
template <class Iterator, class T>
|
||||
void writable_iterator_traversal_test(Iterator i1, T v, mpl::true_)
|
||||
{
|
||||
++i1; // we just wrote into that position
|
||||
*i1++ = v;
|
||||
}
|
||||
|
||||
template <class Iterator, class T>
|
||||
void writable_iterator_traversal_test(const Iterator i1, T v, mpl::false_)
|
||||
{}
|
||||
|
||||
|
||||
// Preconditions: *i == v
|
||||
template <class Iterator, class T>
|
||||
void readable_iterator_test(const Iterator i1, T v)
|
||||
@ -45,6 +72,8 @@ void readable_iterator_test(const Iterator i1, T v)
|
||||
assert(v2 == v);
|
||||
|
||||
# if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
readable_iterator_traversal_test(i1, v, detail::is_postfix_incrementable<Iterator>());
|
||||
|
||||
// I think we don't really need this as it checks the same things as
|
||||
// the above code.
|
||||
BOOST_STATIC_ASSERT(is_readable_iterator<Iterator>::value);
|
||||
@ -52,10 +81,18 @@ void readable_iterator_test(const Iterator i1, T v)
|
||||
}
|
||||
|
||||
template <class Iterator, class T>
|
||||
void writable_iterator_test(Iterator i, T v)
|
||||
void writable_iterator_test(Iterator i, T v, T v2)
|
||||
{
|
||||
Iterator i2(i); // Copy Constructible
|
||||
*i2 = v;
|
||||
|
||||
# if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
writable_iterator_traversal_test(
|
||||
i, v2, mpl::and_<
|
||||
detail::is_incrementable<Iterator>
|
||||
, detail::is_postfix_incrementable<Iterator>
|
||||
>());
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class Iterator>
|
||||
|
@ -18,64 +18,40 @@ namespace boost
|
||||
{
|
||||
|
||||
template< class ElementIterator
|
||||
, class IndexIterator
|
||||
, class ValueT = use_default
|
||||
, class CategoryT = use_default
|
||||
, class ReferenceT = use_default
|
||||
, class DifferenceT = use_default >
|
||||
, class IndexIterator>
|
||||
class permutation_iterator
|
||||
: public iterator_adaptor<
|
||||
permutation_iterator<ElementIterator, IndexIterator, ValueT, CategoryT, ReferenceT, DifferenceT>
|
||||
, ElementIterator, ValueT, CategoryT, ReferenceT, DifferenceT >
|
||||
permutation_iterator<ElementIterator, IndexIterator>
|
||||
, IndexIterator, typename detail::iterator_traits<ElementIterator>::value_type
|
||||
, use_default, typename detail::iterator_traits<ElementIterator>::reference>
|
||||
{
|
||||
typedef iterator_adaptor<
|
||||
permutation_iterator<ElementIterator, IndexIterator, ValueT, CategoryT, ReferenceT, DifferenceT>
|
||||
, ElementIterator, ValueT, CategoryT, ReferenceT, DifferenceT > super_t;
|
||||
permutation_iterator<ElementIterator, IndexIterator>
|
||||
, IndexIterator, typename detail::iterator_traits<ElementIterator>::value_type
|
||||
, use_default, typename detail::iterator_traits<ElementIterator>::reference> super_t;
|
||||
|
||||
friend class iterator_core_access;
|
||||
|
||||
public:
|
||||
permutation_iterator() : order_it_() {}
|
||||
permutation_iterator() : m_elt_iter() {}
|
||||
|
||||
explicit permutation_iterator(ElementIterator x, IndexIterator y)
|
||||
: super_t(x), order_it_(y) {}
|
||||
: super_t(y), m_elt_iter(x) {}
|
||||
|
||||
template<class OtherElementIterator, class OtherIndexIterator, class V, class C, class R, class D >
|
||||
template<class OtherElementIterator, class OtherIndexIterator>
|
||||
permutation_iterator(
|
||||
permutation_iterator<OtherElementIterator, OtherIndexIterator, V, C, R, D> const& r
|
||||
permutation_iterator<OtherElementIterator, OtherIndexIterator> const& r
|
||||
, typename enable_if_convertible<OtherElementIterator, ElementIterator>::type* = 0
|
||||
, typename enable_if_convertible<OtherIndexIterator, IndexIterator>::type* = 0
|
||||
)
|
||||
: super_t(r.base())
|
||||
: super_t(r.base()), m_elt_iter(r.m_elt_iter)
|
||||
{}
|
||||
|
||||
private:
|
||||
typename super_t::reference dereference() const
|
||||
{ return *(this->base() + *this->order_it_); }
|
||||
|
||||
void increment() { ++this->order_it_; }
|
||||
void decrement() { --this->order_it_; }
|
||||
{ return *(m_elt_iter + *this->base()); }
|
||||
|
||||
void advance(typename super_t::difference_type n)
|
||||
{
|
||||
std::advance( order_it_, n );
|
||||
}
|
||||
|
||||
template<class OtherElementIterator, class OtherIndexIterator, class V, class C, class R, class D >
|
||||
typename super_t::difference_type
|
||||
distance_to( permutation_iterator<OtherElementIterator, OtherIndexIterator, V, C, R, D> const& y ) const
|
||||
{
|
||||
return std::distance( this->order_it_, y.order_it_ );
|
||||
}
|
||||
|
||||
template<class OtherElementIterator, class OtherIndexIterator, class V, class C, class R, class D >
|
||||
bool
|
||||
equal( permutation_iterator<OtherElementIterator, OtherIndexIterator, V, C, R, D> const& y ) const
|
||||
{
|
||||
return( y.order_it_ == this->order_it_ );
|
||||
}
|
||||
|
||||
IndexIterator order_it_;
|
||||
ElementIterator m_elt_iter;
|
||||
};
|
||||
|
||||
|
||||
|
@ -24,8 +24,13 @@
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
|
||||
# include <boost/type_traits/is_base_and_derived.hpp>
|
||||
|
||||
#endif
|
||||
#include <boost/iterator/detail/config_def.hpp>
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template <class UnaryFunction, class Iterator, class Reference = use_default, class Value = use_default>
|
||||
@ -111,12 +116,20 @@ namespace boost
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class OtherIterator>
|
||||
template<
|
||||
class OtherUnaryFunction
|
||||
, class OtherIterator
|
||||
, class OtherReference
|
||||
, class OtherValue>
|
||||
transform_iterator(
|
||||
transform_iterator<UnaryFunction, OtherIterator, Reference, Value> const& t
|
||||
transform_iterator<OtherUnaryFunction, OtherIterator, OtherReference, OtherValue> const& t
|
||||
, typename enable_if_convertible<OtherIterator, Iterator>::type* = 0
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1310)
|
||||
, typename enable_if_convertible<OtherUnaryFunction, UnaryFunction>::type* = 0
|
||||
#endif
|
||||
)
|
||||
: super_t(t.base()), m_f(t.functor()) {}
|
||||
: super_t(t.base()), m_f(t.functor())
|
||||
{}
|
||||
|
||||
UnaryFunction functor() const
|
||||
{ return m_f; }
|
||||
|
@ -32,10 +32,6 @@
|
||||
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
#if BOOST_WORKAROUND(__GNUC__, == 2) || BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
# include <boost/type_traits/remove_cv.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/apply.hpp>
|
||||
@ -106,21 +102,13 @@ namespace boost {
|
||||
template<typename Iterator>
|
||||
struct apply
|
||||
{
|
||||
#if BOOST_WORKAROUND(__GNUC__, == 2) || BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
typedef typename
|
||||
iterator_traits<
|
||||
typename boost::remove_cv<Iterator>::type
|
||||
>::reference
|
||||
iterator_traits<Iterator>::reference
|
||||
type;
|
||||
#else
|
||||
typedef typename
|
||||
iterator_traits<Iterator>::reference
|
||||
type;
|
||||
#endif
|
||||
};
|
||||
|
||||
template<typename Iterator>
|
||||
typename apply<Iterator>::type operator()(Iterator& it)
|
||||
typename apply<Iterator>::type operator()(Iterator const& it)
|
||||
{ return *it; }
|
||||
};
|
||||
|
||||
|
13
include/boost/iterator_adaptors.hpp
Normal file
13
include/boost/iterator_adaptors.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
// 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.
|
||||
|
||||
#ifndef BOOST_ITERATOR_ADAPTOR_13062003HK_HPP
|
||||
#define BOOST_ITERATOR_ADAPTOR_13062003HK_HPP
|
||||
|
||||
#define BOOST_ITERATOR_ADAPTORS_VERSION 0x0200
|
||||
#include <boost/iterator/iterator_adaptor.hpp>
|
||||
|
||||
#endif // BOOST_ITERATOR_ADAPTOR_13062003HK_HPP
|
75
include/boost/pending/detail/int_iterator.hpp
Normal file
75
include/boost/pending/detail/int_iterator.hpp
Normal file
@ -0,0 +1,75 @@
|
||||
// (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.
|
||||
|
||||
#ifndef BOOST_INT_ITERATOR_H
|
||||
#define BOOST_INT_ITERATOR_H
|
||||
|
||||
#include <boost/iterator.hpp>
|
||||
#if !defined BOOST_MSVC
|
||||
#include <boost/operators.hpp>
|
||||
#endif
|
||||
#include <iostream>
|
||||
//using namespace std;
|
||||
|
||||
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||
namespace boost {
|
||||
#endif
|
||||
|
||||
// this should use random_access_iterator_helper but I've had
|
||||
// VC++ portablility problems with that. -JGS
|
||||
template <class IntT>
|
||||
class int_iterator
|
||||
{
|
||||
typedef int_iterator self;
|
||||
public:
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
typedef IntT value_type;
|
||||
typedef IntT& reference;
|
||||
typedef IntT* pointer;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
|
||||
inline int_iterator() : _i(0) { }
|
||||
inline int_iterator(IntT i) : _i(i) { }
|
||||
inline int_iterator(const self& x) : _i(x._i) { }
|
||||
inline self& operator=(const self& x) { _i = x._i; return *this; }
|
||||
inline IntT operator*() { return _i; }
|
||||
inline IntT operator[](IntT n) { return _i + n; }
|
||||
inline self& operator++() { ++_i; return *this; }
|
||||
inline self operator++(int) { self t = *this; ++_i; return t; }
|
||||
inline self& operator+=(IntT n) { _i += n; return *this; }
|
||||
inline self operator+(IntT n) { self t = *this; t += n; return t; }
|
||||
inline self& operator--() { --_i; return *this; }
|
||||
inline self operator--(int) { self t = *this; --_i; return t; }
|
||||
inline self& operator-=(IntT n) { _i -= n; return *this; }
|
||||
inline IntT operator-(const self& x) const { return _i - x._i; }
|
||||
inline bool operator==(const self& x) const { return _i == x._i; }
|
||||
// vc++ had a problem finding != in random_access_iterator_helper
|
||||
// need to look into this... for now implementing everything here -JGS
|
||||
inline bool operator!=(const self& x) const { return _i != x._i; }
|
||||
inline bool operator<(const self& x) const { return _i < x._i; }
|
||||
inline bool operator<=(const self& x) const { return _i <= x._i; }
|
||||
inline bool operator>(const self& x) const { return _i > x._i; }
|
||||
inline bool operator>=(const self& x) const { return _i >= x._i; }
|
||||
protected:
|
||||
IntT _i;
|
||||
};
|
||||
|
||||
template <class IntT>
|
||||
inline int_iterator<IntT>
|
||||
operator+(IntT n, int_iterator<IntT> t) { t += n; return t; }
|
||||
|
||||
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||
} /* namespace boost */
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_NO_OPERATORS_IN_NAMESPACE
|
||||
namespace boost {
|
||||
using ::int_iterator;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* BOOST_INT_ITERATOR_H */
|
60
include/boost/pending/integer_range.hpp
Normal file
60
include/boost/pending/integer_range.hpp
Normal file
@ -0,0 +1,60 @@
|
||||
// (C) Copyright David Abrahams and Jeremy Siek 2000-2001. 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:
|
||||
// 04 Jan 2001 Factored counting_iterator stuff into
|
||||
// boost/counting_iterator.hpp (David Abrahams)
|
||||
|
||||
#ifndef BOOST_INTEGER_RANGE_HPP_
|
||||
#define BOOST_INTEGER_RANGE_HPP_
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/iterator/counting_iterator.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
namespace boost {
|
||||
|
||||
//=============================================================================
|
||||
// Counting Iterator and Integer Range Class
|
||||
|
||||
template <class IntegerType>
|
||||
struct integer_range {
|
||||
typedef counting_iterator<IntegerType> iterator;
|
||||
|
||||
typedef iterator const_iterator;
|
||||
typedef IntegerType value_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef IntegerType reference;
|
||||
typedef IntegerType const_reference;
|
||||
typedef const IntegerType* pointer;
|
||||
typedef const IntegerType* const_pointer;
|
||||
typedef IntegerType size_type;
|
||||
|
||||
integer_range(IntegerType start, IntegerType finish)
|
||||
: m_start(start), m_finish(finish) { }
|
||||
|
||||
iterator begin() const { return iterator(m_start); }
|
||||
iterator end() const { return iterator(m_finish); }
|
||||
size_type size() const { return m_finish - m_start; }
|
||||
bool empty() const { return m_finish == m_start; }
|
||||
void swap(integer_range& x) {
|
||||
std::swap(m_start, x.m_start);
|
||||
std::swap(m_finish, x.m_finish);
|
||||
}
|
||||
protected:
|
||||
IntegerType m_start, m_finish;
|
||||
};
|
||||
|
||||
template <class IntegerType>
|
||||
inline integer_range<IntegerType>
|
||||
make_integer_range(IntegerType first, IntegerType last)
|
||||
{
|
||||
return integer_range<IntegerType>(first, last);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_INTEGER_RANGE_HPP_
|
7
include/boost/pending/iterator_adaptors.hpp
Normal file
7
include/boost/pending/iterator_adaptors.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
// Copyright David Abrahams 2003. 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.
|
||||
|
||||
#include <boost/iterator_adaptors.hpp>
|
269
include/boost/pending/iterator_tests.hpp
Normal file
269
include/boost/pending/iterator_tests.hpp
Normal file
@ -0,0 +1,269 @@
|
||||
// Copyright David Abrahams and Jeremy Siek 2003. 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.
|
||||
#ifndef BOOST_ITERATOR_TESTS_HPP
|
||||
# define BOOST_ITERATOR_TESTS_HPP
|
||||
|
||||
// This is meant to be the beginnings of a comprehensive, generic
|
||||
// test suite for STL concepts such as iterators and containers.
|
||||
//
|
||||
// Revision History:
|
||||
// 28 Apr 2002 Fixed input iterator requirements.
|
||||
// For a == b a++ == b++ is no longer required.
|
||||
// See 24.1.1/3 for details.
|
||||
// (Thomas Witt)
|
||||
// 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 <assert.h>
|
||||
# include <boost/type_traits.hpp>
|
||||
# include <boost/static_assert.hpp>
|
||||
# include <boost/concept_archetype.hpp> // for detail::dummy_constructor
|
||||
# include <boost/implicit_cast.hpp>
|
||||
# include <boost/type_traits/broken_compiler_spec.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
// use this for the value type
|
||||
struct dummyT {
|
||||
dummyT() { }
|
||||
dummyT(detail::dummy_constructor) { }
|
||||
dummyT(int x) : m_x(x) { }
|
||||
int foo() const { return m_x; }
|
||||
bool operator==(const dummyT& d) const { return m_x == d.m_x; }
|
||||
int m_x;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
BOOST_TT_BROKEN_COMPILER_SPEC(boost::dummyT)
|
||||
|
||||
namespace boost {
|
||||
|
||||
// Tests whether type Iterator satisfies the requirements for a
|
||||
// TrivialIterator.
|
||||
// Preconditions: i != j, *i == val
|
||||
template <class Iterator, class T>
|
||||
void trivial_iterator_test(const Iterator i, const Iterator j, T val)
|
||||
{
|
||||
Iterator k;
|
||||
assert(i == i);
|
||||
assert(j == j);
|
||||
assert(i != j);
|
||||
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
T v = *i;
|
||||
#else
|
||||
typename std::iterator_traits<Iterator>::value_type v = *i;
|
||||
#endif
|
||||
assert(v == val);
|
||||
#if 0
|
||||
// hmm, this will give a warning for transform_iterator... perhaps
|
||||
// this should be separated out into a stand-alone test since there
|
||||
// are several situations where it can't be used, like for
|
||||
// integer_range::iterator.
|
||||
assert(v == i->foo());
|
||||
#endif
|
||||
k = i;
|
||||
assert(k == k);
|
||||
assert(k == i);
|
||||
assert(k != j);
|
||||
assert(*k == val);
|
||||
}
|
||||
|
||||
|
||||
// Preconditions: i != j
|
||||
template <class Iterator, class T>
|
||||
void mutable_trivial_iterator_test(const Iterator i, const Iterator j, T val)
|
||||
{
|
||||
*i = val;
|
||||
trivial_iterator_test(i, j, val);
|
||||
}
|
||||
|
||||
|
||||
// Preconditions: *i == v1, *++i == v2
|
||||
template <class Iterator, class T>
|
||||
void input_iterator_test(Iterator i, T v1, T v2)
|
||||
{
|
||||
Iterator i1(i);
|
||||
|
||||
assert(i == i1);
|
||||
assert(!(i != i1));
|
||||
|
||||
// I can see no generic way to create an input iterator
|
||||
// that is in the domain of== of i and != i.
|
||||
// The following works for istream_iterator but is not
|
||||
// guaranteed to work for arbitrary input iterators.
|
||||
//
|
||||
// Iterator i2;
|
||||
//
|
||||
// assert(i != i2);
|
||||
// assert(!(i == i2));
|
||||
|
||||
assert(*i1 == v1);
|
||||
assert(*i == v1);
|
||||
|
||||
// we cannot test for equivalence of (void)++i & (void)i++
|
||||
// as i is only guaranteed to be single pass.
|
||||
assert(*i++ == v1);
|
||||
|
||||
i1 = i;
|
||||
|
||||
assert(i == i1);
|
||||
assert(!(i != i1));
|
||||
|
||||
assert(*i1 == v2);
|
||||
assert(*i == v2);
|
||||
|
||||
// i is dereferencable, so it must be incrementable.
|
||||
++i;
|
||||
|
||||
// how to test for operator-> ?
|
||||
}
|
||||
|
||||
// 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>
|
||||
void forward_iterator_test(Iterator i, T v1, T v2)
|
||||
{
|
||||
input_iterator_test(i, v1, v2);
|
||||
|
||||
Iterator i1 = i, i2 = i;
|
||||
|
||||
assert(i == i1++);
|
||||
assert(i != ++i2);
|
||||
|
||||
trivial_iterator_test(i, i1, v1);
|
||||
trivial_iterator_test(i, i2, v1);
|
||||
|
||||
++i;
|
||||
assert(i == i1);
|
||||
assert(i == i2);
|
||||
++i1;
|
||||
++i2;
|
||||
|
||||
trivial_iterator_test(i, i1, v2);
|
||||
trivial_iterator_test(i, i2, 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
|
||||
template <class Iterator, class T>
|
||||
void bidirectional_iterator_test(Iterator i, T v1, T v2)
|
||||
{
|
||||
forward_iterator_test(i, v1, v2);
|
||||
++i;
|
||||
|
||||
Iterator i1 = i, i2 = i;
|
||||
|
||||
assert(i == i1--);
|
||||
assert(i != --i2);
|
||||
|
||||
trivial_iterator_test(i, i1, v2);
|
||||
trivial_iterator_test(i, i2, v2);
|
||||
|
||||
--i;
|
||||
assert(i == i1);
|
||||
assert(i == i2);
|
||||
++i1;
|
||||
++i2;
|
||||
|
||||
trivial_iterator_test(i, i1, v1);
|
||||
trivial_iterator_test(i, i2, v1);
|
||||
}
|
||||
|
||||
// mutable_bidirectional_iterator_test
|
||||
|
||||
template <class U> struct undefined;
|
||||
|
||||
// Preconditions: [i,i+N) is a valid range
|
||||
template <class Iterator, class TrueVals>
|
||||
void random_access_iterator_test(Iterator i, int N, TrueVals vals)
|
||||
{
|
||||
bidirectional_iterator_test(i, vals[0], vals[1]);
|
||||
const Iterator j = i;
|
||||
int c;
|
||||
|
||||
typedef typename boost::detail::iterator_traits<Iterator>::value_type value_type;
|
||||
|
||||
for (c = 0; c < N-1; ++c) {
|
||||
assert(i == j + c);
|
||||
assert(*i == vals[c]);
|
||||
assert(*i == boost::implicit_cast<value_type>(j[c]));
|
||||
assert(*i == *(j + c));
|
||||
assert(*i == *(c + j));
|
||||
++i;
|
||||
assert(i > j);
|
||||
assert(i >= j);
|
||||
assert(j <= i);
|
||||
assert(j < i);
|
||||
}
|
||||
|
||||
Iterator k = j + N - 1;
|
||||
for (c = 0; c < N-1; ++c) {
|
||||
assert(i == k - c);
|
||||
assert(*i == vals[N - 1 - c]);
|
||||
assert(*i == boost::implicit_cast<value_type>(j[N - 1 - c]));
|
||||
Iterator q = k - c;
|
||||
assert(*i == *q);
|
||||
assert(i > j);
|
||||
assert(i >= j);
|
||||
assert(j <= i);
|
||||
assert(j < i);
|
||||
--i;
|
||||
}
|
||||
}
|
||||
|
||||
// Precondition: i != j
|
||||
template <class Iterator, class ConstIterator>
|
||||
void const_nonconst_iterator_test(Iterator i, ConstIterator j)
|
||||
{
|
||||
assert(i != j);
|
||||
assert(j != i);
|
||||
|
||||
ConstIterator k(i);
|
||||
assert(k == i);
|
||||
assert(i == k);
|
||||
|
||||
k = i;
|
||||
assert(k == i);
|
||||
assert(i == k);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ITERATOR_TESTS_HPP
|
68
include/boost/pointee.hpp
Executable file
68
include/boost/pointee.hpp
Executable file
@ -0,0 +1,68 @@
|
||||
// Copyright David Abrahams 2004. Use, modification and distribution is
|
||||
// subject to the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
#ifndef POINTEE_DWA200415_HPP
|
||||
# define POINTEE_DWA200415_HPP
|
||||
|
||||
// dereferenceable_traits provides access to the value_type and
|
||||
// reference of a Dereferenceable type.
|
||||
|
||||
# include <boost/detail/is_incrementable.hpp>
|
||||
# include <boost/iterator/iterator_traits.hpp>
|
||||
# include <boost/type_traits/add_const.hpp>
|
||||
# include <boost/type_traits/remove_cv.hpp>
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/mpl/apply_if.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class P>
|
||||
struct smart_ptr_pointee
|
||||
{
|
||||
typedef typename P::element_type type;
|
||||
};
|
||||
|
||||
template <class Iterator>
|
||||
struct iterator_pointee
|
||||
{
|
||||
typedef typename iterator_traits<Iterator>::value_type value_type;
|
||||
|
||||
struct impl
|
||||
{
|
||||
template <class T>
|
||||
static char test(T const&);
|
||||
|
||||
static char (& test(value_type&) )[2];
|
||||
|
||||
static Iterator& x;
|
||||
};
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, is_constant = sizeof(impl::test(*impl::x)) == 1);
|
||||
|
||||
typedef typename mpl::if_c<
|
||||
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
::boost::detail::iterator_pointee<Iterator>::is_constant
|
||||
# else
|
||||
is_constant
|
||||
# endif
|
||||
, typename add_const<value_type>::type
|
||||
, value_type
|
||||
>::type type;
|
||||
};
|
||||
}
|
||||
|
||||
template <class P>
|
||||
struct pointee
|
||||
: mpl::apply_if<
|
||||
detail::is_incrementable<P>
|
||||
, detail::iterator_pointee<P>
|
||||
, detail::smart_ptr_pointee<P>
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // POINTEE_DWA200415_HPP
|
62
include/boost/shared_container_iterator.hpp
Normal file
62
include/boost/shared_container_iterator.hpp
Normal file
@ -0,0 +1,62 @@
|
||||
// (C) Copyright Ronald Garcia 2002. 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/libs/utility/shared_container_iterator.html for documentation.
|
||||
|
||||
#ifndef SHARED_CONTAINER_ITERATOR_RG08102002_HPP
|
||||
#define SHARED_CONTAINER_ITERATOR_RG08102002_HPP
|
||||
|
||||
#include "boost/iterator_adaptors.hpp"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
#include <utility>
|
||||
|
||||
namespace boost {
|
||||
|
||||
template <typename Container>
|
||||
class shared_container_iterator : public iterator_adaptor<
|
||||
shared_container_iterator<Container>,
|
||||
typename Container::iterator> {
|
||||
|
||||
typedef iterator_adaptor<
|
||||
shared_container_iterator<Container>,
|
||||
typename Container::iterator> super_t;
|
||||
|
||||
typedef typename Container::iterator iterator_t;
|
||||
typedef boost::shared_ptr<Container> container_ref_t;
|
||||
|
||||
container_ref_t container_ref;
|
||||
public:
|
||||
shared_container_iterator() { }
|
||||
|
||||
shared_container_iterator(iterator_t const& x,container_ref_t const& c) :
|
||||
super_t(x), container_ref(c) { }
|
||||
|
||||
|
||||
};
|
||||
|
||||
template <typename Container>
|
||||
shared_container_iterator<Container>
|
||||
make_shared_container_iterator(typename Container::iterator iter,
|
||||
boost::shared_ptr<Container> const& container) {
|
||||
typedef shared_container_iterator<Container> iterator;
|
||||
return iterator(iter,container);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename Container>
|
||||
std::pair<
|
||||
shared_container_iterator<Container>,
|
||||
shared_container_iterator<Container> >
|
||||
make_shared_container_range(boost::shared_ptr<Container> const& container) {
|
||||
return
|
||||
std::make_pair(
|
||||
make_shared_container_iterator(container->begin(),container),
|
||||
make_shared_container_iterator(container->end(),container));
|
||||
}
|
||||
|
||||
|
||||
} // namespace boost
|
||||
#endif // SHARED_CONTAINER_ITERATOR_RG08102002_HPP
|
50
test/Jamfile
50
test/Jamfile
@ -1,50 +0,0 @@
|
||||
# Copyright David Abrahams 2003. 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.
|
||||
|
||||
subproject libs/iterator/test ;
|
||||
|
||||
import testing ;
|
||||
|
||||
test-suite iterator
|
||||
:
|
||||
# These first two tests will run last, and are expected to fail
|
||||
# for many less-capable compilers.
|
||||
|
||||
[ compile-fail interoperable_fail.cpp ]
|
||||
# test uses expected success, so that we catch unrelated
|
||||
# compilation problems.
|
||||
[ run is_convertible_fail.cpp ]
|
||||
|
||||
[ run zip_iterator_test.cpp ]
|
||||
|
||||
# These tests should work for just about everything.
|
||||
[ compile is_lvalue_iterator.cpp ]
|
||||
[ compile is_readable_iterator.cpp ]
|
||||
|
||||
[ run unit_tests.cpp ]
|
||||
[ run concept_tests.cpp ]
|
||||
[ run iterator_adaptor_cc.cpp ]
|
||||
[ run iterator_adaptor_test.cpp ]
|
||||
[ compile iterator_archetype_cc.cpp ]
|
||||
[ run transform_iterator_test.cpp ]
|
||||
[ run indirect_iterator_test.cpp ]
|
||||
[ run filter_iterator_test.cpp ]
|
||||
[ run reverse_iterator_test.cpp ]
|
||||
[ run counting_iterator_test.cpp ]
|
||||
[ run permutation_iterator_test.cpp : : : # <stlport-iostream>on
|
||||
]
|
||||
|
||||
[ run ../../utility/iterator_adaptor_examples.cpp ]
|
||||
[ run ../../utility/counting_iterator_example.cpp ]
|
||||
[ run ../../utility/filter_iterator_example.cpp ]
|
||||
[ run ../../utility/fun_out_iter_example.cpp ]
|
||||
[ run ../../utility/indirect_iterator_example.cpp ]
|
||||
[ run ../../utility/projection_iterator_example.cpp ]
|
||||
[ run ../../utility/reverse_iterator_example.cpp ]
|
||||
[ run ../../utility/transform_iterator_example.cpp ]
|
||||
[ run ../../utility/iterator_traits_test.cpp ]
|
||||
|
||||
;
|
@ -1,44 +0,0 @@
|
||||
# Copyright David Abrahams 2003. 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.
|
||||
|
||||
import testing ;
|
||||
|
||||
test-suite iterator
|
||||
:
|
||||
# These first two tests will run last, and are expected to fail
|
||||
# for many less-capable compilers.
|
||||
|
||||
[ compile-fail interoperable_fail.cpp ]
|
||||
# test uses expected success, so that we catch unrelated
|
||||
# compilation problems.
|
||||
[ run is_convertible_fail.cpp ]
|
||||
|
||||
# These tests should work for just about everything.
|
||||
[ run unit_tests.cpp ]
|
||||
[ run concept_tests.cpp ]
|
||||
[ run iterator_adaptor_cc.cpp ]
|
||||
[ run iterator_adaptor_test.cpp ]
|
||||
[ compile iterator_archetype_cc.cpp ]
|
||||
[ run transform_iterator_test.cpp ]
|
||||
[ run indirect_iterator_test.cpp ]
|
||||
[ run filter_iterator_test.cpp ]
|
||||
[ run reverse_iterator_test.cpp ]
|
||||
[ run counting_iterator_test.cpp ]
|
||||
[ run permutation_iterator_test.cpp : : : # <stlport-iostream>on
|
||||
]
|
||||
[ run zip_iterator_test.cpp ]
|
||||
|
||||
[ run ../../utility/iterator_adaptor_examples.cpp ]
|
||||
[ run ../../utility/counting_iterator_example.cpp ]
|
||||
[ run ../../utility/filter_iterator_example.cpp ]
|
||||
[ run ../../utility/fun_out_iter_example.cpp ]
|
||||
[ run ../../utility/indirect_iterator_example.cpp ]
|
||||
[ run ../../utility/projection_iterator_example.cpp ]
|
||||
[ run ../../utility/reverse_iterator_example.cpp ]
|
||||
[ run ../../utility/transform_iterator_example.cpp ]
|
||||
[ run ../../utility/iterator_traits_test.cpp ]
|
||||
|
||||
;
|
@ -1,83 +0,0 @@
|
||||
// (C) Copyright Jeremy Siek 2002. 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.
|
||||
|
||||
#include <boost/iterator/iterator_concepts.hpp>
|
||||
#include <boost/iterator/iterator_categories.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
|
||||
struct new_random_access
|
||||
: std::random_access_iterator_tag
|
||||
, boost::random_access_traversal_tag
|
||||
{};
|
||||
|
||||
struct new_iterator
|
||||
: public boost::iterator< new_random_access, int >
|
||||
{
|
||||
int& operator*() const { return *m_x; }
|
||||
new_iterator& operator++() { return *this; }
|
||||
new_iterator operator++(int) { return *this; }
|
||||
new_iterator& operator--() { return *this; }
|
||||
new_iterator operator--(int) { return *this; }
|
||||
new_iterator& operator+=(std::ptrdiff_t) { return *this; }
|
||||
new_iterator operator+(std::ptrdiff_t) { return *this; }
|
||||
new_iterator& operator-=(std::ptrdiff_t) { return *this; }
|
||||
std::ptrdiff_t operator-(const new_iterator&) const { return 0; }
|
||||
new_iterator operator-(std::ptrdiff_t) const { return *this; }
|
||||
bool operator==(const new_iterator&) const { return false; }
|
||||
bool operator!=(const new_iterator&) const { return false; }
|
||||
bool operator<(const new_iterator&) const { return false; }
|
||||
int* m_x;
|
||||
};
|
||||
new_iterator operator+(std::ptrdiff_t, new_iterator x) { return x; }
|
||||
|
||||
struct old_iterator
|
||||
: public boost::iterator<std::random_access_iterator_tag, int>
|
||||
{
|
||||
int& operator*() const { return *m_x; }
|
||||
old_iterator& operator++() { return *this; }
|
||||
old_iterator operator++(int) { return *this; }
|
||||
old_iterator& operator--() { return *this; }
|
||||
old_iterator operator--(int) { return *this; }
|
||||
old_iterator& operator+=(std::ptrdiff_t) { return *this; }
|
||||
old_iterator operator+(std::ptrdiff_t) { return *this; }
|
||||
old_iterator& operator-=(std::ptrdiff_t) { return *this; }
|
||||
old_iterator operator-(std::ptrdiff_t) const { return *this; }
|
||||
std::ptrdiff_t operator-(const old_iterator&) const { return 0; }
|
||||
bool operator==(const old_iterator&) const { return false; }
|
||||
bool operator!=(const old_iterator&) const { return false; }
|
||||
bool operator<(const old_iterator&) const { return false; }
|
||||
int* m_x;
|
||||
};
|
||||
old_iterator operator+(std::ptrdiff_t, old_iterator x) { return x; }
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
boost::iterator_traversal<new_iterator>::type tc;
|
||||
boost::random_access_traversal_tag derived = tc;
|
||||
(void)derived;
|
||||
|
||||
boost::function_requires<
|
||||
boost_concepts::WritableLvalueIteratorConcept<int*> >();
|
||||
boost::function_requires<
|
||||
boost_concepts::RandomAccessTraversalConcept<int*> >();
|
||||
|
||||
boost::function_requires<
|
||||
boost_concepts::ReadableLvalueIteratorConcept<const int*> >();
|
||||
boost::function_requires<
|
||||
boost_concepts::RandomAccessTraversalConcept<const int*> >();
|
||||
|
||||
boost::function_requires<
|
||||
boost_concepts::WritableLvalueIteratorConcept<new_iterator> >();
|
||||
boost::function_requires<
|
||||
boost_concepts::RandomAccessTraversalConcept<new_iterator> >();
|
||||
|
||||
boost::function_requires<
|
||||
boost_concepts::WritableLvalueIteratorConcept<old_iterator> >();
|
||||
boost::function_requires<
|
||||
boost_concepts::RandomAccessTraversalConcept<old_iterator> >();
|
||||
return 0;
|
||||
}
|
@ -1,295 +0,0 @@
|
||||
// (C) Copyright David Abrahams 2001. 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
|
||||
// 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)
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#ifdef __BORLANDC__ // Borland mis-detects our custom iterators
|
||||
# pragma warn -8091 // template argument ForwardIterator passed to '...' is a output iterator
|
||||
# pragma warn -8071 // Conversion may lose significant digits (due to counting_iterator<char> += n).
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(disable:4786) // identifier truncated in debug info
|
||||
#endif
|
||||
|
||||
#include <boost/detail/iterator.hpp>
|
||||
#include <boost/iterator/counting_iterator.hpp>
|
||||
#include <boost/iterator/new_iterator_tests.hpp>
|
||||
|
||||
#include <boost/next_prior.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/limits.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <climits>
|
||||
#include <iterator>
|
||||
#include <stdlib.h>
|
||||
#ifndef __BORLANDC__
|
||||
# include <boost/tuple/tuple.hpp>
|
||||
#endif
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <cassert>
|
||||
#ifndef BOOST_NO_SLIST
|
||||
# include <slist>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||
template <class T>
|
||||
struct signed_assert_nonnegative
|
||||
{
|
||||
static void test(T x) { assert(x >= 0); }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct unsigned_assert_nonnegative
|
||||
{
|
||||
static void test(T x) {}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct assert_nonnegative
|
||||
: boost::mpl::if_c<
|
||||
std::numeric_limits<T>::is_signed
|
||||
, signed_assert_nonnegative<T>
|
||||
, unsigned_assert_nonnegative<T>
|
||||
>::type
|
||||
{
|
||||
};
|
||||
#endif
|
||||
|
||||
// Special tests for RandomAccess CountingIterators.
|
||||
template <class CountingIterator, class Value>
|
||||
void category_test(
|
||||
CountingIterator start,
|
||||
CountingIterator finish,
|
||||
Value,
|
||||
std::random_access_iterator_tag)
|
||||
{
|
||||
typedef typename
|
||||
boost::detail::iterator_traits<CountingIterator>::difference_type
|
||||
difference_type;
|
||||
difference_type distance = boost::detail::distance(start, finish);
|
||||
|
||||
// Pick a random position internal to the range
|
||||
difference_type offset = (unsigned)rand() % distance;
|
||||
|
||||
#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||
assert(offset >= 0);
|
||||
#else
|
||||
assert_nonnegative<difference_type>::test(offset);
|
||||
#endif
|
||||
|
||||
CountingIterator internal = start;
|
||||
std::advance(internal, offset);
|
||||
|
||||
// Try some binary searches on the range to show that it's ordered
|
||||
assert(std::binary_search(start, finish, *internal));
|
||||
|
||||
// #including tuple crashed borland, so I had to give up on tie().
|
||||
std::pair<CountingIterator,CountingIterator> xy(
|
||||
std::equal_range(start, finish, *internal));
|
||||
CountingIterator x = xy.first, y = xy.second;
|
||||
|
||||
assert(boost::detail::distance(x, y) == 1);
|
||||
|
||||
// Show that values outside the range can't be found
|
||||
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);
|
||||
|
||||
// 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, v.size(), v.begin());
|
||||
}
|
||||
|
||||
// Special tests for bidirectional CountingIterators
|
||||
template <class CountingIterator, class Value>
|
||||
void category_test(CountingIterator start, Value v1, std::bidirectional_iterator_tag)
|
||||
{
|
||||
Value v2 = v1;
|
||||
++v2;
|
||||
|
||||
// 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(start, v1, v2);
|
||||
}
|
||||
|
||||
template <class CountingIterator, class Value>
|
||||
void category_test(CountingIterator start, CountingIterator finish, Value v1, std::forward_iterator_tag)
|
||||
{
|
||||
Value v2 = v1;
|
||||
++v2;
|
||||
if (finish != start && finish != boost::next(start))
|
||||
boost::forward_readable_iterator_test(start, finish, v1, v2);
|
||||
}
|
||||
|
||||
template <class CountingIterator, class Value>
|
||||
void test_aux(CountingIterator start, CountingIterator finish, Value v1)
|
||||
{
|
||||
typedef typename CountingIterator::iterator_category category;
|
||||
typedef typename CountingIterator::value_type value_type;
|
||||
|
||||
// If it's a RandomAccessIterator we can do a few delicate tests
|
||||
category_test(start, finish, v1, category());
|
||||
|
||||
// Okay, brute force...
|
||||
for (CountingIterator p = start
|
||||
; p != finish && boost::next(p) != finish
|
||||
; ++p)
|
||||
{
|
||||
assert(boost::next(*p) == *boost::next(p));
|
||||
}
|
||||
|
||||
// prove that a reference can be formed to these values
|
||||
typedef typename CountingIterator::value_type value;
|
||||
const value* q = &*start;
|
||||
(void)q; // suppress unused variable warning
|
||||
}
|
||||
|
||||
template <class Incrementable>
|
||||
void test(Incrementable start, Incrementable finish)
|
||||
{
|
||||
test_aux(boost::make_counting_iterator(start), boost::make_counting_iterator(finish), start);
|
||||
}
|
||||
|
||||
template <class Integer>
|
||||
void test_integer(Integer* = 0) // default arg works around MSVC bug
|
||||
{
|
||||
Integer start = 0;
|
||||
Integer finish = 120;
|
||||
test(start, finish);
|
||||
}
|
||||
|
||||
template <class Integer, class Category, class Difference>
|
||||
void test_integer3(Integer* = 0, Category* = 0, Difference* = 0) // default arg works around MSVC bug
|
||||
{
|
||||
Integer start = 0;
|
||||
Integer finish = 120;
|
||||
typedef boost::counting_iterator<Integer,Category,Difference> iterator;
|
||||
test_aux(iterator(start), iterator(finish), start);
|
||||
}
|
||||
|
||||
template <class Container>
|
||||
void test_container(Container* = 0) // default arg works around MSVC bug
|
||||
{
|
||||
Container c(1 + (unsigned)rand() % 1673);
|
||||
|
||||
const typename Container::iterator start = c.begin();
|
||||
|
||||
// back off by 1 to leave room for dereferenceable value at the end
|
||||
typename Container::iterator finish = start;
|
||||
std::advance(finish, c.size() - 1);
|
||||
|
||||
test(start, finish);
|
||||
|
||||
typedef typename Container::const_iterator const_iterator;
|
||||
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;
|
||||
};
|
||||
|
||||
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()
|
||||
{
|
||||
// Test the built-in integer types.
|
||||
test_integer<char>();
|
||||
test_integer<unsigned char>();
|
||||
test_integer<signed char>();
|
||||
test_integer<wchar_t>();
|
||||
test_integer<short>();
|
||||
test_integer<unsigned short>();
|
||||
test_integer<int>();
|
||||
test_integer<unsigned int>();
|
||||
test_integer<long>();
|
||||
test_integer<unsigned long>();
|
||||
#if defined(BOOST_HAS_LONG_LONG)
|
||||
test_integer<long long>();
|
||||
test_integer<unsigned long long>();
|
||||
#endif
|
||||
|
||||
// Test user-defined type.
|
||||
|
||||
test_integer3<my_int1, std::forward_iterator_tag, int>();
|
||||
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::list<int> >();
|
||||
# ifndef BOOST_NO_SLIST
|
||||
test_container<BOOST_STD_EXTENSION_NAMESPACE::slist<int> >();
|
||||
# endif
|
||||
|
||||
// Also prove that we can handle raw pointers.
|
||||
int array[2000];
|
||||
test(boost::make_counting_iterator(array), boost::make_counting_iterator(array+2000-1));
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
// Copyright David Abrahams 2003. 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.
|
||||
|
||||
#include <boost/iterator/filter_iterator.hpp>
|
||||
#include <boost/iterator/reverse_iterator.hpp>
|
||||
#include <boost/iterator/new_iterator_tests.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
|
||||
using boost::dummyT;
|
||||
|
||||
struct one_or_four
|
||||
{
|
||||
bool operator()(dummyT x) const
|
||||
{
|
||||
return x.foo() == 1 || x.foo() == 4;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T> struct undefined;
|
||||
|
||||
// Test filter iterator
|
||||
int main()
|
||||
{
|
||||
dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),
|
||||
dummyT(3), dummyT(4), dummyT(5) };
|
||||
const int N = sizeof(array)/sizeof(dummyT);
|
||||
|
||||
typedef boost::filter_iterator<one_or_four, dummyT*> filter_iter;
|
||||
|
||||
boost::bidirectional_readable_iterator_test(
|
||||
filter_iter(one_or_four(), array, array+N)
|
||||
, dummyT(1), dummyT(4));
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
(!boost::is_convertible<
|
||||
boost::iterator_traversal<filter_iter>::type
|
||||
, boost::random_access_traversal_tag
|
||||
>::value
|
||||
));
|
||||
|
||||
//# endif
|
||||
|
||||
// On compilers not supporting partial specialization, we can do more type
|
||||
// deduction with deque iterators than with pointers... unless the library
|
||||
// is broken ;-(
|
||||
std::deque<dummyT> array2;
|
||||
std::copy(array+0, array+N, std::back_inserter(array2));
|
||||
boost::bidirectional_readable_iterator_test(
|
||||
boost::make_filter_iterator(one_or_four(), array2.begin(), array2.end()),
|
||||
dummyT(1), dummyT(4));
|
||||
|
||||
boost::bidirectional_readable_iterator_test(
|
||||
boost::make_filter_iterator(one_or_four(), array2.begin(), array2.end()),
|
||||
dummyT(1), dummyT(4));
|
||||
|
||||
boost::bidirectional_readable_iterator_test(
|
||||
boost::make_filter_iterator(
|
||||
one_or_four()
|
||||
, boost::make_reverse_iterator(array2.end())
|
||||
, boost::make_reverse_iterator(array2.begin())
|
||||
),
|
||||
dummyT(4), dummyT(1));
|
||||
|
||||
boost::bidirectional_readable_iterator_test(
|
||||
filter_iter(array+0, array+N),
|
||||
dummyT(1), dummyT(4));
|
||||
|
||||
boost::bidirectional_readable_iterator_test(
|
||||
filter_iter(one_or_four(), array, array + N),
|
||||
dummyT(1), dummyT(4));
|
||||
|
||||
std::cout << "test successful " << std::endl;
|
||||
return 0;
|
||||
}
|
@ -1,209 +0,0 @@
|
||||
// (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
|
||||
// 22 Nov 2002 Thomas Witt
|
||||
// Added interoperability check.
|
||||
// 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/indirect_iterator.hpp>
|
||||
#include <boost/iterator/iterator_concepts.hpp>
|
||||
#include <boost/iterator/new_iterator_tests.hpp>
|
||||
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#include <boost/concept_archetype.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
#include <boost/type_traits/broken_compiler_spec.hpp>
|
||||
#include <vector>
|
||||
#include <stdlib.h>
|
||||
#include <set>
|
||||
|
||||
#if !defined(__SGI_STL_PORT) \
|
||||
&& (defined(BOOST_MSVC_STD_ITERATOR) \
|
||||
|| BOOST_WORKAROUND(_CPPLIB_VER, <= 310) \
|
||||
|| BOOST_WORKAROUND(__GNUC__, <= 2))
|
||||
|
||||
// std container random-access iterators don't support mutable/const
|
||||
// interoperability (but may support const/mutable interop).
|
||||
# define NO_MUTABLE_CONST_STD_SET_ITERATOR_INTEROPERABILITY
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
struct my_iterator_tag : public std::random_access_iterator_tag { };
|
||||
|
||||
using boost::dummyT;
|
||||
BOOST_TT_BROKEN_COMPILER_SPEC(boost::shared_ptr<dummyT>)
|
||||
|
||||
typedef std::vector<int> storage;
|
||||
typedef std::vector<int*> pointer_ra_container;
|
||||
typedef std::set<storage::iterator> iterator_set;
|
||||
|
||||
template <class Container>
|
||||
struct indirect_iterator_pair_generator
|
||||
{
|
||||
typedef boost::indirect_iterator<typename Container::iterator> iterator;
|
||||
|
||||
typedef boost::indirect_iterator<
|
||||
typename Container::iterator
|
||||
, typename iterator::value_type const
|
||||
> const_iterator;
|
||||
};
|
||||
|
||||
void more_indirect_iterator_tests()
|
||||
{
|
||||
storage store(1000);
|
||||
std::generate(store.begin(), store.end(), rand);
|
||||
|
||||
pointer_ra_container ptr_ra_container;
|
||||
iterator_set iter_set;
|
||||
|
||||
for (storage::iterator p = store.begin(); p != store.end(); ++p)
|
||||
{
|
||||
ptr_ra_container.push_back(&*p);
|
||||
iter_set.insert(p);
|
||||
}
|
||||
|
||||
typedef indirect_iterator_pair_generator<pointer_ra_container> indirect_ra_container;
|
||||
|
||||
indirect_ra_container::iterator db(ptr_ra_container.begin());
|
||||
indirect_ra_container::iterator de(ptr_ra_container.end());
|
||||
assert(static_cast<std::size_t>(de - db) == store.size());
|
||||
assert(db + store.size() == de);
|
||||
indirect_ra_container::const_iterator dci = db;
|
||||
|
||||
assert(dci == db);
|
||||
|
||||
#ifndef NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY
|
||||
assert(db == dci);
|
||||
#endif
|
||||
|
||||
assert(dci != de);
|
||||
assert(dci < de);
|
||||
assert(dci <= de);
|
||||
|
||||
#ifndef NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY
|
||||
assert(de >= dci);
|
||||
assert(de > dci);
|
||||
#endif
|
||||
|
||||
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 typedefs here
|
||||
typedef boost::indirect_iterator<iterator_set::iterator> indirect_set_iterator;
|
||||
typedef boost::indirect_iterator<
|
||||
iterator_set::iterator
|
||||
, iterator_set::iterator::value_type const
|
||||
> 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);
|
||||
|
||||
# ifndef NO_MUTABLE_CONST_STD_SET_ITERATOR_INTEROPERABILITY
|
||||
assert(se != sci);
|
||||
# endif
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),
|
||||
dummyT(3), dummyT(4), dummyT(5) };
|
||||
const int N = sizeof(array)/sizeof(dummyT);
|
||||
|
||||
typedef std::vector<boost::shared_ptr<dummyT> > shared_t;
|
||||
shared_t shared;
|
||||
|
||||
// Concept checks
|
||||
{
|
||||
typedef boost::indirect_iterator<shared_t::iterator> iter_t;
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
boost::detail::has_element_type<
|
||||
boost::shared_ptr<dummyT>
|
||||
// std::iterator_traits<shared_t::iterator>::value_type
|
||||
>::value
|
||||
);
|
||||
|
||||
typedef boost::indirect_iterator<
|
||||
shared_t::iterator
|
||||
, boost::iterator_value<shared_t::iterator>::type const
|
||||
> c_iter_t;
|
||||
|
||||
# ifndef NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY
|
||||
boost::function_requires< boost_concepts::InteroperableConcept<iter_t, c_iter_t> >();
|
||||
# endif
|
||||
}
|
||||
|
||||
// Test indirect_iterator_generator
|
||||
{
|
||||
for (int jj = 0; jj < N; ++jj)
|
||||
shared.push_back(boost::shared_ptr<dummyT>(new dummyT(jj)));
|
||||
|
||||
dummyT* ptr[N];
|
||||
for (int k = 0; k < N; ++k)
|
||||
ptr[k] = array + k;
|
||||
|
||||
typedef boost::indirect_iterator<dummyT**> indirect_iterator;
|
||||
|
||||
typedef boost::indirect_iterator<dummyT**, dummyT const>
|
||||
const_indirect_iterator;
|
||||
|
||||
indirect_iterator i(ptr);
|
||||
boost::random_access_iterator_test(i, N, array);
|
||||
|
||||
boost::random_access_iterator_test(
|
||||
boost::indirect_iterator<shared_t::iterator>(shared.begin())
|
||||
, N, array);
|
||||
|
||||
boost::random_access_iterator_test(boost::make_indirect_iterator(ptr), N, array);
|
||||
|
||||
// check operator->
|
||||
assert((*i).m_x == i->foo());
|
||||
|
||||
const_indirect_iterator j(ptr);
|
||||
boost::random_access_iterator_test(j, N, array);
|
||||
|
||||
|
||||
dummyT const*const* const_ptr = ptr;
|
||||
boost::random_access_iterator_test(boost::make_indirect_iterator(const_ptr), N, array);
|
||||
|
||||
boost::const_nonconst_iterator_test(i, ++j);
|
||||
|
||||
more_indirect_iterator_tests();
|
||||
}
|
||||
std::cout << "test successful " << std::endl;
|
||||
return 0;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
// Copyright Thomas Witt 2003. 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.
|
||||
#include <boost/iterator/indirect_iterator.hpp>
|
||||
#include <boost/iterator/reverse_iterator.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/cstdlib.hpp>
|
||||
#include <list>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef boost::reverse_iterator<std::list<int*>::iterator> rev_iter;
|
||||
typedef boost::indirect_iterator<std::list<int*>::iterator> ind_iter;
|
||||
|
||||
ind_iter() == rev_iter();
|
||||
}
|
||||
|
||||
return boost::exit_success;
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
#include <boost/iterator/reverse_iterator.hpp>
|
||||
#include <boost/cstdlib.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::reverse_iterator<int*> rev_iter1;
|
||||
typedef boost::reverse_iterator<char*> rev_iter2;
|
||||
|
||||
return boost::is_convertible<rev_iter1, rev_iter2>::value
|
||||
? boost::exit_failure : boost::exit_success;
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
// Copyright David Abrahams 2003. Use, modification and distribution is
|
||||
// subject to the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <deque>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/type_traits/broken_compiler_spec.hpp>
|
||||
#include <boost/iterator/is_lvalue_iterator.hpp>
|
||||
#include <boost/iterator.hpp>
|
||||
|
||||
// Last, for BOOST_NO_LVALUE_RETURN_DETECTION
|
||||
#include <boost/iterator/detail/config_def.hpp>
|
||||
|
||||
struct v
|
||||
{
|
||||
v();
|
||||
~v();
|
||||
};
|
||||
|
||||
BOOST_TT_BROKEN_COMPILER_SPEC(v)
|
||||
|
||||
struct value_iterator : boost::iterator<std::input_iterator_tag,v>
|
||||
{
|
||||
v operator*() const;
|
||||
};
|
||||
|
||||
struct noncopyable_iterator : boost::iterator<std::forward_iterator_tag,boost::noncopyable>
|
||||
{
|
||||
boost::noncopyable const& operator*() const;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct proxy_iterator
|
||||
: boost::iterator<std::output_iterator_tag,T>
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
#if BOOST_WORKAROUND(__GNUC__, == 2)
|
||||
typedef boost::iterator<std::input_iterator_tag,value_type> base;
|
||||
typedef base::iterator_category iterator_category;
|
||||
typedef base::difference_type difference_type;
|
||||
typedef base::pointer pointer;
|
||||
typedef base::reference reference;
|
||||
#endif
|
||||
|
||||
struct proxy
|
||||
{
|
||||
operator value_type&() const;
|
||||
proxy& operator=(value_type) const;
|
||||
};
|
||||
|
||||
proxy operator*() const;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct lvalue_iterator
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef T& reference;
|
||||
typedef T difference_type;
|
||||
typedef std::input_iterator_tag iterator_category;
|
||||
typedef T* pointer;
|
||||
|
||||
T& operator*() const;
|
||||
lvalue_iterator& operator++();
|
||||
lvalue_iterator operator++(int);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct constant_lvalue_iterator
|
||||
{
|
||||
typedef T value_type;
|
||||
typedef T const& reference;
|
||||
typedef T difference_type;
|
||||
typedef std::input_iterator_tag iterator_category;
|
||||
typedef T const* pointer;
|
||||
|
||||
T const& operator*() const;
|
||||
constant_lvalue_iterator& operator++();
|
||||
constant_lvalue_iterator operator++(int);
|
||||
};
|
||||
|
||||
BOOST_TT_BROKEN_COMPILER_SPEC(proxy_iterator<v>::proxy)
|
||||
BOOST_TT_BROKEN_COMPILER_SPEC(proxy_iterator<int>::proxy)
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<v*>::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<v const*>::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<std::deque<v>::iterator>::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<std::deque<v>::const_iterator>::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<std::back_insert_iterator<std::deque<v> > >::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<std::ostream_iterator<v> >::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<proxy_iterator<v> >::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<proxy_iterator<int> >::value);
|
||||
#ifndef BOOST_NO_LVALUE_RETURN_DETECTION
|
||||
BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator<value_iterator>::value);
|
||||
#endif
|
||||
// Make sure inaccessible copy constructor doesn't prevent
|
||||
// reference binding
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<noncopyable_iterator>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<lvalue_iterator<v> >::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<lvalue_iterator<int> >::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<lvalue_iterator<char*> >::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<lvalue_iterator<float> >::value);
|
||||
|
||||
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<constant_lvalue_iterator<v> >::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<constant_lvalue_iterator<int> >::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<constant_lvalue_iterator<char*> >::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<constant_lvalue_iterator<float> >::value);
|
||||
|
||||
|
||||
|
||||
BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<v*>::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<v const*>::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<std::deque<v>::iterator>::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<std::deque<v>::const_iterator>::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<std::back_insert_iterator<std::deque<v> > >::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<std::ostream_iterator<v> >::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<proxy_iterator<v> >::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<proxy_iterator<int> >::value);
|
||||
#ifndef BOOST_NO_LVALUE_RETURN_DETECTION
|
||||
BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<value_iterator>::value);
|
||||
#endif
|
||||
BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<noncopyable_iterator>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<lvalue_iterator<v> >::value);
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<lvalue_iterator<int> >::value);
|
||||
#endif
|
||||
BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<lvalue_iterator<char*> >::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<lvalue_iterator<float> >::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<constant_lvalue_iterator<v> >::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<constant_lvalue_iterator<int> >::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<constant_lvalue_iterator<char*> >::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator<constant_lvalue_iterator<float> >::value);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
// Copyright David Abrahams 2003. Use, modification and distribution is
|
||||
// subject to the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <deque>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/type_traits/broken_compiler_spec.hpp>
|
||||
#include <boost/iterator/is_readable_iterator.hpp>
|
||||
#include <boost/iterator.hpp>
|
||||
|
||||
// Last, for BOOST_NO_LVALUE_RETURN_DETECTION
|
||||
#include <boost/iterator/detail/config_def.hpp>
|
||||
|
||||
struct v
|
||||
{
|
||||
v();
|
||||
~v();
|
||||
};
|
||||
|
||||
BOOST_TT_BROKEN_COMPILER_SPEC(v)
|
||||
|
||||
struct value_iterator : boost::iterator<std::input_iterator_tag,v>
|
||||
{
|
||||
v operator*() const;
|
||||
};
|
||||
|
||||
struct noncopyable_iterator : boost::iterator<std::forward_iterator_tag,boost::noncopyable>
|
||||
{
|
||||
boost::noncopyable const& operator*() const;
|
||||
};
|
||||
|
||||
struct proxy_iterator : boost::iterator<std::output_iterator_tag,v>
|
||||
{
|
||||
#if BOOST_WORKAROUND(__GNUC__, == 2)
|
||||
typedef boost::iterator<std::input_iterator_tag,v> base;
|
||||
typedef base::iterator_category iterator_category;
|
||||
typedef base::value_type value_type;
|
||||
typedef base::difference_type difference_type;
|
||||
typedef base::pointer pointer;
|
||||
typedef base::reference reference;
|
||||
#endif
|
||||
|
||||
struct proxy
|
||||
{
|
||||
operator v&();
|
||||
proxy& operator=(v) const;
|
||||
};
|
||||
|
||||
proxy operator*() const;
|
||||
};
|
||||
|
||||
struct proxy_iterator2 : boost::iterator<std::output_iterator_tag,v>
|
||||
{
|
||||
#if BOOST_WORKAROUND(__GNUC__, == 2)
|
||||
typedef boost::iterator<std::input_iterator_tag,v> base;
|
||||
typedef base::iterator_category iterator_category;
|
||||
typedef base::value_type value_type;
|
||||
typedef base::difference_type difference_type;
|
||||
typedef base::pointer pointer;
|
||||
typedef base::reference reference;
|
||||
#endif
|
||||
|
||||
struct proxy
|
||||
{
|
||||
proxy& operator=(v) const;
|
||||
};
|
||||
|
||||
proxy operator*() const;
|
||||
};
|
||||
|
||||
BOOST_TT_BROKEN_COMPILER_SPEC(proxy_iterator::proxy)
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_STATIC_ASSERT(boost::is_readable_iterator<v*>::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_readable_iterator<v const*>::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_readable_iterator<std::deque<v>::iterator>::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_readable_iterator<std::deque<v>::const_iterator>::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_readable_iterator<std::back_insert_iterator<std::deque<v> > >::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_readable_iterator<std::ostream_iterator<v> >::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_readable_iterator<proxy_iterator>::value);
|
||||
BOOST_STATIC_ASSERT(!boost::is_readable_iterator<proxy_iterator2>::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_readable_iterator<value_iterator>::value);
|
||||
|
||||
// Make sure inaccessible copy constructor doesn't prevent
|
||||
// readability
|
||||
BOOST_STATIC_ASSERT(boost::is_readable_iterator<noncopyable_iterator>::value);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
#include <boost/iterator/reverse_iterator.hpp>
|
||||
#include <boost/iterator/iterator_concepts.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/cstdlib.hpp>
|
||||
#include <list>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef boost::reverse_iterator<int*> rev_iter;
|
||||
typedef boost::reverse_iterator<int const*> c_rev_iter;
|
||||
|
||||
boost::function_requires< boost_concepts::WritableLvalueIteratorConcept<rev_iter> >();
|
||||
boost::function_requires< boost_concepts::RandomAccessTraversalConcept<rev_iter> >();
|
||||
boost::function_requires< boost::RandomAccessIteratorConcept<rev_iter> >();
|
||||
boost::function_requires< boost_concepts::InteroperableConcept<rev_iter, c_rev_iter> >();
|
||||
}
|
||||
{
|
||||
typedef boost::reverse_iterator<std::list<int>::iterator> rev_iter;
|
||||
typedef boost::reverse_iterator<std::list<int>::const_iterator> c_rev_iter;
|
||||
|
||||
boost::function_requires< boost_concepts::ReadableLvalueIteratorConcept<c_rev_iter> >();
|
||||
boost::function_requires< boost_concepts::BidirectionalTraversalConcept<c_rev_iter> >();
|
||||
boost::function_requires< boost::BidirectionalIteratorConcept<c_rev_iter> >();
|
||||
boost::function_requires< boost_concepts::InteroperableConcept<rev_iter, c_rev_iter> >();
|
||||
}
|
||||
|
||||
return boost::exit_success;
|
||||
}
|
@ -1,323 +0,0 @@
|
||||
// (C) Copyright Thomas Witt 2003. 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.
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
|
||||
#include <boost/iterator/iterator_adaptor.hpp>
|
||||
#if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
# include <boost/iterator/is_readable_iterator.hpp>
|
||||
# include <boost/iterator/is_lvalue_iterator.hpp>
|
||||
#endif
|
||||
#include <boost/pending/iterator_tests.hpp>
|
||||
|
||||
# include <boost/type_traits/broken_compiler_spec.hpp>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <set>
|
||||
#include <list>
|
||||
|
||||
#include "static_assert_same.hpp"
|
||||
|
||||
#include <boost/iterator/detail/config_def.hpp>
|
||||
|
||||
using boost::dummyT;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
template <class Pair>
|
||||
struct select1st_
|
||||
: public std::unary_function<Pair, typename Pair::first_type>
|
||||
{
|
||||
const typename Pair::first_type& operator()(const Pair& x) const {
|
||||
return x.first;
|
||||
}
|
||||
typename Pair::first_type& operator()(Pair& x) const {
|
||||
return x.first;
|
||||
}
|
||||
};
|
||||
|
||||
struct one_or_four {
|
||||
bool operator()(dummyT x) const {
|
||||
return x.foo() == 1 || x.foo() == 4;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::deque<int> storage;
|
||||
typedef std::deque<int*> pointer_deque;
|
||||
typedef std::set<storage::iterator> iterator_set;
|
||||
|
||||
template <class T> struct foo;
|
||||
|
||||
void blah(int) { }
|
||||
|
||||
struct my_gen
|
||||
{
|
||||
typedef int result_type;
|
||||
my_gen() : n(0) { }
|
||||
int operator()() { return ++n; }
|
||||
int n;
|
||||
};
|
||||
|
||||
template <class V>
|
||||
struct ptr_iterator
|
||||
: boost::iterator_adaptor<
|
||||
ptr_iterator<V>
|
||||
, V*
|
||||
, V
|
||||
, boost::random_access_traversal_tag
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
, V&
|
||||
#endif
|
||||
>
|
||||
{
|
||||
private:
|
||||
typedef boost::iterator_adaptor<
|
||||
ptr_iterator<V>
|
||||
, V*
|
||||
, V
|
||||
, boost::random_access_traversal_tag
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
, V&
|
||||
#endif
|
||||
> super_t;
|
||||
|
||||
public:
|
||||
ptr_iterator() { }
|
||||
ptr_iterator(V* d) : super_t(d) { }
|
||||
|
||||
template <class V2>
|
||||
ptr_iterator(
|
||||
const ptr_iterator<V2>& x
|
||||
, typename boost::enable_if_convertible<V2*, V*>::type* = 0
|
||||
)
|
||||
: super_t(x.base())
|
||||
{}
|
||||
};
|
||||
|
||||
// Non-functional iterator for category modification checking
|
||||
template <class Iter, class Traversal>
|
||||
struct modify_traversal
|
||||
: boost::iterator_adaptor<
|
||||
modify_traversal<Iter, Traversal>
|
||||
, Iter
|
||||
, boost::use_default
|
||||
, Traversal
|
||||
>
|
||||
{};
|
||||
|
||||
template <class T>
|
||||
struct fwd_iterator
|
||||
: boost::iterator_adaptor<
|
||||
fwd_iterator<T>
|
||||
, boost::forward_iterator_archetype<T>
|
||||
>
|
||||
{
|
||||
private:
|
||||
typedef boost::iterator_adaptor<
|
||||
fwd_iterator<T>
|
||||
, boost::forward_iterator_archetype<T>
|
||||
> super_t;
|
||||
|
||||
public:
|
||||
fwd_iterator() { }
|
||||
fwd_iterator(boost::forward_iterator_archetype<T> d) : super_t(d) { }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct in_iterator
|
||||
: boost::iterator_adaptor<
|
||||
in_iterator<T>
|
||||
, boost::input_iterator_archetype<T>
|
||||
>
|
||||
{
|
||||
private:
|
||||
typedef boost::iterator_adaptor<
|
||||
in_iterator<T>
|
||||
, boost::input_iterator_archetype<T>
|
||||
> super_t;
|
||||
|
||||
public:
|
||||
in_iterator() { }
|
||||
in_iterator(boost::input_iterator_archetype<T> d) : super_t(d) { }
|
||||
};
|
||||
|
||||
template <class Iter>
|
||||
struct constant_iterator
|
||||
: boost::iterator_adaptor<
|
||||
constant_iterator<Iter>
|
||||
, Iter
|
||||
, typename std::iterator_traits<Iter>::value_type const
|
||||
>
|
||||
{
|
||||
typedef boost::iterator_adaptor<
|
||||
constant_iterator<Iter>
|
||||
, Iter
|
||||
, typename std::iterator_traits<Iter>::value_type const
|
||||
> base_t;
|
||||
|
||||
constant_iterator() {}
|
||||
constant_iterator(Iter it)
|
||||
: base_t(it) {}
|
||||
};
|
||||
|
||||
char (& traversal2(boost::incrementable_traversal_tag) )[1];
|
||||
char (& traversal2(boost::single_pass_traversal_tag ) )[2];
|
||||
char (& traversal2(boost::forward_traversal_tag ) )[3];
|
||||
char (& traversal2(boost::bidirectional_traversal_tag) )[4];
|
||||
char (& traversal2(boost::random_access_traversal_tag) )[5];
|
||||
|
||||
template <class Cat>
|
||||
struct traversal3
|
||||
{
|
||||
static typename boost::iterator_category_to_traversal<Cat>::type x;
|
||||
BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(traversal2(x)));
|
||||
typedef char (&type)[value];
|
||||
};
|
||||
|
||||
template <class Cat>
|
||||
typename traversal3<Cat>::type traversal(Cat);
|
||||
|
||||
template <class Iter, class Trav>
|
||||
int static_assert_traversal(Iter* = 0, Trav* = 0)
|
||||
{
|
||||
typedef typename boost::iterator_category_to_traversal<
|
||||
BOOST_DEDUCED_TYPENAME Iter::iterator_category
|
||||
>::type t2;
|
||||
|
||||
return static_assert_same<Trav,t2>::value;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),
|
||||
dummyT(3), dummyT(4), dummyT(5) };
|
||||
const int N = sizeof(array)/sizeof(dummyT);
|
||||
|
||||
// sanity check, if this doesn't pass the test is buggy
|
||||
boost::random_access_iterator_test(array, N, array);
|
||||
|
||||
// Test the iterator_adaptor
|
||||
{
|
||||
ptr_iterator<dummyT> i(array);
|
||||
boost::random_access_iterator_test(i, N, array);
|
||||
|
||||
ptr_iterator<const dummyT> j(array);
|
||||
boost::random_access_iterator_test(j, N, array);
|
||||
boost::const_nonconst_iterator_test(i, ++j);
|
||||
}
|
||||
|
||||
int test;
|
||||
// Test the iterator_traits
|
||||
{
|
||||
// Test computation of defaults
|
||||
typedef ptr_iterator<int> Iter1;
|
||||
// don't use std::iterator_traits here to avoid VC++ problems
|
||||
test = static_assert_same<Iter1::value_type, int>::value;
|
||||
test = static_assert_same<Iter1::reference, int&>::value;
|
||||
test = static_assert_same<Iter1::pointer, int*>::value;
|
||||
test = static_assert_same<Iter1::difference_type, std::ptrdiff_t>::value;
|
||||
#if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
BOOST_STATIC_ASSERT((boost::is_convertible<Iter1::iterator_category, std::random_access_iterator_tag>::value));
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
// Test computation of default when the Value is const
|
||||
typedef ptr_iterator<int const> Iter1;
|
||||
test = static_assert_same<Iter1::value_type, int>::value;
|
||||
test = static_assert_same<Iter1::reference, const int&>::value;
|
||||
|
||||
#if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
BOOST_STATIC_ASSERT(boost::is_readable_iterator<Iter1>::value);
|
||||
# ifndef BOOST_NO_LVALUE_RETURN_DETECTION
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<Iter1>::value);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) // borland drops constness
|
||||
test = static_assert_same<Iter1::pointer, int const*>::value;
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
// Test constant iterator idiom
|
||||
typedef ptr_iterator<int> BaseIter;
|
||||
typedef constant_iterator<BaseIter> Iter;
|
||||
|
||||
test = static_assert_same<Iter::value_type, int>::value;
|
||||
test = static_assert_same<Iter::reference, int const&>::value;
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) // borland drops constness
|
||||
test = static_assert_same<Iter::pointer, int const*>::value;
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NO_LVALUE_RETURN_DETECTION
|
||||
BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator<BaseIter>::value);
|
||||
BOOST_STATIC_ASSERT(boost::is_lvalue_iterator<Iter>::value);
|
||||
#endif
|
||||
|
||||
typedef modify_traversal<BaseIter, boost::incrementable_traversal_tag> IncrementableIter;
|
||||
|
||||
static_assert_traversal<BaseIter,boost::random_access_traversal_tag>();
|
||||
static_assert_traversal<IncrementableIter,boost::incrementable_traversal_tag>();
|
||||
}
|
||||
|
||||
// Test the iterator_adaptor
|
||||
{
|
||||
ptr_iterator<dummyT> i(array);
|
||||
boost::random_access_iterator_test(i, N, array);
|
||||
|
||||
ptr_iterator<const dummyT> j(array);
|
||||
boost::random_access_iterator_test(j, N, array);
|
||||
boost::const_nonconst_iterator_test(i, ++j);
|
||||
}
|
||||
|
||||
// check operator-> with a forward iterator
|
||||
{
|
||||
boost::forward_iterator_archetype<dummyT> forward_iter;
|
||||
|
||||
typedef fwd_iterator<dummyT> adaptor_type;
|
||||
|
||||
adaptor_type i(forward_iter);
|
||||
int zero = 0;
|
||||
if (zero) // don't do this, just make sure it compiles
|
||||
assert((*i).m_x == i->foo());
|
||||
}
|
||||
|
||||
// check operator-> with an input iterator
|
||||
{
|
||||
boost::input_iterator_archetype<dummyT> input_iter;
|
||||
typedef in_iterator<dummyT> adaptor_type;
|
||||
adaptor_type i(input_iter);
|
||||
int zero = 0;
|
||||
if (zero) // don't do this, just make sure it compiles
|
||||
assert((*i).m_x == i->foo());
|
||||
}
|
||||
|
||||
std::cout << "test successful " << std::endl;
|
||||
(void)test;
|
||||
return 0;
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
//
|
||||
// Copyright Thomas Witt 2003. 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.
|
||||
//
|
||||
#include <boost/iterator/iterator_archetypes.hpp>
|
||||
#include <boost/iterator/iterator_categories.hpp>
|
||||
#include <boost/iterator/iterator_concepts.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::iterator_archetype<
|
||||
int
|
||||
, boost::iterator_archetypes::writable_lvalue_iterator_t
|
||||
, boost::random_access_traversal_tag
|
||||
> iter;
|
||||
|
||||
boost::function_requires< boost_concepts::WritableLvalueIteratorConcept<iter> >();
|
||||
boost::function_requires< boost_concepts::RandomAccessTraversalConcept<iter> >();
|
||||
|
||||
return 0; // keep msvc happy
|
||||
}
|
||||
|
@ -1,84 +0,0 @@
|
||||
// (C) Copyright Toon Knapen 2001.
|
||||
// (C) Copyright Roland Richter 2003.
|
||||
// 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.
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/test/minimal.hpp>
|
||||
|
||||
#include <boost/iterator/permutation_iterator.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
void permutation_test()
|
||||
{
|
||||
// Example taken from documentation of old permutation_iterator.
|
||||
typedef std::vector< int > element_range_type;
|
||||
typedef std::list< int > index_type;
|
||||
|
||||
const int element_range_size = 10;
|
||||
const int index_size = 7;
|
||||
|
||||
BOOST_STATIC_ASSERT(index_size <= element_range_size);
|
||||
element_range_type elements( element_range_size );
|
||||
for( element_range_type::iterator el_it = elements.begin(); el_it != elements.end(); ++el_it )
|
||||
{ *el_it = std::distance(elements.begin(), el_it); }
|
||||
|
||||
index_type indices( index_size );
|
||||
for( index_type::iterator i_it = indices.begin(); i_it != indices.end(); ++i_it )
|
||||
{ *i_it = element_range_size - index_size + std::distance(indices.begin(), i_it); }
|
||||
std::reverse( indices.begin(), indices.end() );
|
||||
|
||||
typedef boost::permutation_iterator< element_range_type::iterator, index_type::iterator > permutation_type;
|
||||
permutation_type begin = boost::make_permutation_iterator( elements.begin(), indices.begin() );
|
||||
permutation_type it = begin;
|
||||
permutation_type end = boost::make_permutation_iterator( elements.begin(), indices.end() );
|
||||
|
||||
BOOST_CHECK( it == begin );
|
||||
BOOST_CHECK( it != end );
|
||||
|
||||
BOOST_CHECK( std::distance( begin, end ) == index_size );
|
||||
|
||||
for( index_type::iterator i_it1 = indices.begin(); it != end; ++i_it1, ++it )
|
||||
{
|
||||
BOOST_CHECK( *it == elements[ *i_it1 ] );
|
||||
}
|
||||
|
||||
it = begin;
|
||||
for( int i1 = 0; i1 < index_size - 1 ; i1+=2, it+=2 )
|
||||
{
|
||||
index_type::iterator i_it2 = indices.begin();
|
||||
std::advance( i_it2, i1 );
|
||||
BOOST_CHECK( *it == elements[ *i_it2 ] );
|
||||
}
|
||||
|
||||
|
||||
it = begin + (index_size);
|
||||
for( index_type::iterator i_it3 = indices.end(); it != begin; )
|
||||
{
|
||||
BOOST_CHECK( *--it == elements[ *--i_it3 ] );
|
||||
}
|
||||
|
||||
it = begin + index_size;
|
||||
for( int i2 = 0; i2 < index_size - 1; i2+=2, --it )
|
||||
{
|
||||
index_type::iterator i_it4 = --indices.end();
|
||||
std::advance( i_it4, -i2 );
|
||||
BOOST_CHECK( *--it == elements[ *i_it4 ] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int test_main(int, char *[])
|
||||
{
|
||||
permutation_test();
|
||||
return 0;
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
// Copyright Thomas Witt 2003. 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.
|
||||
|
||||
#include <boost/iterator/reverse_iterator.hpp>
|
||||
#include <boost/iterator/new_iterator_tests.hpp>
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
|
||||
using boost::dummyT;
|
||||
|
||||
// Test reverse iterator
|
||||
int main()
|
||||
{
|
||||
dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),
|
||||
dummyT(3), dummyT(4), dummyT(5) };
|
||||
const int N = sizeof(array)/sizeof(dummyT);
|
||||
|
||||
// Test reverse_iterator_generator
|
||||
{
|
||||
dummyT reversed[N];
|
||||
std::copy(array, array + N, reversed);
|
||||
std::reverse(reversed, reversed + N);
|
||||
|
||||
typedef boost::reverse_iterator<dummyT*> reverse_iterator;
|
||||
|
||||
reverse_iterator i(reversed + N);
|
||||
boost::random_access_iterator_test(i, N, array);
|
||||
|
||||
boost::random_access_iterator_test(boost::make_reverse_iterator(reversed + N), N, array);
|
||||
|
||||
typedef boost::reverse_iterator<const dummyT*> const_reverse_iterator;
|
||||
|
||||
const_reverse_iterator j(reversed + N);
|
||||
boost::random_access_iterator_test(j, N, array);
|
||||
|
||||
const dummyT* const_reversed = reversed;
|
||||
|
||||
boost::random_access_iterator_test(boost::make_reverse_iterator(const_reversed + N), N, array);
|
||||
|
||||
boost::const_nonconst_iterator_test(i, ++j);
|
||||
}
|
||||
|
||||
// Test reverse_iterator_generator again, with traits fully deducible on all platforms
|
||||
{
|
||||
std::deque<dummyT> reversed_container;
|
||||
std::reverse_copy(array, array + N, std::back_inserter(reversed_container));
|
||||
const std::deque<dummyT>::iterator reversed = reversed_container.begin();
|
||||
|
||||
|
||||
typedef boost::reverse_iterator<
|
||||
std::deque<dummyT>::iterator> reverse_iterator;
|
||||
typedef boost::reverse_iterator<
|
||||
std::deque<dummyT>::const_iterator> const_reverse_iterator;
|
||||
|
||||
// MSVC/STLport gives an INTERNAL COMPILER ERROR when any computation
|
||||
// (e.g. "reversed + N") is used in the constructor below.
|
||||
const std::deque<dummyT>::iterator finish = reversed_container.end();
|
||||
reverse_iterator i(finish);
|
||||
|
||||
boost::random_access_iterator_test(i, N, array);
|
||||
boost::random_access_iterator_test(boost::make_reverse_iterator(reversed + N), N, array);
|
||||
|
||||
const_reverse_iterator j = reverse_iterator(finish);
|
||||
boost::random_access_iterator_test(j, N, array);
|
||||
|
||||
const std::deque<dummyT>::const_iterator const_reversed = reversed;
|
||||
boost::random_access_iterator_test(boost::make_reverse_iterator(const_reversed + N), N, array);
|
||||
|
||||
// Many compilers' builtin deque iterators don't interoperate well, though
|
||||
// STLport fixes that problem.
|
||||
#if defined(__SGI_STL_PORT) \
|
||||
|| !BOOST_WORKAROUND(__GNUC__, <= 2) \
|
||||
&& !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) \
|
||||
&& !BOOST_WORKAROUND(__LIBCOMO_VERSION__, BOOST_TESTED_AT(29)) \
|
||||
&& !BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, <= 1)
|
||||
|
||||
boost::const_nonconst_iterator_test(i, ++j);
|
||||
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
// Copyright David Abrahams 2003. 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.
|
||||
#ifndef STATIC_ASSERT_SAME_DWA2003530_HPP
|
||||
# define STATIC_ASSERT_SAME_DWA2003530_HPP
|
||||
|
||||
# include <boost/type.hpp>
|
||||
|
||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T, class U>
|
||||
struct static_assert_same_base;
|
||||
|
||||
template <class T>
|
||||
struct static_assert_same_base<T,T>
|
||||
{
|
||||
enum { value = 1 };
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct static_assert_same : static_assert_same_base<T,U> {};
|
||||
|
||||
#else
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/mpl/bool.hpp>
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
|
||||
template <class T, class U>
|
||||
struct static_assert_same
|
||||
: boost::mpl::if_<boost::is_same<T,U>,boost::mpl::true_,void>::type
|
||||
{};
|
||||
#endif
|
||||
|
||||
#endif // STATIC_ASSERT_SAME_DWA2003530_HPP
|
@ -1,246 +0,0 @@
|
||||
// (C) Copyright Jeremy Siek 2002. 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
|
||||
// 22 Nov 2002 Thomas Witt
|
||||
// Added interoperability check.
|
||||
// 28 Oct 2002 Jeremy Siek
|
||||
// Updated for new iterator adaptors.
|
||||
// 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/transform_iterator.hpp>
|
||||
#include <boost/iterator/iterator_concepts.hpp>
|
||||
#include <boost/iterator/new_iterator_tests.hpp>
|
||||
#include <boost/pending/iterator_tests.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
|
||||
|
||||
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
namespace boost { namespace detail
|
||||
{
|
||||
template<> struct function_object_result<int (*)(int)>
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
}}
|
||||
#endif
|
||||
|
||||
struct mult_functor {
|
||||
// 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;
|
||||
};
|
||||
|
||||
struct adaptable_mult_functor
|
||||
: 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.
|
||||
adaptable_mult_functor() { }
|
||||
adaptable_mult_functor(int aa) : mult_functor(aa) { }
|
||||
};
|
||||
|
||||
|
||||
struct select_first
|
||||
{
|
||||
typedef int& result_type;
|
||||
|
||||
int& operator()(std::pair<int, int>& p) const
|
||||
{
|
||||
return p.first;
|
||||
}
|
||||
};
|
||||
|
||||
struct select_second
|
||||
{
|
||||
typedef int& result_type;
|
||||
|
||||
int& operator()(std::pair<int, int>& p) const
|
||||
{
|
||||
return p.second;
|
||||
}
|
||||
};
|
||||
|
||||
struct const_select_first
|
||||
{
|
||||
typedef int const& result_type;
|
||||
|
||||
int const& operator()(std::pair<int, int>const& p) const
|
||||
{
|
||||
return p.first;
|
||||
}
|
||||
};
|
||||
|
||||
struct value_select_first
|
||||
{
|
||||
typedef int result_type;
|
||||
|
||||
int operator()(std::pair<int, int>const& p) const
|
||||
{
|
||||
return p.first;
|
||||
}
|
||||
};
|
||||
|
||||
int mult_2(int arg)
|
||||
{
|
||||
return arg*2;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
const int N = 10;
|
||||
|
||||
// Concept checks
|
||||
{
|
||||
typedef boost::transform_iterator<adaptable_mult_functor, int*> iter_t;
|
||||
typedef boost::transform_iterator<adaptable_mult_functor, int const*> c_iter_t;
|
||||
|
||||
boost::function_requires< boost_concepts::InteroperableConcept<iter_t, c_iter_t> >();
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
typedef boost::transform_iterator<adaptable_mult_functor, int*> iter_t;
|
||||
iter_t i(y, adaptable_mult_functor(2));
|
||||
boost::input_iterator_test(i, x[0], x[1]);
|
||||
boost::input_iterator_test(iter_t(&y[0], adaptable_mult_functor(2)), x[0], x[1]);
|
||||
|
||||
boost::random_access_readable_iterator_test(i, N, x);
|
||||
}
|
||||
|
||||
// Test transform_iterator non adaptable functor
|
||||
{
|
||||
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;
|
||||
|
||||
typedef boost::transform_iterator<mult_functor, int*, int> iter_t;
|
||||
iter_t i(y, mult_functor(2));
|
||||
boost::input_iterator_test(i, x[0], x[1]);
|
||||
boost::input_iterator_test(iter_t(&y[0], mult_functor(2)), x[0], x[1]);
|
||||
|
||||
boost::random_access_readable_iterator_test(i, N, x);
|
||||
}
|
||||
|
||||
// Test transform_iterator default argument handling
|
||||
{
|
||||
{
|
||||
typedef boost::transform_iterator<adaptable_mult_functor, int*, float> iter_t;
|
||||
BOOST_STATIC_ASSERT((boost::is_same<iter_t::reference, float>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<iter_t::value_type, float>::value));
|
||||
}
|
||||
|
||||
{
|
||||
typedef boost::transform_iterator<adaptable_mult_functor, int*, boost::use_default, float> iter_t;
|
||||
BOOST_STATIC_ASSERT((boost::is_same<iter_t::reference, int>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<iter_t::value_type, float>::value));
|
||||
}
|
||||
|
||||
{
|
||||
typedef boost::transform_iterator<adaptable_mult_functor, int*, float, double> iter_t;
|
||||
BOOST_STATIC_ASSERT((boost::is_same<iter_t::reference, float>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<iter_t::value_type, double>::value));
|
||||
}
|
||||
}
|
||||
|
||||
// Test transform_iterator with function pointers
|
||||
{
|
||||
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::input_iterator_test(
|
||||
boost::make_transform_iterator(y, mult_2), x[0], x[1]);
|
||||
|
||||
boost::input_iterator_test(
|
||||
boost::make_transform_iterator(&y[0], mult_2), x[0], x[1]);
|
||||
|
||||
boost::random_access_readable_iterator_test(
|
||||
boost::make_transform_iterator(y, mult_2), N, x);
|
||||
|
||||
}
|
||||
|
||||
// Test transform_iterator as projection iterator
|
||||
{
|
||||
typedef std::pair<int, int> pair_t;
|
||||
|
||||
int x[N];
|
||||
int y[N];
|
||||
pair_t values[N];
|
||||
|
||||
for(int i = 0; i < N; ++i) {
|
||||
|
||||
x[i] = i;
|
||||
y[i] = N - (i + 1);
|
||||
|
||||
}
|
||||
|
||||
std::copy(
|
||||
x
|
||||
, x + N
|
||||
, boost::make_transform_iterator((pair_t*)values, select_first())
|
||||
);
|
||||
|
||||
std::copy(
|
||||
y
|
||||
, y + N
|
||||
, boost::make_transform_iterator((pair_t*)values, select_second())
|
||||
);
|
||||
|
||||
boost::random_access_readable_iterator_test(
|
||||
boost::make_transform_iterator((pair_t*)values, value_select_first())
|
||||
, N
|
||||
, x
|
||||
);
|
||||
|
||||
boost::random_access_readable_iterator_test(
|
||||
boost::make_transform_iterator((pair_t*)values, const_select_first())
|
||||
, N, x
|
||||
);
|
||||
|
||||
boost::constant_lvalue_iterator_test(
|
||||
boost::make_transform_iterator((pair_t*)values, const_select_first()), x[0]);
|
||||
|
||||
boost::non_const_lvalue_iterator_test(
|
||||
boost::make_transform_iterator((pair_t*)values, select_first()), x[0], 17);
|
||||
|
||||
}
|
||||
|
||||
std::cout << "test successful " << std::endl;
|
||||
return 0;
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
// Copyright David Abrahams 2003. 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.
|
||||
#include <boost/iterator/iterator_adaptor.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
#include "static_assert_same.hpp"
|
||||
|
||||
#include <boost/type_traits/broken_compiler_spec.hpp>
|
||||
|
||||
#include <boost/iterator/detail/minimum_category.hpp>
|
||||
|
||||
struct X { int a; };
|
||||
|
||||
BOOST_TT_BROKEN_COMPILER_SPEC(X)
|
||||
|
||||
struct Xiter : boost::iterator_adaptor<Xiter,X*>
|
||||
{
|
||||
Xiter();
|
||||
Xiter(X* p) : boost::iterator_adaptor<Xiter, X*>(p) {}
|
||||
};
|
||||
|
||||
void take_xptr(X*) {}
|
||||
void operator_arrow_test()
|
||||
{
|
||||
// check that the operator-> result is a pointer for lvalue iterators
|
||||
X x;
|
||||
take_xptr(Xiter(&x).operator->());
|
||||
}
|
||||
|
||||
template <class T, class U, class Min>
|
||||
struct static_assert_min_cat
|
||||
: static_assert_same<
|
||||
typename boost::detail::minimum_category<T,U>::type, Min
|
||||
>
|
||||
{};
|
||||
|
||||
void category_test()
|
||||
{
|
||||
using namespace boost;
|
||||
using namespace boost::detail;
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
!boost::is_convertible<
|
||||
std::input_iterator_tag
|
||||
, input_output_iterator_tag>::value));
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
!boost::is_convertible<
|
||||
std::output_iterator_tag
|
||||
, input_output_iterator_tag>::value));
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_convertible<
|
||||
input_output_iterator_tag
|
||||
, std::input_iterator_tag>::value));
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_convertible<
|
||||
input_output_iterator_tag
|
||||
, std::output_iterator_tag>::value));
|
||||
|
||||
#if 0 // This seems wrong; we're not advertising
|
||||
// input_output_iterator_tag are we?
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_convertible<
|
||||
std::forward_iterator_tag
|
||||
, input_output_iterator_tag>::value));
|
||||
#endif
|
||||
|
||||
int test = static_assert_min_cat<
|
||||
std::input_iterator_tag,input_output_iterator_tag, std::input_iterator_tag
|
||||
>::value;
|
||||
|
||||
test = static_assert_min_cat<
|
||||
input_output_iterator_tag,std::input_iterator_tag, std::input_iterator_tag
|
||||
>::value;
|
||||
|
||||
#if 0
|
||||
test = static_assert_min_cat<
|
||||
input_output_iterator_tag,std::forward_iterator_tag, input_output_iterator_tag
|
||||
>::value;
|
||||
#endif
|
||||
|
||||
test = static_assert_min_cat<
|
||||
std::input_iterator_tag,std::forward_iterator_tag, std::input_iterator_tag
|
||||
>::value;
|
||||
|
||||
test = static_assert_min_cat<
|
||||
std::input_iterator_tag,std::random_access_iterator_tag, std::input_iterator_tag
|
||||
>::value;
|
||||
|
||||
#if 0 // This would be wrong: a random access iterator is not
|
||||
// neccessarily writable, as is an output iterator.
|
||||
test = static_assert_min_cat<
|
||||
std::output_iterator_tag,std::random_access_iterator_tag, std::output_iterator_tag
|
||||
>::value;
|
||||
#endif
|
||||
|
||||
(void)test;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
category_test();
|
||||
operator_arrow_test();
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,910 +0,0 @@
|
||||
// (C) Copyright Dave Abrahams and Thomas Becker 2003. 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.
|
||||
//
|
||||
|
||||
// File:
|
||||
// =====
|
||||
// zip_iterator_test_main.cpp
|
||||
|
||||
// Author:
|
||||
// =======
|
||||
// Thomas Becker
|
||||
|
||||
// Created:
|
||||
// ========
|
||||
// Jul 15, 2003
|
||||
|
||||
// Purpose:
|
||||
// ========
|
||||
// Test driver for zip_iterator.hpp
|
||||
|
||||
// Compilers Tested:
|
||||
// =================
|
||||
// Metrowerks Codewarrior Pro 7.2, 8.3
|
||||
// gcc 2.95.3
|
||||
// gcc 3.2
|
||||
// Microsoft VC 6sp5 (test fails due to some compiler bug)
|
||||
// Microsoft VC 7 (works)
|
||||
// Microsoft VC 7.1
|
||||
// Intel 5
|
||||
// Intel 6
|
||||
// Intel 7.1
|
||||
// Intel 8
|
||||
// Borland 5.5.1 (broken due to lack of support from Boost.Tuples)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Includes
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <boost/iterator/zip_iterator.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/iterator/transform_iterator.hpp>
|
||||
#include <boost/iterator/is_readable_iterator.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <stddef.h>
|
||||
|
||||
template <class It>
|
||||
struct pure_traversal
|
||||
: boost::detail::pure_traversal_tag<
|
||||
typename boost::iterator_traversal<It>::type
|
||||
>
|
||||
{};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Das Main Funktion
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main( void )
|
||||
{
|
||||
|
||||
std::cout << "\n"
|
||||
<< "***********************************************\n"
|
||||
<< "* *\n"
|
||||
<< "* Test driver for boost::zip_iterator *\n"
|
||||
<< "* Copyright Thomas Becker 2003 *\n"
|
||||
<< "* *\n"
|
||||
<< "***********************************************\n\n"
|
||||
<< std::flush;
|
||||
|
||||
size_t num_successful_tests = 0;
|
||||
size_t num_failed_tests = 0;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Make sure tuples are supported
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Basic tuple support: "
|
||||
<< std::flush;
|
||||
|
||||
typedef boost::tuples::tuple<int, double> mytuple;
|
||||
mytuple t1;
|
||||
boost::tuples::get<0>(t1) = 42;
|
||||
boost::tuples::get<1>(t1) = 42.1;
|
||||
|
||||
if( 2 == boost::tuples::length<mytuple>::value &&
|
||||
42 == boost::tuples::get<0>(t1) &&
|
||||
42.1 == boost::tuples::get<1>(t1)
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Make sure iterator adaptor is supported
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Basic iterator adaptor support: "
|
||||
<< std::flush;
|
||||
|
||||
std::set<int> s;
|
||||
s.insert(42);
|
||||
s.insert(43);
|
||||
s.insert(44);
|
||||
|
||||
typedef boost::transform_iterator<
|
||||
std::binder1st<std::plus<int> >,
|
||||
std::set<int>::iterator
|
||||
>
|
||||
add_seven_iterator;
|
||||
|
||||
typedef boost::transform_iterator<
|
||||
std::binder1st<std::plus<int> >,
|
||||
std::set<int>::const_iterator
|
||||
>
|
||||
const_add_seven_iterator;
|
||||
|
||||
add_seven_iterator set_run(s.begin(), std::bind1st(std::plus<int>(), 7));
|
||||
add_seven_iterator set_end(s.end(), std::bind1st(std::plus<int>(), 7));
|
||||
|
||||
const_add_seven_iterator const_set_run(s.begin(), std::bind1st(std::plus<int>(), 7));
|
||||
// set_run = const_set_run; // Error: can't convert from const to non-const
|
||||
const_set_run = set_run;
|
||||
|
||||
if( 49 == *set_run &&
|
||||
50 == *++set_run &&
|
||||
51 == *++set_run &&
|
||||
set_end == ++set_run &&
|
||||
49 == *const_set_run &&
|
||||
50 == *++const_set_run &&
|
||||
51 == *++const_set_run &&
|
||||
set_end == ++const_set_run
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator construction and dereferencing
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator construction and dereferencing: "
|
||||
<< std::flush;
|
||||
|
||||
std::vector<double> vect1(3);
|
||||
vect1[0] = 42.;
|
||||
vect1[1] = 43.;
|
||||
vect1[2] = 44.;
|
||||
|
||||
std::set<int> intset;
|
||||
intset.insert(52);
|
||||
intset.insert(53);
|
||||
intset.insert(54);
|
||||
//
|
||||
|
||||
boost::zip_iterator<
|
||||
boost::tuples::tuple<
|
||||
std::set<int>::iterator
|
||||
, std::vector<double>::iterator
|
||||
>
|
||||
>
|
||||
zip_it_mixed(
|
||||
boost::make_tuple(
|
||||
intset.begin()
|
||||
, vect1.begin()
|
||||
)
|
||||
);
|
||||
|
||||
boost::tuples::tuple<int, double> val_tuple(
|
||||
*zip_it_mixed);
|
||||
|
||||
boost::tuples::tuple<const int&, double&> ref_tuple(
|
||||
*zip_it_mixed);
|
||||
|
||||
double dblOldVal = boost::tuples::get<1>(ref_tuple);
|
||||
boost::tuples::get<1>(ref_tuple) -= 41.;
|
||||
|
||||
if( 52 == boost::tuples::get<0>(val_tuple) &&
|
||||
42. == boost::tuples::get<1>(val_tuple) &&
|
||||
52 == boost::tuples::get<0>(ref_tuple) &&
|
||||
1. == boost::tuples::get<1>(ref_tuple) &&
|
||||
1. == *vect1.begin()
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
// Undo change to vect1
|
||||
boost::tuples::get<1>(ref_tuple) = dblOldVal;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator with 12 components
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterators with 12 components: "
|
||||
<< std::flush;
|
||||
|
||||
// Declare 12 containers
|
||||
//
|
||||
std::list<int> li1;
|
||||
li1.push_back(1);
|
||||
std::set<int> se1;
|
||||
se1.insert(2);
|
||||
std::vector<int> ve1;
|
||||
ve1.push_back(3);
|
||||
//
|
||||
std::list<int> li2;
|
||||
li2.push_back(4);
|
||||
std::set<int> se2;
|
||||
se2.insert(5);
|
||||
std::vector<int> ve2;
|
||||
ve2.push_back(6);
|
||||
//
|
||||
std::list<int> li3;
|
||||
li3.push_back(7);
|
||||
std::set<int> se3;
|
||||
se3.insert(8);
|
||||
std::vector<int> ve3;
|
||||
ve3.push_back(9);
|
||||
//
|
||||
std::list<int> li4;
|
||||
li4.push_back(10);
|
||||
std::set<int> se4;
|
||||
se4.insert(11);
|
||||
std::vector<int> ve4;
|
||||
ve4.push_back(12);
|
||||
|
||||
// typedefs for cons lists of iterators.
|
||||
typedef boost::tuples::cons<
|
||||
std::set<int>::iterator,
|
||||
boost::tuples::tuple<
|
||||
std::vector<int>::iterator,
|
||||
std::list<int>::iterator,
|
||||
std::set<int>::iterator,
|
||||
std::vector<int>::iterator,
|
||||
std::list<int>::iterator,
|
||||
std::set<int>::iterator,
|
||||
std::vector<int>::iterator,
|
||||
std::list<int>::iterator,
|
||||
std::set<int>::iterator,
|
||||
std::vector<int>::const_iterator
|
||||
>::inherited
|
||||
> cons_11_its_type;
|
||||
//
|
||||
typedef boost::tuples::cons<
|
||||
std::list<int>::const_iterator,
|
||||
cons_11_its_type
|
||||
> cons_12_its_type;
|
||||
|
||||
// typedefs for cons lists for dereferencing the zip iterator
|
||||
// made from the cons list above.
|
||||
typedef boost::tuples::cons<
|
||||
const int&,
|
||||
boost::tuples::tuple<
|
||||
int&,
|
||||
int&,
|
||||
const int&,
|
||||
int&,
|
||||
int&,
|
||||
const int&,
|
||||
int&,
|
||||
int&,
|
||||
const int&,
|
||||
const int&
|
||||
>::inherited
|
||||
> cons_11_refs_type;
|
||||
//
|
||||
typedef boost::tuples::cons<
|
||||
const int&,
|
||||
cons_11_refs_type
|
||||
> cons_12_refs_type;
|
||||
|
||||
// typedef for zip iterator with 12 elements
|
||||
typedef boost::zip_iterator<cons_12_its_type> zip_it_12_type;
|
||||
|
||||
// Declare a 12-element zip iterator.
|
||||
zip_it_12_type zip_it_12(
|
||||
cons_12_its_type(
|
||||
li1.begin(),
|
||||
cons_11_its_type(
|
||||
se1.begin(),
|
||||
boost::make_tuple(
|
||||
ve1.begin(),
|
||||
li2.begin(),
|
||||
se2.begin(),
|
||||
ve2.begin(),
|
||||
li3.begin(),
|
||||
se3.begin(),
|
||||
ve3.begin(),
|
||||
li4.begin(),
|
||||
se4.begin(),
|
||||
ve4.begin()
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Dereference, mess with the result a little.
|
||||
cons_12_refs_type zip_it_12_dereferenced(*zip_it_12);
|
||||
boost::tuples::get<9>(zip_it_12_dereferenced) = 42;
|
||||
|
||||
// Make a copy and move it a little to force some instantiations.
|
||||
zip_it_12_type zip_it_12_copy(zip_it_12);
|
||||
++zip_it_12_copy;
|
||||
|
||||
if( boost::tuples::get<11>(zip_it_12.get_iterator_tuple()) == ve4.begin() &&
|
||||
boost::tuples::get<11>(zip_it_12_copy.get_iterator_tuple()) == ve4.end() &&
|
||||
1 == boost::tuples::get<0>(zip_it_12_dereferenced) &&
|
||||
12 == boost::tuples::get<11>(zip_it_12_dereferenced) &&
|
||||
42 == *(li4.begin())
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator incrementing and dereferencing
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator ++ and *: "
|
||||
<< std::flush;
|
||||
|
||||
std::vector<double> vect2(3);
|
||||
vect2[0] = 2.2;
|
||||
vect2[1] = 3.3;
|
||||
vect2[2] = 4.4;
|
||||
|
||||
boost::zip_iterator<
|
||||
boost::tuples::tuple<
|
||||
std::vector<double>::const_iterator,
|
||||
std::vector<double>::const_iterator
|
||||
>
|
||||
>
|
||||
zip_it_begin(
|
||||
boost::make_tuple(
|
||||
vect1.begin(),
|
||||
vect2.begin()
|
||||
)
|
||||
);
|
||||
|
||||
boost::zip_iterator<
|
||||
boost::tuples::tuple<
|
||||
std::vector<double>::const_iterator,
|
||||
std::vector<double>::const_iterator
|
||||
>
|
||||
>
|
||||
zip_it_run(
|
||||
boost::make_tuple(
|
||||
vect1.begin(),
|
||||
vect2.begin()
|
||||
)
|
||||
);
|
||||
|
||||
boost::zip_iterator<
|
||||
boost::tuples::tuple<
|
||||
std::vector<double>::const_iterator,
|
||||
std::vector<double>::const_iterator
|
||||
>
|
||||
>
|
||||
zip_it_end(
|
||||
boost::make_tuple(
|
||||
vect1.end(),
|
||||
vect2.end()
|
||||
)
|
||||
);
|
||||
|
||||
if( zip_it_run == zip_it_begin &&
|
||||
42. == boost::tuples::get<0>(*zip_it_run) &&
|
||||
2.2 == boost::tuples::get<1>(*zip_it_run) &&
|
||||
43. == boost::tuples::get<0>(*(++zip_it_run)) &&
|
||||
3.3 == boost::tuples::get<1>(*zip_it_run) &&
|
||||
44. == boost::tuples::get<0>(*(++zip_it_run)) &&
|
||||
4.4 == boost::tuples::get<1>(*zip_it_run) &&
|
||||
zip_it_end == ++zip_it_run
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator decrementing and dereferencing
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator -- and *: "
|
||||
<< std::flush;
|
||||
|
||||
if( zip_it_run == zip_it_end &&
|
||||
zip_it_end == zip_it_run-- &&
|
||||
44. == boost::tuples::get<0>(*zip_it_run) &&
|
||||
4.4 == boost::tuples::get<1>(*zip_it_run) &&
|
||||
43. == boost::tuples::get<0>(*(--zip_it_run)) &&
|
||||
3.3 == boost::tuples::get<1>(*zip_it_run) &&
|
||||
42. == boost::tuples::get<0>(*(--zip_it_run)) &&
|
||||
2.2 == boost::tuples::get<1>(*zip_it_run) &&
|
||||
zip_it_begin == zip_it_run
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator copy construction and equality
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator copy construction and equality: "
|
||||
<< std::flush;
|
||||
|
||||
boost::zip_iterator<
|
||||
boost::tuples::tuple<
|
||||
std::vector<double>::const_iterator,
|
||||
std::vector<double>::const_iterator
|
||||
>
|
||||
> zip_it_run_copy(zip_it_run);
|
||||
|
||||
if(zip_it_run == zip_it_run && zip_it_run == zip_it_run_copy)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator inequality
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator inequality: "
|
||||
<< std::flush;
|
||||
|
||||
if(!(zip_it_run != zip_it_run_copy) && zip_it_run != ++zip_it_run_copy)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator less than
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator less than: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run_copy == zip_it_run + 1
|
||||
//
|
||||
if( zip_it_run < zip_it_run_copy &&
|
||||
!( zip_it_run < --zip_it_run_copy) &&
|
||||
zip_it_run == zip_it_run_copy
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator less than or equal
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "zip iterator less than or equal: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run_copy == zip_it_run
|
||||
//
|
||||
++zip_it_run;
|
||||
zip_it_run_copy += 2;
|
||||
|
||||
if( zip_it_run <= zip_it_run_copy &&
|
||||
zip_it_run <= --zip_it_run_copy &&
|
||||
!( zip_it_run <= --zip_it_run_copy) &&
|
||||
zip_it_run <= zip_it_run
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator greater than
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator greater than: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run_copy == zip_it_run - 1
|
||||
//
|
||||
if( zip_it_run > zip_it_run_copy &&
|
||||
!( zip_it_run > ++zip_it_run_copy) &&
|
||||
zip_it_run == zip_it_run_copy
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator greater than or equal
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator greater than or equal: "
|
||||
<< std::flush;
|
||||
|
||||
++zip_it_run;
|
||||
|
||||
// Note: zip_it_run == zip_it_run_copy + 1
|
||||
//
|
||||
if( zip_it_run >= zip_it_run_copy &&
|
||||
--zip_it_run >= zip_it_run_copy &&
|
||||
! (zip_it_run >= ++zip_it_run_copy)
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator + int
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator + int: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run == zip_it_run_copy - 1
|
||||
//
|
||||
zip_it_run = zip_it_run + 2;
|
||||
++zip_it_run_copy;
|
||||
|
||||
if( zip_it_run == zip_it_run_copy && zip_it_run == zip_it_begin + 3 )
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator - int
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator - int: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run == zip_it_run_copy, and both are at end position
|
||||
//
|
||||
zip_it_run = zip_it_run - 2;
|
||||
--zip_it_run_copy;
|
||||
--zip_it_run_copy;
|
||||
|
||||
if( zip_it_run == zip_it_run_copy && (zip_it_run - 1) == zip_it_begin )
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator +=
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator +=: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run == zip_it_run_copy, and both are at begin + 1
|
||||
//
|
||||
zip_it_run += 2;
|
||||
if( zip_it_run == zip_it_begin + 3 )
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator -=
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator -=: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run is at end position, zip_it_run_copy is at
|
||||
// begin plus one.
|
||||
//
|
||||
zip_it_run -= 2;
|
||||
if( zip_it_run == zip_it_run_copy )
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator getting member iterators
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator member iterators: "
|
||||
<< std::flush;
|
||||
|
||||
// Note: zip_it_run and zip_it_run_copy are both at
|
||||
// begin plus one.
|
||||
//
|
||||
if( boost::tuples::get<0>(zip_it_run.get_iterator_tuple()) == vect1.begin() + 1 &&
|
||||
boost::tuples::get<1>(zip_it_run.get_iterator_tuple()) == vect2.begin() + 1
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Making zip iterators
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Making zip iterators: "
|
||||
<< std::flush;
|
||||
|
||||
std::vector<boost::tuples::tuple<double, double> >
|
||||
vect_of_tuples(3);
|
||||
|
||||
std::copy(
|
||||
boost::make_zip_iterator(
|
||||
boost::make_tuple(
|
||||
vect1.begin(),
|
||||
vect2.begin()
|
||||
)
|
||||
),
|
||||
boost::make_zip_iterator(
|
||||
boost::make_tuple(
|
||||
vect1.end(),
|
||||
vect2.end()
|
||||
)
|
||||
),
|
||||
vect_of_tuples.begin()
|
||||
);
|
||||
|
||||
if( 42. == boost::tuples::get<0>(*vect_of_tuples.begin()) &&
|
||||
2.2 == boost::tuples::get<1>(*vect_of_tuples.begin()) &&
|
||||
43. == boost::tuples::get<0>(*(vect_of_tuples.begin() + 1)) &&
|
||||
3.3 == boost::tuples::get<1>(*(vect_of_tuples.begin() + 1)) &&
|
||||
44. == boost::tuples::get<0>(*(vect_of_tuples.begin() + 2)) &&
|
||||
4.4 == boost::tuples::get<1>(*(vect_of_tuples.begin() + 2))
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator non-const --> const conversion
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator non-const to const conversion: "
|
||||
<< std::flush;
|
||||
|
||||
boost::zip_iterator<
|
||||
boost::tuples::tuple<
|
||||
std::set<int>::const_iterator,
|
||||
std::vector<double>::const_iterator
|
||||
>
|
||||
>
|
||||
zip_it_const(
|
||||
boost::make_tuple(
|
||||
intset.begin(),
|
||||
vect2.begin()
|
||||
)
|
||||
);
|
||||
//
|
||||
boost::zip_iterator<
|
||||
boost::tuples::tuple<
|
||||
std::set<int>::iterator,
|
||||
std::vector<double>::const_iterator
|
||||
>
|
||||
>
|
||||
zip_it_half_const(
|
||||
boost::make_tuple(
|
||||
intset.begin(),
|
||||
vect2.begin()
|
||||
)
|
||||
);
|
||||
//
|
||||
boost::zip_iterator<
|
||||
boost::tuples::tuple<
|
||||
std::set<int>::iterator,
|
||||
std::vector<double>::iterator
|
||||
>
|
||||
>
|
||||
zip_it_non_const(
|
||||
boost::make_tuple(
|
||||
intset.begin(),
|
||||
vect2.begin()
|
||||
)
|
||||
);
|
||||
|
||||
zip_it_half_const = ++zip_it_non_const;
|
||||
zip_it_const = zip_it_half_const;
|
||||
++zip_it_const;
|
||||
// zip_it_non_const = ++zip_it_const; // Error: can't convert from const to non-const
|
||||
|
||||
if( 54 == boost::tuples::get<0>(*zip_it_const) &&
|
||||
4.4 == boost::tuples::get<1>(*zip_it_const) &&
|
||||
53 == boost::tuples::get<0>(*zip_it_half_const) &&
|
||||
3.3 == boost::tuples::get<1>(*zip_it_half_const)
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Zip iterator categories
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::cout << "Zip iterator categories: "
|
||||
<< std::flush;
|
||||
|
||||
// The big iterator of the previous test has vector, list, and set iterators.
|
||||
// Therefore, it must be bidirectional, but not random access.
|
||||
bool bBigItIsBidirectionalIterator = boost::is_convertible<
|
||||
boost::iterator_traversal<zip_it_12_type>::type
|
||||
, boost::bidirectional_traversal_tag
|
||||
>::value;
|
||||
|
||||
bool bBigItIsRandomAccessIterator = boost::is_convertible<
|
||||
boost::iterator_traversal<zip_it_12_type>::type
|
||||
, boost::random_access_traversal_tag
|
||||
>::value;
|
||||
|
||||
// A combining iterator with all vector iterators must have random access
|
||||
// traversal.
|
||||
//
|
||||
typedef boost::zip_iterator<
|
||||
boost::tuples::tuple<
|
||||
std::vector<double>::const_iterator,
|
||||
std::vector<double>::const_iterator
|
||||
>
|
||||
> all_vects_type;
|
||||
|
||||
bool bAllVectsIsRandomAccessIterator = boost::is_convertible<
|
||||
boost::iterator_traversal<all_vects_type>::type
|
||||
, boost::random_access_traversal_tag
|
||||
>::value;
|
||||
|
||||
// The big test.
|
||||
if( bBigItIsBidirectionalIterator &&
|
||||
! bBigItIsRandomAccessIterator &&
|
||||
bAllVectsIsRandomAccessIterator
|
||||
)
|
||||
{
|
||||
++num_successful_tests;
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
++num_failed_tests = 0;
|
||||
std::cout << "not OK" << std::endl;
|
||||
}
|
||||
|
||||
// Done
|
||||
//
|
||||
std::cout << "\nTest Result:"
|
||||
<< "\n============"
|
||||
<< "\nNumber of successful tests: " << static_cast<unsigned int>(num_successful_tests)
|
||||
<< "\nNumber of failed tests: " << static_cast<unsigned int>(num_failed_tests)
|
||||
<< std::endl;
|
||||
|
||||
return num_failed_tests;
|
||||
}
|
||||
|
Reference in New Issue
Block a user