mirror of
https://github.com/boostorg/iterator.git
synced 2025-06-27 21:11:02 +02:00
Compare commits
82 Commits
boost-1.20
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
abffbb8300 | |||
34c159dd8d | |||
b22a3adc02 | |||
4a24e0f401 | |||
3844edc4bf | |||
fdd1601ba4 | |||
e9b33b336c | |||
2574365b5c | |||
12b9366f33 | |||
4772bb099e | |||
2be5179020 | |||
8cb49713b4 | |||
bd666dc0e9 | |||
57251d58cc | |||
ebcb4d861a | |||
15a7a839f9 | |||
76a307d31e | |||
37aee7c13b | |||
50a502bb81 | |||
8a4839354e | |||
4da7371246 | |||
e162a75e53 | |||
e60df6ad92 | |||
4c2b3a9d2c | |||
75023a1dd3 | |||
79370a6dfb | |||
4566798afc | |||
3fd1c4bc5d | |||
2d6f48d5ab | |||
d1c7594344 | |||
ac327f51e9 | |||
4e18b11263 | |||
81e3df2b36 | |||
ac05307515 | |||
552a1e6785 | |||
134b8b51aa | |||
efecfd17b9 | |||
799158841e | |||
582ebfd054 | |||
42e4db1539 | |||
d7023154a3 | |||
9582b2223c | |||
d7908fb81f | |||
e48cdcb94f | |||
0846ad5fd0 | |||
84663ff2e2 | |||
6de1934420 | |||
a110b9fd27 | |||
eb06c122d1 | |||
cbbe851adb | |||
f6cc2e520f | |||
4e29b5aa29 | |||
d924f56ad8 | |||
f27fd095f7 | |||
d22edf735a | |||
af8dd117d5 | |||
149d07cda0 | |||
e9d9bdbb10 | |||
8d8f828da5 | |||
fc15f5f710 | |||
ef66d28b19 | |||
0c8d74863f | |||
1c73f1f2ae | |||
ee20a630dd | |||
c2472221ef | |||
bf45977491 | |||
1988994bd3 | |||
5482763a93 | |||
2c2a3eab21 | |||
dca20fae75 | |||
e3aaf2cc91 | |||
ea4c7c7dd9 | |||
fd6ba58d5e | |||
268e70faa1 | |||
170b44763d | |||
b2701f9f78 | |||
ad4c5ab089 | |||
c585adde71 | |||
c5f24d0d72 | |||
dbb99b1cf3 | |||
be44a4714b | |||
e9f24023d4 |
@ -1,282 +0,0 @@
|
|||||||
#ifndef BOOST_ITERATOR_CONCEPTS_HPP
|
|
||||||
#define BOOST_ITERATOR_CONCEPTS_HPP
|
|
||||||
|
|
||||||
#include <boost/concept_check.hpp>
|
|
||||||
#include <boost/iterator_traits.hpp>
|
|
||||||
|
|
||||||
namespace boost_concepts {
|
|
||||||
// Used a different namespace here (instead of "boost") so that the
|
|
||||||
// concept descriptions do not take for granted the names in
|
|
||||||
// namespace boost.
|
|
||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
|
|
||||||
template <typename Iterator>
|
|
||||||
class ReadableIteratorConcept {
|
|
||||||
public:
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::value_type value_type;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::reference reference;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::return_category
|
|
||||||
return_category;
|
|
||||||
|
|
||||||
void constraints() {
|
|
||||||
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
|
|
||||||
boost::function_requires< boost::EqualityComparableConcept<Iterator> >();
|
|
||||||
boost::function_requires< boost::DefaultConstructibleConcept<Iterator> >();
|
|
||||||
|
|
||||||
boost::function_requires<
|
|
||||||
boost::ConvertibleConcept<return_category, boost::readable_iterator_tag> >();
|
|
||||||
|
|
||||||
reference r = *i; // or perhaps read(x)
|
|
||||||
value_type v(r);
|
|
||||||
boost::ignore_unused_variable_warning(v);
|
|
||||||
}
|
|
||||||
Iterator i;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Iterator, typename ValueType>
|
|
||||||
class WritableIteratorConcept {
|
|
||||||
public:
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::return_category
|
|
||||||
return_category;
|
|
||||||
|
|
||||||
void constraints() {
|
|
||||||
boost::function_requires< boost::SGIAssignableConcept<Iterator> >();
|
|
||||||
boost::function_requires< boost::EqualityComparableConcept<Iterator> >();
|
|
||||||
boost::function_requires< boost::DefaultConstructibleConcept<Iterator> >();
|
|
||||||
|
|
||||||
boost::function_requires<
|
|
||||||
boost::ConvertibleConcept<return_category, boost::writable_iterator_tag> >();
|
|
||||||
|
|
||||||
*i = v; // an alternative could be something like write(x, v)
|
|
||||||
}
|
|
||||||
ValueType v;
|
|
||||||
Iterator i;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Iterator>
|
|
||||||
class ConstantLvalueIteratorConcept {
|
|
||||||
public:
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::value_type value_type;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::reference reference;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::return_category
|
|
||||||
return_category;
|
|
||||||
|
|
||||||
void constraints() {
|
|
||||||
boost::function_requires< ReadableIteratorConcept<Iterator> >();
|
|
||||||
|
|
||||||
boost::function_requires<
|
|
||||||
boost::ConvertibleConcept<return_category,
|
|
||||||
boost::constant_lvalue_iterator_tag> >();
|
|
||||||
|
|
||||||
typedef typename boost::require_same<reference, const value_type&>::type req;
|
|
||||||
|
|
||||||
reference v = *i;
|
|
||||||
boost::ignore_unused_variable_warning(v);
|
|
||||||
}
|
|
||||||
Iterator i;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Iterator>
|
|
||||||
class MutableLvalueIteratorConcept {
|
|
||||||
public:
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::value_type value_type;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::reference reference;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::return_category
|
|
||||||
return_category;
|
|
||||||
|
|
||||||
void constraints() {
|
|
||||||
boost::function_requires< ReadableIteratorConcept<Iterator> >();
|
|
||||||
boost::function_requires< WritableIteratorConcept<Iterator, value_type> >();
|
|
||||||
|
|
||||||
boost::function_requires<
|
|
||||||
boost::ConvertibleConcept<return_category,
|
|
||||||
boost::constant_lvalue_iterator_tag> >();
|
|
||||||
|
|
||||||
typedef typename boost::require_same<reference, value_type&>::type req;
|
|
||||||
|
|
||||||
reference v = *i;
|
|
||||||
boost::ignore_unused_variable_warning(v);
|
|
||||||
}
|
|
||||||
Iterator i;
|
|
||||||
};
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
|
|
||||||
template <typename Iterator>
|
|
||||||
class SinglePassIteratorConcept {
|
|
||||||
public:
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::motion_category
|
|
||||||
motion_category;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::difference_type
|
|
||||||
difference_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::ConvertibleConcept<motion_category,
|
|
||||||
boost::single_pass_iterator_tag> >();
|
|
||||||
|
|
||||||
// difference_type must be a signed integral type
|
|
||||||
|
|
||||||
++i;
|
|
||||||
(void)i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator i;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Iterator>
|
|
||||||
class ForwardIteratorConcept {
|
|
||||||
public:
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::motion_category
|
|
||||||
motion_category;
|
|
||||||
|
|
||||||
void constraints() {
|
|
||||||
boost::function_requires< SinglePassIteratorConcept<Iterator> >();
|
|
||||||
|
|
||||||
boost::function_requires<
|
|
||||||
boost::ConvertibleConcept<motion_category,
|
|
||||||
boost::forward_iterator_tag> >();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Iterator>
|
|
||||||
class BidirectionalIteratorConcept {
|
|
||||||
public:
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::motion_category
|
|
||||||
motion_category;
|
|
||||||
|
|
||||||
void constraints() {
|
|
||||||
boost::function_requires< ForwardIteratorConcept<Iterator> >();
|
|
||||||
|
|
||||||
boost::function_requires<
|
|
||||||
boost::ConvertibleConcept<motion_category,
|
|
||||||
boost::bidirectional_iterator_tag> >();
|
|
||||||
|
|
||||||
--i;
|
|
||||||
(void)i--;
|
|
||||||
}
|
|
||||||
Iterator i;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Iterator>
|
|
||||||
class RandomAccessIteratorConcept {
|
|
||||||
public:
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::motion_category
|
|
||||||
motion_category;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::difference_type
|
|
||||||
difference_type;
|
|
||||||
|
|
||||||
void constraints() {
|
|
||||||
boost::function_requires< BidirectionalIteratorConcept<Iterator> >();
|
|
||||||
|
|
||||||
boost::function_requires<
|
|
||||||
boost::ConvertibleConcept<motion_category,
|
|
||||||
boost::random_access_iterator_tag> >();
|
|
||||||
|
|
||||||
i += n;
|
|
||||||
i = i + n;
|
|
||||||
i = n + i;
|
|
||||||
i -= n;
|
|
||||||
i = i - n;
|
|
||||||
n = i - j;
|
|
||||||
}
|
|
||||||
difference_type n;
|
|
||||||
Iterator i, j;
|
|
||||||
};
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
|
|
||||||
template <typename Iterator>
|
|
||||||
class ReadableRandomAccessIteratorConcept {
|
|
||||||
public:
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::value_type value_type;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::reference reference;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::difference_type
|
|
||||||
difference_type;
|
|
||||||
|
|
||||||
void constraints() {
|
|
||||||
boost::function_requires< RandomAccessIteratorConcept<Iterator> >();
|
|
||||||
boost::function_requires< ReadableIteratorConcept<Iterator> >();
|
|
||||||
|
|
||||||
reference r = i[n];
|
|
||||||
value_type v(r);
|
|
||||||
boost::ignore_unused_variable_warning(v);
|
|
||||||
}
|
|
||||||
difference_type n;
|
|
||||||
Iterator i;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Iterator>
|
|
||||||
class WritableRandomAccessIteratorConcept {
|
|
||||||
public:
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::value_type value_type;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::difference_type
|
|
||||||
difference_type;
|
|
||||||
|
|
||||||
void constraints() {
|
|
||||||
boost::function_requires< RandomAccessIteratorConcept<Iterator> >();
|
|
||||||
boost::function_requires< WritableIteratorConcept<Iterator, value_type> >();
|
|
||||||
|
|
||||||
i[n] = v;
|
|
||||||
boost::ignore_unused_variable_warning(v);
|
|
||||||
}
|
|
||||||
difference_type n;
|
|
||||||
value_type v;
|
|
||||||
Iterator i;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Iterator>
|
|
||||||
class ConstantLvalueRandomAccessIteratorConcept {
|
|
||||||
public:
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::value_type value_type;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::reference reference;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::difference_type
|
|
||||||
difference_type;
|
|
||||||
|
|
||||||
void constraints() {
|
|
||||||
boost::function_requires< RandomAccessIteratorConcept<Iterator> >();
|
|
||||||
boost::function_requires< ReadableIteratorConcept<Iterator> >();
|
|
||||||
|
|
||||||
typedef typename boost::require_same<reference, const value_type&>::type req;
|
|
||||||
|
|
||||||
reference v = i[n];
|
|
||||||
boost::ignore_unused_variable_warning(v);
|
|
||||||
}
|
|
||||||
difference_type n;
|
|
||||||
value_type v;
|
|
||||||
Iterator i;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Iterator>
|
|
||||||
class MutableLvalueRandomAccessIteratorConcept {
|
|
||||||
public:
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::value_type value_type;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::reference reference;
|
|
||||||
typedef typename boost::iterator_traits<Iterator>::difference_type
|
|
||||||
difference_type;
|
|
||||||
|
|
||||||
void constraints() {
|
|
||||||
boost::function_requires< RandomAccessIteratorConcept<Iterator> >();
|
|
||||||
boost::function_requires< WritableIteratorConcept<Iterator, value_type> >();
|
|
||||||
boost::function_requires< ReadableIteratorConcept<Iterator> >();
|
|
||||||
|
|
||||||
typedef typename boost::require_same<reference, value_type&>::type req;
|
|
||||||
|
|
||||||
reference v = i[n];
|
|
||||||
boost::ignore_unused_variable_warning(v);
|
|
||||||
}
|
|
||||||
difference_type n;
|
|
||||||
value_type v;
|
|
||||||
Iterator i;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace boost_concepts
|
|
||||||
|
|
||||||
|
|
||||||
#endif // BOOST_ITERATOR_CONCEPTS_HPP
|
|
@ -1,60 +0,0 @@
|
|||||||
#ifndef BOOST_ITERATOR_TRAITS_HPP
|
|
||||||
#define BOOST_ITERATOR_TRAITS_HPP
|
|
||||||
|
|
||||||
#include <boost/config.hpp>
|
|
||||||
#include <boost/type_traits.hpp>
|
|
||||||
|
|
||||||
namespace boost {
|
|
||||||
|
|
||||||
template <typename Iterator>
|
|
||||||
struct iterator_traits {
|
|
||||||
typedef typename Iterator::value_type value_type;
|
|
||||||
typedef typename Iterator::reference reference;
|
|
||||||
typedef typename Iterator::pointer pointer;
|
|
||||||
typedef typename Iterator::difference_type difference_type;
|
|
||||||
typedef typename Iterator::return_category return_category;
|
|
||||||
typedef typename Iterator::motion_category motion_category;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Motion Categories
|
|
||||||
struct single_pass_iterator_tag { };
|
|
||||||
struct forward_iterator_tag : public single_pass_iterator_tag { };
|
|
||||||
struct bidirectional_iterator_tag : public forward_iterator_tag { };
|
|
||||||
struct random_access_iterator_tag : public bidirectional_iterator_tag { };
|
|
||||||
|
|
||||||
// Return Type Categories
|
|
||||||
struct readable_iterator_tag { };
|
|
||||||
struct writable_iterator_tag { };
|
|
||||||
struct mutable_lvalue_iterator_tag : virtual public writable_iterator_tag,
|
|
||||||
virtual public readable_iterator_tag { };
|
|
||||||
struct constant_lvalue_iterator_tag : public readable_iterator_tag { };
|
|
||||||
|
|
||||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
template <bool IsConst>
|
|
||||||
struct pointer_return_category {
|
|
||||||
typedef constant_lvalue_iterator_tag type;
|
|
||||||
};
|
|
||||||
template <>
|
|
||||||
struct pointer_return_category<false> {
|
|
||||||
typedef mutable_lvalue_iterator_tag type;
|
|
||||||
};
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct iterator_traits<T*> {
|
|
||||||
typedef T value_type;
|
|
||||||
typedef T& reference;
|
|
||||||
typedef T* pointer;
|
|
||||||
typedef std::ptrdiff_t difference_type;
|
|
||||||
typedef typename detail::pointer_return_category<is_const<T>::value>::type
|
|
||||||
return_category;
|
|
||||||
typedef random_access_iterator_tag motion_category;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
#endif // BOOST_ITERATOR_TRAITS_HPP
|
|
@ -1,13 +0,0 @@
|
|||||||
#include <boost/iterator_concepts.hpp>
|
|
||||||
|
|
||||||
int
|
|
||||||
main()
|
|
||||||
{
|
|
||||||
boost::function_requires<
|
|
||||||
boost_concepts::MutableLvalueRandomAccessIteratorConcept<int*> >();
|
|
||||||
|
|
||||||
boost::function_requires<
|
|
||||||
boost_concepts::ConstantLvalueRandomAccessIteratorConcept<const int*> >();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -28,6 +28,14 @@
|
|||||||
// Incrementable.
|
// Incrementable.
|
||||||
//
|
//
|
||||||
// Revision History
|
// Revision History
|
||||||
|
// 14 Feb 2001 Removed unnecessary typedefs from counting_iterator_traits
|
||||||
|
// (Jeremy Siek)
|
||||||
|
// 11 Feb 2001 Use BOOST_STATIC_CONSTANT (Dave Abrahams)
|
||||||
|
// 11 Feb 2001 Clean up after John Maddocks's (finally effective!) Borland
|
||||||
|
// fixes (David Abrahams).
|
||||||
|
// 10 Feb 2001 Use new iterator_adaptor<> interface (David Abrahams)
|
||||||
|
// 10 Feb 2001 Rolled in supposed Borland fixes from John Maddock, but not
|
||||||
|
// seeing any improvement yet (David Abrahams)
|
||||||
// 09 Feb 2001 Factored out is_numeric computation. Borland still
|
// 09 Feb 2001 Factored out is_numeric computation. Borland still
|
||||||
// unhappy :( (David Abrahams)
|
// unhappy :( (David Abrahams)
|
||||||
// 08 Feb 2001 Beginning of a failed attempt to appease Borland
|
// 08 Feb 2001 Beginning of a failed attempt to appease Borland
|
||||||
@ -48,9 +56,7 @@
|
|||||||
# include <boost/type_traits.hpp>
|
# include <boost/type_traits.hpp>
|
||||||
# include <boost/detail/numeric_traits.hpp>
|
# include <boost/detail/numeric_traits.hpp>
|
||||||
# include <boost/static_assert.hpp>
|
# include <boost/static_assert.hpp>
|
||||||
# ifndef BOOST_NO_LIMITS
|
# include <boost/limits.hpp>
|
||||||
# include <limits>
|
|
||||||
# endif
|
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
|
|
||||||
@ -126,15 +132,24 @@ namespace detail {
|
|||||||
struct is_numeric {
|
struct is_numeric {
|
||||||
// For a while, this wasn't true, but we rely on it below. This is a regression assert.
|
// For a while, this wasn't true, but we rely on it below. This is a regression assert.
|
||||||
BOOST_STATIC_ASSERT(::boost::is_integral<char>::value);
|
BOOST_STATIC_ASSERT(::boost::is_integral<char>::value);
|
||||||
enum { value =
|
# ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
# if defined(BOOST_HAS_LONG_LONG)
|
||||||
std::numeric_limits<T>::is_specialized
|
BOOST_STATIC_CONSTANT(bool,
|
||||||
#elif defined(__BORLANDC__)
|
value = (
|
||||||
::boost::is_integral<T>::value
|
std::numeric_limits<T>::is_specialized
|
||||||
#else
|
| boost::is_same<T,long long>::value
|
||||||
boost::is_convertible<int,T>::value && boost::is_convertible<T,int>::value
|
| boost::is_same<T,unsigned long long>::value));
|
||||||
#endif
|
# else
|
||||||
};
|
BOOST_STATIC_CONSTANT(bool, value = std::numeric_limits<T>::is_specialized);
|
||||||
|
# endif
|
||||||
|
# else
|
||||||
|
# if !defined(__BORLANDC__)
|
||||||
|
BOOST_STATIC_CONSTANT(bool, value = (
|
||||||
|
boost::is_convertible<int,T>::value && boost::is_convertible<T,int>::value));
|
||||||
|
# else
|
||||||
|
BOOST_STATIC_CONSTANT(bool, value = ::boost::is_arithmetic<T>::value);
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// Compute the distance over arbitrary numeric and/or iterator types
|
// Compute the distance over arbitrary numeric and/or iterator types
|
||||||
@ -152,14 +167,11 @@ namespace detail {
|
|||||||
template <class Incrementable>
|
template <class Incrementable>
|
||||||
struct counting_iterator_traits {
|
struct counting_iterator_traits {
|
||||||
private:
|
private:
|
||||||
enum {numeric = detail::is_numeric<Incrementable>::value };
|
typedef ::boost::detail::counting_iterator_traits_select<(
|
||||||
typedef typename detail::counting_iterator_traits_select<(
|
::boost::detail::is_numeric<Incrementable>::value
|
||||||
numeric
|
)> binder;
|
||||||
)>::template traits<Incrementable> traits;
|
typedef typename binder::template traits<Incrementable> traits;
|
||||||
public:
|
public:
|
||||||
typedef Incrementable value_type;
|
|
||||||
typedef const Incrementable& reference;
|
|
||||||
typedef const value_type* pointer;
|
|
||||||
typedef typename traits::difference_type difference_type;
|
typedef typename traits::difference_type difference_type;
|
||||||
typedef typename traits::iterator_category iterator_category;
|
typedef typename traits::iterator_category iterator_category;
|
||||||
};
|
};
|
||||||
@ -167,14 +179,17 @@ struct counting_iterator_traits {
|
|||||||
template <class Incrementable>
|
template <class Incrementable>
|
||||||
struct counting_iterator_policies : public default_iterator_policies
|
struct counting_iterator_policies : public default_iterator_policies
|
||||||
{
|
{
|
||||||
const Incrementable& dereference(type<const Incrementable&>, const Incrementable& i) const
|
template <class IteratorAdaptor>
|
||||||
{ return i; }
|
typename IteratorAdaptor::reference dereference(const IteratorAdaptor& i) const
|
||||||
|
{ return i.base(); }
|
||||||
template <class Difference, class Iterator1, class Iterator2>
|
|
||||||
Difference distance(type<Difference>, const Iterator1& x,
|
template <class Iterator1, class Iterator2>
|
||||||
const Iterator2& y) const
|
typename Iterator1::difference_type distance(
|
||||||
|
const Iterator1& x, const Iterator2& y) const
|
||||||
{
|
{
|
||||||
return boost::detail::any_distance<Difference>(x, y);//,(Difference*)());
|
typedef typename Iterator1::difference_type difference_type;
|
||||||
|
return boost::detail::any_distance<difference_type>(
|
||||||
|
x.base(), y.base());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -182,9 +197,21 @@ struct counting_iterator_policies : public default_iterator_policies
|
|||||||
template <class Incrementable>
|
template <class Incrementable>
|
||||||
struct counting_iterator_generator
|
struct counting_iterator_generator
|
||||||
{
|
{
|
||||||
typedef iterator_adaptor<Incrementable,
|
typedef typename boost::remove_const<
|
||||||
counting_iterator_policies<Incrementable>,
|
Incrementable
|
||||||
counting_iterator_traits<Incrementable> > type;
|
>::type value_type;
|
||||||
|
|
||||||
|
typedef counting_iterator_traits<value_type> traits;
|
||||||
|
|
||||||
|
typedef iterator_adaptor<
|
||||||
|
value_type
|
||||||
|
, counting_iterator_policies<value_type>
|
||||||
|
, value_type
|
||||||
|
, value_type const&
|
||||||
|
, value_type const*
|
||||||
|
, typename traits::iterator_category
|
||||||
|
, typename traits::difference_type
|
||||||
|
> type;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Manufacture a counting iterator for an arbitrary incrementable type
|
// Manufacture a counting iterator for an arbitrary incrementable type
|
||||||
@ -192,9 +219,8 @@ template <class Incrementable>
|
|||||||
inline typename counting_iterator_generator<Incrementable>::type
|
inline typename counting_iterator_generator<Incrementable>::type
|
||||||
make_counting_iterator(Incrementable x)
|
make_counting_iterator(Incrementable x)
|
||||||
{
|
{
|
||||||
return iterator_adaptor<Incrementable,
|
typedef typename counting_iterator_generator<Incrementable>::type result_t;
|
||||||
counting_iterator_policies<Incrementable>,
|
return result_t(x);
|
||||||
counting_iterator_traits<Incrementable> >(x);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
55
include/boost/function_output_iterator.hpp
Normal file
55
include/boost/function_output_iterator.hpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// (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(const UnaryFunction& f = UnaryFunction())
|
||||||
|
: 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
|
@ -5,8 +5,10 @@
|
|||||||
// for any purpose.
|
// for any purpose.
|
||||||
//
|
//
|
||||||
// Revision History:
|
// Revision History:
|
||||||
// 04 Feb 2001 Support for user-defined iterator categories (David Abrahams)
|
// 11 Feb 2001 Use new iterator_adaptor interface, Fixes for Borland.
|
||||||
// 30 Jan 2001 Initial Checkin (David Abrahams)
|
// (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_
|
#ifndef BOOST_HALF_OPEN_RANGE_HPP_
|
||||||
# define BOOST_HALF_OPEN_RANGE_HPP_
|
# define BOOST_HALF_OPEN_RANGE_HPP_
|
||||||
@ -75,7 +77,7 @@ namespace detail {
|
|||||||
static const Incrementable choose(const Incrementable& start, const Incrementable& finish)
|
static const Incrementable choose(const Incrementable& start, const Incrementable& finish)
|
||||||
{
|
{
|
||||||
return finish_chooser<(
|
return finish_chooser<(
|
||||||
boost::is_convertible<Category,std::random_access_iterator_tag>::value
|
::boost::is_convertible<Category*,std::random_access_iterator_tag*>::value
|
||||||
)>::template rebind<Incrementable>::choose(start, finish);
|
)>::template rebind<Incrementable>::choose(start, finish);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -85,27 +87,29 @@ namespace detail {
|
|||||||
template <class Incrementable>
|
template <class Incrementable>
|
||||||
struct half_open_range
|
struct half_open_range
|
||||||
{
|
{
|
||||||
typedef iterator_adaptor<Incrementable,
|
typedef typename counting_iterator_generator<Incrementable>::type iterator;
|
||||||
counting_iterator_policies<Incrementable>,
|
|
||||||
counting_iterator_traits<Incrementable> > iterator;
|
|
||||||
|
|
||||||
private: // utility type definitions
|
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 std::less<Incrementable> less_value;
|
||||||
typedef typename boost::detail::iterator_traits<iterator>::iterator_category category;
|
typedef typename iter_t::iterator_category category;
|
||||||
|
typedef half_open_range<Incrementable> self;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef iterator const_iterator;
|
typedef iter_t const_iterator;
|
||||||
typedef typename counting_iterator_traits<Incrementable>::value_type value_type;
|
typedef typename iterator::value_type value_type;
|
||||||
typedef typename counting_iterator_traits<Incrementable>::difference_type difference_type;
|
typedef typename iterator::difference_type difference_type;
|
||||||
typedef typename counting_iterator_traits<Incrementable>::reference reference;
|
typedef typename iterator::reference reference;
|
||||||
typedef typename counting_iterator_traits<Incrementable>::reference const_reference;
|
typedef typename iterator::reference const_reference;
|
||||||
typedef typename counting_iterator_traits<Incrementable>::pointer pointer;
|
typedef typename iterator::pointer pointer;
|
||||||
typedef typename counting_iterator_traits<Incrementable>::pointer const_pointer;
|
typedef typename iterator::pointer const_pointer;
|
||||||
|
|
||||||
// It would be nice to select an unsigned type, but this is appropriate
|
// 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
|
// since the library makes an attempt to select a difference_type which can
|
||||||
// hold the difference between any two iterators.
|
// hold the difference between any two iterators.
|
||||||
typedef typename counting_iterator_traits<Incrementable>::difference_type size_type;
|
typedef typename iterator::difference_type size_type;
|
||||||
|
|
||||||
half_open_range(Incrementable start, Incrementable finish)
|
half_open_range(Incrementable start, Incrementable finish)
|
||||||
: m_start(start),
|
: m_start(start),
|
||||||
@ -130,7 +134,14 @@ struct half_open_range
|
|||||||
#endif
|
#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)
|
half_open_range& operator=(const std::pair<Incrementable,Incrementable>& x)
|
||||||
{
|
{
|
||||||
m_start = x.first;
|
m_start = x.first;
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
# ifdef BOOST_NO_STD_ITERATOR
|
# if defined(BOOST_NO_STD_ITERATOR) && !defined(BOOST_MSVC_STD_ITERATOR)
|
||||||
template <class Category, class T,
|
template <class Category, class T,
|
||||||
class Distance = std::ptrdiff_t,
|
class Distance = std::ptrdiff_t,
|
||||||
class Pointer = T*, class Reference = T&>
|
class Pointer = T*, class Reference = T&>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -5,6 +5,10 @@
|
|||||||
// test suite for STL concepts such as iterators and containers.
|
// test suite for STL concepts such as iterators and containers.
|
||||||
//
|
//
|
||||||
// Revision History:
|
// 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
|
// 08 Feb 2001 Fixed bidirectional iterator test so that
|
||||||
// --i is no longer a precondition.
|
// --i is no longer a precondition.
|
||||||
// (Jeremy Siek)
|
// (Jeremy Siek)
|
||||||
@ -15,12 +19,14 @@
|
|||||||
# include <assert.h>
|
# include <assert.h>
|
||||||
# include <boost/type_traits.hpp>
|
# include <boost/type_traits.hpp>
|
||||||
# include <boost/static_assert.hpp>
|
# include <boost/static_assert.hpp>
|
||||||
|
# include <boost/concept_archetype.hpp> // for detail::dummy_constructor
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
|
|
||||||
// use this for the value type
|
// use this for the value type
|
||||||
struct dummyT {
|
struct dummyT {
|
||||||
dummyT() { }
|
dummyT() { }
|
||||||
|
dummyT(detail::dummy_constructor) { }
|
||||||
dummyT(int x) : m_x(x) { }
|
dummyT(int x) : m_x(x) { }
|
||||||
int foo() const { return m_x; }
|
int foo() const { return m_x; }
|
||||||
bool operator==(const dummyT& d) const { return m_x == d.m_x; }
|
bool operator==(const dummyT& d) const { return m_x == d.m_x; }
|
||||||
@ -72,22 +78,40 @@ void mutable_trivial_iterator_test(const Iterator i, const Iterator j, T val)
|
|||||||
template <class Iterator, class T>
|
template <class Iterator, class T>
|
||||||
void input_iterator_test(Iterator i, T v1, T v2)
|
void input_iterator_test(Iterator i, T v1, T v2)
|
||||||
{
|
{
|
||||||
Iterator i1 = i, i2 = i;
|
Iterator i1(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 == i1);
|
||||||
assert(i == i2);
|
assert(!(i != i1));
|
||||||
++i1;
|
|
||||||
++i2;
|
|
||||||
|
|
||||||
trivial_iterator_test(i, i1, v2);
|
// I can see no generic way to create an input iterator
|
||||||
trivial_iterator_test(i, i2, v2);
|
// 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?
|
// how to test output iterator?
|
||||||
@ -122,6 +146,23 @@ void forward_iterator_test(Iterator i, T v1, T v2)
|
|||||||
{
|
{
|
||||||
input_iterator_test(i, v1, 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
|
// borland doesn't allow non-type template parameters
|
||||||
# if !defined(__BORLANDC__) || (__BORLANDC__ > 0x551)
|
# if !defined(__BORLANDC__) || (__BORLANDC__ > 0x551)
|
||||||
lvalue_test<(boost::is_pointer<Iterator>::value)>::check(i);
|
lvalue_test<(boost::is_pointer<Iterator>::value)>::check(i);
|
||||||
|
72
include/boost/permutation_iterator.hpp
Normal file
72
include/boost/permutation_iterator.hpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
// (C) Copyright Toon Knapen 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.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef boost_permutation_iterator_hpp
|
||||||
|
#define boost_permutation_iterator_hpp
|
||||||
|
|
||||||
|
#include <boost/iterator_adaptors.hpp>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
template < typename IndexIterator >
|
||||||
|
struct permutation_iterator_policies : public default_iterator_policies
|
||||||
|
{
|
||||||
|
permutation_iterator_policies() {}
|
||||||
|
|
||||||
|
permutation_iterator_policies(IndexIterator order_it)
|
||||||
|
: order_it_( order_it )
|
||||||
|
{}
|
||||||
|
|
||||||
|
template <class IteratorAdaptor>
|
||||||
|
typename IteratorAdaptor::reference dereference(const IteratorAdaptor& x) const
|
||||||
|
{ return *(x.base() + *order_it_); }
|
||||||
|
|
||||||
|
template <class IteratorAdaptor>
|
||||||
|
void increment(IteratorAdaptor&)
|
||||||
|
{ ++order_it_; }
|
||||||
|
|
||||||
|
template <class IteratorAdaptor>
|
||||||
|
void decrement(IteratorAdaptor&)
|
||||||
|
{ --order_it_; }
|
||||||
|
|
||||||
|
template <class IteratorAdaptor, class DifferenceType>
|
||||||
|
void advance(IteratorAdaptor& x, DifferenceType n)
|
||||||
|
{ std::advance( order_it_, n ); }
|
||||||
|
|
||||||
|
template <class IteratorAdaptor1, class IteratorAdaptor2>
|
||||||
|
typename IteratorAdaptor1::difference_type
|
||||||
|
distance(const IteratorAdaptor1& x, const IteratorAdaptor2& y) const
|
||||||
|
{ return std::distance( x.policies().order_it_, y.policies().order_it_ ); }
|
||||||
|
|
||||||
|
template <class IteratorAdaptor1, class IteratorAdaptor2>
|
||||||
|
bool equal(const IteratorAdaptor1& x, const IteratorAdaptor2& y) const
|
||||||
|
{ return x.policies().order_it_ == y.policies().order_it_; }
|
||||||
|
|
||||||
|
IndexIterator order_it_;
|
||||||
|
};
|
||||||
|
|
||||||
|
template < typename ElementIterator, typename IndexIterator >
|
||||||
|
struct permutation_iterator_generator
|
||||||
|
{
|
||||||
|
typedef boost::iterator_adaptor
|
||||||
|
< ElementIterator,
|
||||||
|
permutation_iterator_policies< IndexIterator >
|
||||||
|
> type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template < class IndexIterator, class ElementIterator >
|
||||||
|
inline typename permutation_iterator_generator< ElementIterator, IndexIterator >::type
|
||||||
|
make_permutation_iterator(ElementIterator base, IndexIterator order)
|
||||||
|
{
|
||||||
|
typedef typename permutation_iterator_generator< ElementIterator, IndexIterator >::type result_t;
|
||||||
|
return result_t( base, order );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // boost_permutation_iterator_hpp
|
||||||
|
|
Reference in New Issue
Block a user