diff --git a/development/boost/iterator_categories.hpp b/development/boost/iterator_categories.hpp deleted file mode 100644 index 138a5be..0000000 --- a/development/boost/iterator_categories.hpp +++ /dev/null @@ -1,159 +0,0 @@ -#ifndef BOOST_ITERATOR_CATEGORIES_HPP -#define BOOST_ITERATOR_CATEGORIES_HPP - -#include -#include -#include -#include -#include - -namespace boost { - - // Return Type Categories - struct readable_iterator_tag { }; - struct writable_iterator_tag { }; - struct swappable_iterator_tag { }; - struct mutable_lvalue_iterator_tag : - virtual public writable_iterator_tag, - virtual public readable_iterator_tag { }; - struct constant_lvalue_iterator_tag : - virtual public readable_iterator_tag { }; - - // Traversal Categories - struct forward_traversal_tag { }; - struct bidirectional_traversal_tag : public forward_traversal_tag { }; - struct random_access_traversal_tag : public bidirectional_traversal_tag { }; - - struct error_iterator_tag { }; - - // Inherit from iterator_base if your iterator defines its own - // return_category and traversal_category. Otherwise, the "old style" - // iterator category will be mapped to the return_category and - // traversal_category. - struct new_iterator_base { }; - - namespace detail { - - struct return_category_from_nested_type { - template struct bind { - typedef typename Iterator::return_category type; - }; - }; - - struct traversal_category_from_nested_type { - template struct bind { - typedef typename Iterator::traversal_category type; - }; - }; - - template - struct choose_lvalue_return { - typedef typename ct_if::value, - boost::constant_lvalue_iterator_tag, - boost::mutable_lvalue_iterator_tag>::type type; - }; - - - template - struct iter_category_to_return { - typedef typename ct_if< - is_convertible::value, - typename choose_lvalue_return::type, - typename ct_if< - is_convertible::value, - boost::readable_iterator_tag, - typename ct_if< - is_convertible::value, - boost::writable_iterator_tag, - boost::error_iterator_tag - >::type - >::type - >::type type; - }; - - template - struct iter_category_to_traversal { - typedef typename ct_if< - is_convertible::value, - random_access_traversal_tag, - typename ct_if< - is_convertible::value, - bidirectional_traversal_tag, - forward_traversal_tag - >::type - >::type type; - }; - - struct return_category_from_old_traits { - template class bind { - typedef boost::detail::iterator_traits OldTraits; - typedef typename OldTraits::iterator_category Cat; - typedef typename OldTraits::value_type value_type; - public: - typedef iter_category_to_return::type type; - }; - }; - - struct traversal_category_from_old_traits { - template class bind { - typedef boost::detail::iterator_traits OldTraits; - typedef typename OldTraits::iterator_category Cat; - public: - typedef iter_category_to_traversal::type type; - }; - }; - - template - class choose_return_category { - typedef typename ct_if::value, - return_category_from_nested_type, - return_category_from_old_traits>::type Choice; - public: - typedef typename Choice:: template bind::type type; - }; - - template - class choose_traversal_category { - typedef typename ct_if::value, - traversal_category_from_nested_type, - traversal_category_from_old_traits>::type Choice; - public: - typedef typename Choice:: template bind::type type; - }; - - } // namespace detail - - template - struct return_category { - typedef typename detail::choose_return_category::type type; - }; - - - template - struct traversal_category { - typedef typename detail::choose_traversal_category::type type; - }; - -#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - - template - struct return_category - { - typedef typename ct_if::value, - constant_lvalue_iterator_tag, - mutable_lvalue_iterator_tag>::type type; - }; - - template - struct traversal_category - { - typedef random_access_traversal_tag type; - }; - -#endif - -} // namespace boost - -#endif // BOOST_ITERATOR_CATEGORIES_HPP diff --git a/development/boost/iterator_concepts.hpp b/development/boost/iterator_concepts.hpp deleted file mode 100644 index a30ff17..0000000 --- a/development/boost/iterator_concepts.hpp +++ /dev/null @@ -1,172 +0,0 @@ -#ifndef BOOST_ITERATOR_CONCEPTS_HPP -#define BOOST_ITERATOR_CONCEPTS_HPP - -#include -#include -#include -#include - -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. - - - //=========================================================================== - // Iterator Access Concepts - - template - class ReadableIteratorConcept { - public: - typedef typename std::iterator_traits::value_type value_type; - typedef typename std::iterator_traits::reference reference; - typedef typename boost::return_category::type return_category; - - void constraints() { - boost::function_requires< boost::SGIAssignableConcept >(); - boost::function_requires< boost::EqualityComparableConcept >(); - boost::function_requires< - boost::DefaultConstructibleConcept >(); - - BOOST_STATIC_ASSERT((boost::is_convertible::value)); - - reference r = *i; // or perhaps read(x) - value_type v(r); - boost::ignore_unused_variable_warning(v); - } - Iterator i; - }; - - template - class WritableIteratorConcept { - public: - typedef typename boost::return_category::type return_category; - - void constraints() { - boost::function_requires< boost::SGIAssignableConcept >(); - boost::function_requires< boost::EqualityComparableConcept >(); - boost::function_requires< - boost::DefaultConstructibleConcept >(); - - BOOST_STATIC_ASSERT((boost::is_convertible::value)); - - *i = v; // a good alternative could be something like write(x, v) - } - ValueType v; - Iterator i; - }; - - template - class ConstantLvalueIteratorConcept { - public: - typedef typename std::iterator_traits::value_type value_type; - typedef typename std::iterator_traits::reference reference; - typedef typename boost::return_category::type return_category; - - void constraints() { - boost::function_requires< ReadableIteratorConcept >(); - - BOOST_STATIC_ASSERT((boost::is_convertible::value)); - - BOOST_STATIC_ASSERT((boost::is_same::value)); - - reference v = *i; - boost::ignore_unused_variable_warning(v); - } - Iterator i; - }; - - template - class MutableLvalueIteratorConcept { - public: - typedef typename std::iterator_traits::value_type value_type; - typedef typename std::iterator_traits::reference reference; - typedef typename boost::return_category::type return_category; - - void constraints() { - boost::function_requires< ReadableIteratorConcept >(); - boost::function_requires< - WritableIteratorConcept >(); - - BOOST_STATIC_ASSERT((boost::is_convertible::value)); - - BOOST_STATIC_ASSERT((boost::is_same::value)); - - reference v = *i; - boost::ignore_unused_variable_warning(v); - } - Iterator i; - }; - - //=========================================================================== - // Iterator Traversal Concepts - - template - class ForwardIteratorConcept { - public: - typedef typename boost::traversal_category::type traversal_category; - - void constraints() { - boost::function_requires< boost::SGIAssignableConcept >(); - boost::function_requires< boost::EqualityComparableConcept >(); - boost::function_requires< - boost::DefaultConstructibleConcept >(); - - BOOST_STATIC_ASSERT((boost::is_convertible::value)); - ++i; - (void)i++; - } - Iterator i; - }; - - template - class BidirectionalIteratorConcept { - public: - typedef typename boost::traversal_category::type traversal_category; - - void constraints() { - boost::function_requires< ForwardIteratorConcept >(); - - BOOST_STATIC_ASSERT((boost::is_convertible::value)); - - --i; - (void)i--; - } - Iterator i; - }; - - template - class RandomAccessIteratorConcept { - public: - typedef typename boost::traversal_category::type traversal_category; - typedef typename std::iterator_traits::difference_type - difference_type; - - void constraints() { - boost::function_requires< BidirectionalIteratorConcept >(); - - BOOST_STATIC_ASSERT((boost::is_convertible::value)); - - i += n; - i = i + n; - i = n + i; - i -= n; - i = i - n; - n = i - j; - } - difference_type n; - Iterator i, j; - }; - -} // namespace boost_concepts - - -#endif // BOOST_ITERATOR_CONCEPTS_HPP diff --git a/development/libs/iterator/concept_tests.cpp b/development/libs/iterator/concept_tests.cpp deleted file mode 100644 index f75f311..0000000 --- a/development/libs/iterator/concept_tests.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include - -struct new_iterator - : public boost::iterator, - public boost::new_iterator_base -{ - typedef boost::random_access_traversal_tag traversal_category; - typedef boost::mutable_lvalue_iterator_tag return_category; - - 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 -{ - 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() -{ -#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - boost::function_requires< - boost_concepts::MutableLvalueIteratorConcept >(); - boost::function_requires< - boost_concepts::RandomAccessIteratorConcept >(); - - boost::function_requires< - boost_concepts::ConstantLvalueIteratorConcept >(); - boost::function_requires< - boost_concepts::RandomAccessIteratorConcept >(); -#endif - - boost::function_requires< - boost_concepts::MutableLvalueIteratorConcept >(); - boost::function_requires< - boost_concepts::RandomAccessIteratorConcept >(); - - boost::function_requires< - boost_concepts::MutableLvalueIteratorConcept >(); - boost::function_requires< - boost_concepts::RandomAccessIteratorConcept >(); - return 0; -} diff --git a/development/libs/iterator/iterator_categories.htm b/development/libs/iterator/iterator_categories.htm deleted file mode 100644 index 83c29e5..0000000 --- a/development/libs/iterator/iterator_categories.htm +++ /dev/null @@ -1,160 +0,0 @@ - - - - Boost Iterator Traits - - - -C++ Boost -
- -

Boost Iterator Category Traits

-Header boost/iterator_categories.hpp - -

-The boost::traversal_category and -boost::return_category traits classes provides access to the -category tags for iterators that model the Boost Iterator Concepts, which are a -replacement for the iterator requirements in the C++ standard. The -other associated types of the Boost iterator concepts are accessed -through the std::iterator_traits class. - -

    -
  • traversal_category<Iter>::type   Can the iterator go forward, backward, etc.? -
  • return_category<Iter>::type   Is the iterator read or write only? - Is the dereferenced type an lvalue? -
- -

-An important feature of the boost::traversal_category and -boost::return_category classes is that they are backwards -compatible, i.e., they automatically work for iterators for which -there are valid definitions of std::iterator_traits. The old -iterator_category is mapped to the appropriate traversal and -return categories. - -

-When creating a new iterator type that is meant to work with -boost::traversal_category and -boost::return_category, you can either create a -specialization of these classes for your iterator type, or you can -provide all the necessary associated types as nested typedefs. In -this case, your iterator class will need to inherit from -new_iterator_base to let the category traits know -that it will be able to find typedefs for traversal_category -and return_category in you iterator class. - - -Each of the new iterator requirements will need a category tag. - -

-namespace boost {
-
-  // Return Type Categories
-  struct readable_iterator_tag { };
-  struct writable_iterator_tag { };
-  struct swappable_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 { };
-
-  // Traversal Categories
-  struct forward_traversal_tag { };
-  struct bidirectional_traversal_tag : public forward_traversal_tag { };
-  struct random_access_traversal_tag : public bidirectional_traversal_tag { };
-
-}
-
- -

-The following is pseudo-code for the iterator category traits classes. - -

-namespace boost {
-
-  // Inherit from iterator_base if your iterator defines its own
-  // return_category and traversal_category. Otherwise, the "old style"
-  // iterator category will be mapped to the return_category and
-  // traversal_category.
-  struct new_iterator_base { };
-
-  template <typename Iterator>
-  struct return_category
-  {
-    // Pseudo-code
-    if (Iterator inherits from new_iterator_base) {
-      typedef typename Iterator::return_category type;
-    } else {
-      typedef std::iterator_traits<Iterator> OldTraits;
-      typedef typename OldTraits::iterator_category Cat;
-      if (Cat inherits from std::forward_iterator_tag)
-	if (is-const(T))
-	  typedef boost::constant_lvalue_iterator_tag type;
-	else
-	  typedef boost::mutable_lvalue_iterator_tag type;
-      else if (Cat inherits from std::input_iterator_tag)
-	typedef boost::readable_iterator_tag type;
-      else if (Cat inherits from std::output_iterator_tag)
-	typedef boost::writable_iterator_tag type;
-    }
-  };
-
-  template <typename T>
-  struct return_category<T*>
-  {
-    // Pseudo-code
-    if (is-const(T))
-      typedef boost::constant_lvalue_iterator_tag type;
-    else
-      typedef boost::mutable_lvalue_iterator_tag type;
-  };
-
-  template <typename Iterator>
-  struct traversal_category
-  {
-    // Pseudo-code
-    if (Iterator inherits from new_iterator_base) {
-      typedef typename Iterator::traversal_category type;
-    } else {
-      typedef std::iterator_traits<Iterator> OldTraits;
-      typedef typename OldTraits::iterator_category Cat;
-
-      if (Cat inherits from std::random_access_iterator_tag)
-	typedef boost::random_access_traversal_tag type;
-      else if (Cat inherits from std::bidirectional_iterator_tag)
-	typedef boost::bidirectional_traversal_tag type;
-      else if (Cat inherits from std::forward_iterator_tag)
-	typedef boost::forward_traversal_tag type;
-    }
-  };
-
-  template <typename T>
-  struct traversal_category<T*>
-  {
-    typedef boost::random_access_traversal_tag type;
-  };
-
-}
-
- -
-
jeremy siek
- - -Last modified: Mon Mar 19 12:59:30 EST 2001 - - - diff --git a/development/libs/iterator/iterator_concepts.fig b/development/libs/iterator/iterator_concepts.fig deleted file mode 100644 index 198205e..0000000 --- a/development/libs/iterator/iterator_concepts.fig +++ /dev/null @@ -1,37 +0,0 @@ -#FIG 3.2 -Landscape -Center -Inches -Letter -100.00 -Single --2 -1200 2 -6 150 2325 4275 4350 -2 1 0 1 0 7 100 0 -1 4.000 0 0 -1 1 0 2 - 1 1 1.00 60.00 120.00 - 1725 4050 1725 3450 -2 1 0 1 0 7 100 0 -1 4.000 0 0 -1 1 0 2 - 1 1 1.00 60.00 120.00 - 1725 3150 1725 2550 -4 0 0 100 0 19 18 0.0000 4 210 3180 375 2550 ForwardTraversalIterator\001 -4 0 0 100 0 19 18 0.0000 4 210 3765 225 3450 BidirectionalTraversalIterator\001 -4 0 0 100 0 19 18 0.0000 4 210 4125 150 4350 RandomAccessTraversalIterator\001 --6 -2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 - 1 1 1.00 60.00 120.00 - 4800 3600 4800 2400 -2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 - 1 1 1.00 60.00 120.00 - 6900 3000 5400 2400 -2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 - 1 1 1.00 60.00 120.00 - 6900 3000 7500 2400 -2 1 0 1 0 7 50 0 -1 0.000 0 0 -1 1 0 2 - 1 1 1.00 60.00 120.00 - 6900 3000 9075 2475 -4 0 0 100 0 19 18 0.0000 4 210 2040 6600 2400 WritableIterator\001 -4 0 0 100 0 19 18 0.0000 4 210 2145 3900 2400 ReadableIterator\001 -4 0 0 50 0 19 18 0.0000 4 210 2835 5700 3300 MutableLvalueIterator\001 -4 0 0 50 0 19 18 0.0000 4 270 2355 9075 2400 SwappableIterator\001 -4 0 0 50 0 19 18 0.0000 4 210 2970 3825 3900 ConstantLvalueIterator\001 diff --git a/development/libs/iterator/iterator_concepts.gif b/development/libs/iterator/iterator_concepts.gif deleted file mode 100644 index bac35c7..0000000 Binary files a/development/libs/iterator/iterator_concepts.gif and /dev/null differ diff --git a/development/libs/iterator/iterator_concepts.htm b/development/libs/iterator/iterator_concepts.htm deleted file mode 100644 index f2f8dcd..0000000 --- a/development/libs/iterator/iterator_concepts.htm +++ /dev/null @@ -1,663 +0,0 @@ - - - - -Iterator Concepts - -C++ Boost - -
- - -

Iterator Concepts

- -

The standard iterator categories and requirements are flawed because -they use a single hierarchy of requirements to address two orthogonal -issues: iterator traversal and dereference return -type. The current iterator requirement hierarchy is mainly -geared towards iterator traversal (hence the category names), while -requirements that address dereference return type sneak in at various -places. - -

-The iterator requirements should be separated into two hierarchies. -One set of concepts handles the return type semantics: -

- -The other set of concepts handles iterator traversal: - - - -The current Input Iterator and Output Iterator requirements will -continue to be used as is. Note that Input Iterator implies Readable -Iterator and Output Iterator implies Writable Iterator. - -

-Note: we considered defining a Single-Pass Iterator, which could be -combined with Readable or Writable Iterator to replace the Input and -Output Iterator requirements. We rejected this idea because there are -some differences between Input and Output Iterators that make it hard -to merge them: for example Input Iterator requires Equality Comparable -while Output Iterator does not. - - -

-
- - - -
Figure 1: -The iterator concepts and refinement relationships. -
-
-

- - -

Relationship with the standard iterator concepts

- -

-std::Input Iterator implies boost::ReadableIterator. - -

-std::Output Iterator implies boost::Writable Iterator. - -

-std::Forward Iterator refines boost::Forward Iterator and -boost::Constant Lvalue Iterator or boost::Mutable Lvalue Iterator. - -

-std::Bidirectional Iterator refines boost::Bidirectional Iterator and -boost::Constant Lvalue Iterator or boost::Mutable Lvalue Iterator. - -

-std::Random Access Iterator refines boost::Random Access Iterator and -boost::Constant Lvalue Iterator or boost::Mutable Lvalue Iterator. - - -

Notation

- - - - - - - - - - - - - - - - - -
XThe iterator type.
TThe value type of X, i.e., std::iterator_traits<X>::value_type.
x, yAn object of type X.
tAn object of type T.
- -

- -


- - -

-Readable Iterator -

- -A Readable Iterator is an iterator that dereferences to produce an -rvalue that is convertible to the value_type of the -iterator. - -

Associated Types

- - - - - - - - - - - - - - - - - - - - - -
Value typestd::iterator_traits<X>::value_typeThe type of the objects pointed to by the iterator.
Reference typestd::iterator_traits<X>::reference - The return type of dereferencing the iterator. This - type must be convertible to T. -
Return Categorystd::return_category<X>::type - A type convertible to std::readable_iterator_tag -
- -

Refinement of

- -Copy Constructible - -

Valid expressions

- - - - - - - - - - - - - - - -
NameExpressionType requirementsReturn type
Dereference*x std::iterator_traits<X>::reference
Member accessx->mT is a type with a member named m. -If m is a data member, the type of m. -If m is a member function, the return type of m. -
- -

- -


- - -

-Writable Iterator -

- -A Writable Iterator is an iterator that can be used to store a value -using the dereference-assignment expression. - -

Definitions

- -If x is an Writable Iterator of type X, then the -expression *x = a; stores the value a into -x. Note that operator=, like other C++ functions, -may be overloaded; it may, in fact, even be a template function. In -general, then, a may be any of several different types. A -type A belongs to the set of value types of X -if, for an object a of type A, *x = a; is -well-defined and does not require performing any non-trivial -conversions on a. - -

Associated Types

- - - - - - - - - -
Return Categorystd::return_category<X>::type - A type convertible to std::writable_iterator_tag -
- - - -

Refinement of

- -Copy Constructible - -

Valid expressions

- - - - - - - - - - -
NameExpressionReturn type
Dereference assignment*x = aunspecified
- -

- - -


- - -

-Swappable Iterator -

- -A Swappable Iterator is an iterator whose dereferenced values can be -swapped. - -

-Note: the requirements for Swappable Iterator are dependent on the -issues surrounding std::swap() being resolved. Here we assume -that the issue will be resolved by allowing the overload of -std::swap() for user-defined types. - -

-Note: Readable Iterator and Writable Iterator combined implies -Swappable Iterator because of the fully templated -std::swap(). However, Swappable Iterator does not imply -Readable Iterator nor Writable Iterator. - -

Associated Types

- - - - - - - - - -
Return Categorystd::return_category<X>::type - A type convertible to std::swappable_iterator_tag -
- - -

Valid expressions

- -Of the two valid expressions listed below, only one OR the -other is required. If std::iter_swap() is overloaded for -X then std::swap() is not required. If -std::iter_swap() is not overloaded for X then the -default (fully templated) version is used, which will call -std::swap() (this means changing the current requirements for -std::iter_swap()). - -

- - - - - - - - - - - - - - - - - -
NameExpressionReturn type
Iterator Swapstd::iter_swap(x, y)void
Dereference and Swapstd::swap(*x, *y)void
- -

- - -


- - -

-Constant Lvalue Iterator -

- -A Constant Lvalue Iterator is an iterator that dereferences to produce a -const reference to the pointed-to object, i.e., the associated -reference type is const T&. Changing the value -of or destroying an iterator that models Constant Lvalue Iterator does -not invalidate pointers and references previously obtained from that -iterator. - - -

Refinement of

- -Readable Iterator - -

Associated Types

- - - - - - - - - - - - - - - - - -
Reference typestd::iterator_traits<X>::reference - The return type of dereferencing the iterator, which must be - const T&. -
Return Categorystd::return_category<X>::type - A type convertible to std::constant_lvalue_iterator_tag -
- - - -

- -


- - -

-Mutable Lvalue Iterator -

- -A Mutable Lvalue Iterator is an iterator that dereferences to produce a -reference to the pointed-to object. The associated reference -type is T&. Changing the value of or destroying an -iterator that models Mutable Lvalue Iterator does not invalidate -pointers and references previously obtained from that iterator. - -

Refinement of

- -Readable Iterator, -Writable Iterator, -and Swappable Iterator. - - - -

Associated Types

- - - - - - - - - - - - - - - - - -
Reference typestd::iterator_traits<X>::referenceThe return type of dereferencing the iterator, which must be - T&.
Return Categorystd::return_category<X>::type - A type convertible to std::mutable_lvalue_iterator_tag -
- - - -

-


- - -

-Forward Traversal Iterator -

- -The Forward Iterator is an iterator that can be incremented. Also, it -is permissible to make multiple passes through the iterator's range. - -

Refinement of

- -Copy Constructible, -Assignable, -Default Constructible, and -Equality Comparable - - -

Associated types

- - - - - - - - - - - - - - -
Difference Typestd::iterator_traits<X>::difference_type - A signed integral type used for representing distances - between iterators that point into the same range. -
Traversal Categorystd::traversal_category<X>::type - A type convertible to std::forward_traversal_tag -
- -

Valid expressions

- - - - - - - - - - - - - - -
NameExpressionType requirementsReturn type
Preincrement++i X&
Postincrementi++ convertible to const X&
- -

-


- - -

-Bidirectional Traversal Iterator -

- -An iterator that can be incremented and decremented. - -

Refinement of

- -Forward Traversal Iterator - -

Associated types

- - - - - - - -
Traversal Categorystd::traversal_category<X>::type - A type convertible to std::bidirectional_traversal_tag -
- -

Valid expressions

- - - - - - - - - - - - -
NameExpressionType requirementsReturn type
Predecrement--i X&
Postdecrementi-- convertible to const X&
- -

-


- - -

-Random Access Traversal Iterator -

- -An iterator that provides constant-time methods for moving forward and -backward in arbitrary-sized steps. - -

Refinement of

- -Bidirectional Traversal Iterator and -Less Than Comparable where < is a total ordering - -

Associated types

- - - - - - - -
Traversal Categorystd::traversal_category<X>::type - A type convertible to std::random_access_traversal_tag -
- -

Valid expressions

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameExpressionType requirementsReturn type
Iterator additioni += n X&
Iterator additioni + n or n + i X
Iterator subtractioni -= n X&
Iterator subtractioni - n X
Differencei - j std::iterator_traits<X>::difference_type
Element operatori[n]X must also be a model of - Readable Iterator. std::iterator_traits<X>::reference
Element assignmenti[n] = tX must also be a model of - Writable Iterator.unspecified
- -

- -


- - -
Copyright © 2000 -Jeremy Siek, Univ.of Notre Dame (jsiek@lsc.nd.edu) -
- - - diff --git a/doc/GNUmakefile b/doc/GNUmakefile deleted file mode 100755 index f1f1a86..0000000 --- a/doc/GNUmakefile +++ /dev/null @@ -1,232 +0,0 @@ -# GNUmakefile for postprocessing PDF files -# -# © 2000 IBM Corporation. -# Licensed under the GNU GPL. - -######################################################################## -# Make sure that the following macros are correct for your setup -######################################################################## -# ... System utilities -RMRF = /bin/rm -rf -MV = /bin/mv -EGREP = /bin/egrep -ECHO = /bin/echo -PERL = /usr/bin/perl -PYTHON = python -CAT = /bin/cat -TOUCH = /bin/touch -ZIP = /usr/bin/zip - -# ... TeX & postprocessors -PPOWER4 = ppower4 -PDFLATEX = pdflatex -METAPOST = mpost -FIG2DEV = fig2dev -BIBTEX = bibtex -FOLIAGECUTTER = foliageCutter --verbose -RST2LATEX = rst2latex --documentclass book --documentoptions 10pt,twoside,pdftex # --use-latex-toc -RST2HTML = rst2html - -TEX = latex -export TEX -######################################################################## -# End of user servicable parts; don't fiddle with the remainder of this -# makefile unless you know what you do. -# -# You have been warned ;=) -######################################################################## - -# ... Variables -TEXFILES = $(strip $(wildcard *.tex)) -RSTFILES = $(strip $(wildcard *.rst)) --include GNUmakefile.local -TEXSTEMS = $(strip $(patsubst %.tex,%,${TEXFILES})) -RSTSTEMS = $(strip $(patsubst %.rst,%,${RSTFILES})) -CUTFOILS = $(strip $(patsubst %,%---toc.tex,${TEXSTEMS})) -PDFFILES = $(strip $(patsubst %.tex,%.pdf,${TEXFILES})) -PRINTS = $(patsubst %.pdf,%-print.pdf,${PDFFILES}) -PRINTZIP = prints.zip -SLIDEZIP = slides.zip - -# ... Depend -DEPENDFILES = .depend -GENFILE = .generated - -# ... List of extensions and files generated -texcrap = *.mpx *.log *.aux *.blg *-print.brf *-print.tex *.out - -mpxcrap = mpxerr.tex mpxerr.pdf - -generated = *.out *.[0-9] *.[0-9][0-9] *.bbl *.brf \ - *.mp *.mmp *.pdf *.ps TMP-*.pdf *.ftoc\ - ${PRINTZIP} ${SLIDEZIP} ${GENFILE} ${DEPENDFILES} \ - ${texcrap} ${mpxcrap} ${CUTFOILS} $(strip $(wildcard *---*.tex)) - - -# ... canned command to run PDFLaTeX -define run-pdflatex -@${ECHO} "" -@${ECHO} "---- Running PDFLaTeX on $<" && ${PDFLATEX} $< -@${ECHO} "---- Running PDFLaTeX on $< again" && ${PDFLATEX} $< --@(${EGREP} -qi 'Rerun to get' $*.log && \ - ${ECHO} "---- Rerunning PDFLaTeX on $* to get cross-refs right" && \ - ${PDFLATEX} $<) || \ - ${ECHO} "---- No cross-refs correcting PDFLaTeX rerun required for $*" --@(${EGREP} -qi $*.ftoc $*.log && \ - ${ECHO} "---- Rerunning PDFLaTeX on $* for FTOC" && \ - ${PDFLATEX} $<) || \ - ${ECHO} "---- No FTOC PDFLaTeX run required for $*" --@(${EGREP} -qi 'Warning: Citation' $*.log && \ - ${ECHO} "---- Running BIBTeX on $*" && \ - ${BIBTEX} $* && \ - ${ECHO} "---- Running PDFLaTeX on $<" && \ - ${PDFLATEX} $<) || \ - ${ECHO} "---- No BIBTeX run required for $*" --@(${EGREP} -qi 'Warning: .+undefined references' $*.log && \ - ${ECHO} "---- Running PDFLaTeX on $<" && \ - ${PDFLATEX} $<) || \ - ${ECHO} "---- No further PDFLaTex run required for $<" -@${ECHO} "Generated: $@ {$<}" >> ${GENFILE} -@${RMRF} ${texcrap} -endef - -# ... canned command to run PDFLaTeX for printable versions -define run-pdflatex-for-print -@${ECHO} "" -@${ECHO} "---- Running PDFLaTeX on $*-print.tex" && ${PDFLATEX} $*-print.tex -@${ECHO} "---- Running PDFLaTeX on $< again" && ${PDFLATEX} $< --@(${EGREP} -qi 'Warning: Citation' $*-print.log && \ - ${ECHO} "---- Running BIBTeX on $*-print" && \ - ${BIBTEX} $*-print && \ - ${ECHO} "---- Running PDFLaTeX on $*-print.tex" && \ - ${PDFLATEX} $*-print.tex) || \ - ${ECHO} "---- No BIBTeX run required for $*" --@(${EGREP} -qi 'Warning: .+undefined references' $*-print.log && \ - ${ECHO} "---- Running PDFLaTeX on $*-print" && \ - ${PDFLATEX} $*-print.tex) || \ - ${ECHO} "---- No further PDFLaTex run required for $*-print" -@${ECHO} "Generated: $@ {$<}" >> ${GENFILE} -@${RMRF} ${texcrap} -endef - -# DWA begin modifications -# ... Rule: How to generate TeX from ReST -%.tex: %.txt - @${ECHO} "---- Running rst2latex on $<" - ${RST2LATEX} $< $@ - @${ECHO} "Generated: $@ {$<}" >> ${GENFILE} - -# ... Rule: How to generate TeX from ReST -%.tex: %.rst - @${ECHO} "---- Running rst2latex on $<" - ${RST2LATEX} $< $@ - @${ECHO} "Generated: $@ {$<}" >> ${GENFILE} - -# ... Rule: How to generate HTML from ReST -%.html: %.txt - @${ECHO} "---- Running rst2html on $<" - ${RST2HTML} $< $@ - @${ECHO} "Generated: $@ {$<}" >> ${GENFILE} - -# ... Rule: How to generate HTML from ReST -%.html: %.rst - @${ECHO} "---- Running rst2html on $<" - ${RST2HTML} $< $@ - @${ECHO} "Generated: $@ {$<}" >> ${GENFILE} -# DWA end modifications - -# ... Rule: How to generate PDF from TeX -%.pdf: %.tex - $(run-pdflatex) - @${MV} $@ TMP-$@ - @${ECHO} "---- Running PPower4 on $*" - ${PPOWER4} -v TMP-$@ $@ - @${RMRF} TMP-$@ - @${ECHO} "Postprocessed: $*.pdf {$*.pdf}" >> ${GENFILE} - -# ... Rule: How to generate printable PDF from TeX -%-print.pdf: %.tex - ${PERL} -pe 's/^\\documentclass\[(.*?)\]/\\documentclass\[$$1,prints\]/;' < $< > $*-print.tex - $(run-pdflatex-for-print) - @${ECHO} "Generated: $*-print.pdf {$*.pdf}" >> ${GENFILE} - -# ... Rule: How to generate cut foils from TeX master -%---toc.tex: %.tex - ${FOLIAGECUTTER} --prefix=$* $< - -# ... Rule: How to generate MetaPost from FIG -%.mp: %.fig - @${ECHO} "---- Running Fig2Dev (mp) on $<" - ${FIG2DEV} -L mp $< $@ - @${ECHO} "Generated: $@ {$<}" >> ${GENFILE} - -# ... Rule: How to generate MultiMetaPost from FIG -%.mmp: %.fig - @${ECHO} "---- Running Fig2Dev (mmp) on $<" - ${FIG2DEV} -L mmp $< $@ - @${ECHO} "Generated: $@ {$<}" >> ${GENFILE} - -# ... Rule: How to generate includable PS from FIG via MetaPost -%.mps: %.fig - @${ECHO} "---- Running Fig2Dev (mps) on $<" - ${FIG2DEV} -L mp $< $*.mps.mp - @${RMRF} $*.mps.[0-9] - ${METAPOST} $*.mps.mp - @${MV} $*.mps.0 $@ - @${ECHO} "Generated: $@ {$<}" >> ${GENFILE} - -# ... Rule: How to generate includable PS files from MultiMetaPost -%.0: %.mmp - @${ECHO} "---- Running MetaPost on $<" - @${RMRF} $*.[0-9] $*.[0-9][0-9] - ${METAPOST} $< - @${ECHO} "Generated: $*.0{...} {$<}" >> ${GENFILE} - -cleanup-crap: - @${RMRF} ${mpxcrap} - -# ... Target: all -all: cleanup-crap ${DEPENDFILES} ${PDFFILES} ${PRINTS} ${PRINTZIP} ${SLIDEZIP} - @${ECHO} "" - @${TOUCH} ${GENFILE} - @${CAT} ${GENFILE} - @${RMRF} ${GENFILE} - -# ... Target: ZIP files -zip zips: ${PRINTZIP} ${SLIDEZIP} - -# ... Target: ZIP file containing printable versions of slides -${PRINTZIP}: .depend ${PDFFILES} - @${RMRF} ${PRINTZIP} - ${ZIP} -r ${PRINTZIP} ${PRINTS} - @${ECHO} "Generated: ${PRINTZIP}" >> ${GENFILE} - -# ... Target: ZIP file containing screen versions of slides - ${SLIDEZIP}: .depend ${PDFFILES} - @${RMRF} ${SLIDEZIP} - ${ZIP} -r ${SLIDEZIP} ${PDFFILES} - @${ECHO} "Generated: ${SLIDEZIP}" >> ${GENFILE} - -# ... Target: clean up -clean: - ${RMRF} ${generated} - -# ... Target: create dependencies -depend: .depend - -# ... Target: dependency file (parse TEXFILES for multiinclude and includegraphics) -# .depend: GNUmakefile ${TEXFILES} -# ${RMRF} $@ -# @for t in ${TEXSTEMS} ; do \ -# ${ECHO} "Scanning $$t.tex"; \ -# ${PERL} -e 'my $$target = shift @ARGV;' -e 'while (<>) { /\\multiinclude(\[.*?\])?{(.*?)}/ && print "$$target: $$2.0\n";}' $$t.pdf < $$t.tex >> $@; \ -# ${PERL} -e 'my $$target = shift @ARGV;' -e 'while (<>) { /\\includegraphics(\[.*?\])?{(.*?)\.(.*?)}/ && print "$$target: $$2.$$3\n";}' $$t.pdf < $$t.tex >> $@; \ -# done - -.depend: GNUmakefile ${RSTFILES} - ${RMRF} $@ - ${PYTHON} scanrst.py ${RSTFILES} > $@ - -# ... include dependency files -# -include .depend --include .depend diff --git a/doc/access.png b/doc/access.png deleted file mode 100644 index 80011dc..0000000 Binary files a/doc/access.png and /dev/null differ diff --git a/doc/access2old.png b/doc/access2old.png deleted file mode 100644 index 8a87b84..0000000 Binary files a/doc/access2old.png and /dev/null differ diff --git a/doc/counting_iterator.html b/doc/counting_iterator.html deleted file mode 100644 index a3366cd..0000000 --- a/doc/counting_iterator.html +++ /dev/null @@ -1,280 +0,0 @@ - - - - - - -Counting Iterator - - - - - - - -
-

Counting Iterator

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-01-15
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved
- --- - - - -
abstract:

How would you fill up a vector with the numbers zero -through one hundred using std::copy()? The only iterator -operation missing from builtin integer types is an -operator*() that returns the current value of the integer. -The counting iterator adaptor adds this crucial piece of -functionality to whatever type it wraps. One can use the -counting iterator adaptor not only with integer types, but with -any incrementable type.

-

counting_iterator adapts an object by adding an operator* that -returns the current value of the object. All other iterator operations -are forwarded to the adapted object.

-
- -
-

counting_iterator synopsis

-
-template <
-    class Incrementable
-  , class CategoryOrTraversal = use_default
-  , class Difference = use_default
->
-class counting_iterator
-{
-public:
-    typedef Incrementable value_type;
-    typedef const Incrementable& reference;
-    typedef const Incrementable* pointer;
-    typedef /* see below */ difference_type;
-    typedef /* see below */ iterator_category;
-
-    counting_iterator();
-    counting_iterator(counting_iterator const& rhs);
-    explicit counting_iterator(Incrementable x);
-    Incrementable const& base() const;
-    reference operator*() const;
-    counting_iterator& operator++();
-    counting_iterator& operator--();
-private:
-    Incrementable m_inc; // exposition
-};
-
-

If the Difference argument is use_default then -difference_type is an unspecified signed integral -type. Otherwise difference_type is Difference.

-

iterator_category is determined according to the following -algorithm:

-
-if (CategoryOrTraversal is not use_default)
-    return CategoryOrTraversal
-else if (numeric_limits<Incrementable>::is_specialized)
-    return iterator-category(
-        random_access_traversal_tag, Incrementable, const Incrementable&)
-else
-    return iterator-category(
-         iterator_traversal<Incrementable>::type, 
-         Incrementable, const Incrementable&)
-
-
-
[Note: implementers are encouraged to provide an implementation of
-
operator- and a difference_type that avoids overflows in -the cases where std::numeric_limits<Incrementable>::is_specialized -is true.]
-
-
-
-

counting_iterator requirements

-

The Incrementable argument shall be Copy Constructible and Assignable.

-

If iterator_category is convertible to forward_iterator_tag -or forward_traversal_tag, the following must be well-formed:

-
-Incrementable i, j;
-++i;         // pre-increment
-i == j;      // operator equal
-
-

If iterator_category is convertible to -bidirectional_iterator_tag or bidirectional_traversal_tag, -the following expression must also be well-formed:

-
---i
-
-

If iterator_category is convertible to -random_access_iterator_tag or random_access_traversal_tag, -the following must must also be valid:

-
-counting_iterator::difference_type n;
-i += n;
-n = i - j;
-i < j;
-
-
-
-

counting_iterator models

-

Specializations of counting_iterator model Readable Lvalue -Iterator. In addition, they model the concepts corresponding to the -iterator tags to which their iterator_category is convertible. -Also, if CategoryOrTraversal is not use_default then -counting_iterator models the concept corresponding to the iterator -tag CategoryOrTraversal. Otherwise, if -numeric_limits<Incrementable>::is_specialized, then -counting_iterator models Random Access Traversal Iterator. -Otherwise, counting_iterator models the same iterator traversal -concepts modeled by Incrementable.

-

counting_iterator<X,C1,D1> is interoperable with -counting_iterator<Y,C2,D2> if and only if X is -interoperable with Y.

-
-
-

counting_iterator operations

-

In addition to the operations required by the concepts modeled by -counting_iterator, counting_iterator provides the following -operations.

-

counting_iterator();

- --- - - - - - -
Requires:Incrementable is Default Constructible.
Effects:Default construct the member m_inc.
-

counting_iterator(counting_iterator const& rhs);

- --- - - - -
Effects:Construct member m_inc from rhs.m_inc.
-

explicit counting_iterator(Incrementable x);

- --- - - - -
Effects:Construct member m_inc from x.
-

reference operator*() const;

- --- - - - -
Returns:m_inc
-

counting_iterator& operator++();

- --- - - - - - -
Effects:++m_inc
Returns:*this
-

counting_iterator& operator--();

- --- - - - - - -
Effects:--m_inc
Returns:*this
-

Incrementable const& base() const;

- --- - - - -
Returns:m_inc
-
-template <class Incrementable>
-counting_iterator<Incrementable> make_counting_iterator(Incrementable x);
-
- --- - - - -
Returns:An instance of counting_iterator<Incrementable> -with current constructed from x.
-
-
-

Example

-

This example fills an array with numbers and a second array with -pointers into the first array, using counting_iterator for both -tasks. Finally indirect_iterator is used to print out the numbers -into the first array via indirection through the second array.

-
-int N = 7;
-std::vector<int> numbers;
-typedef std::vector<int>::iterator n_iter;
-std::copy(boost::counting_iterator<int>(0),
-         boost::counting_iterator<int>(N),
-         std::back_inserter(numbers));
-
-std::vector<std::vector<int>::iterator> pointers;
-std::copy(boost::make_counting_iterator(numbers.begin()),
-          boost::make_counting_iterator(numbers.end()),
-          std::back_inserter(pointers));
-
-std::cout << "indirectly printing out the numbers from 0 to " 
-          << N << std::endl;
-std::copy(boost::make_indirect_iterator(pointers.begin()),
-          boost::make_indirect_iterator(pointers.end()),
-          std::ostream_iterator<int>(std::cout, " "));
-std::cout << std::endl;
-
-

The output is:

-
-indirectly printing out the numbers from 0 to 7
-0 1 2 3 4 5 6 
-
-

The source code for this example can be found here.

-
-
- - diff --git a/doc/counting_iterator.rst b/doc/counting_iterator.rst deleted file mode 100644 index 2d2cad9..0000000 --- a/doc/counting_iterator.rst +++ /dev/null @@ -1,39 +0,0 @@ -+++++++++++++++++++ - Counting Iterator -+++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: How would you fill up a vector with the numbers zero - through one hundred using ``std::copy()``? The only iterator - operation missing from builtin integer types is an - ``operator*()`` that returns the current value of the integer. - The counting iterator adaptor adds this crucial piece of - functionality to whatever type it wraps. One can use the - counting iterator adaptor not only with integer types, but with - any incrementable type. - - .. include:: counting_iterator_abstract.rst - -.. contents:: Table of Contents - -``counting_iterator`` synopsis -.............................. - -.. include:: counting_iterator_ref.rst -.. include:: make_counting_iterator.rst - -.. include:: counting_iterator_eg.rst - -.. _iterator-category: iterator_facade.html#iterator-category -.. |iterator-category| replace:: *iterator-category* diff --git a/doc/counting_iterator_abstract.rst b/doc/counting_iterator_abstract.rst deleted file mode 100644 index bdb8491..0000000 --- a/doc/counting_iterator_abstract.rst +++ /dev/null @@ -1,4 +0,0 @@ -``counting_iterator`` adapts an object by adding an ``operator*`` that -returns the current value of the object. All other iterator operations -are forwarded to the adapted object. - diff --git a/doc/counting_iterator_eg.rst b/doc/counting_iterator_eg.rst deleted file mode 100644 index 5f6b3b3..0000000 --- a/doc/counting_iterator_eg.rst +++ /dev/null @@ -1,40 +0,0 @@ - -Example -....... - -This example fills an array with numbers and a second array with -pointers into the first array, using ``counting_iterator`` for both -tasks. Finally ``indirect_iterator`` is used to print out the numbers -into the first array via indirection through the second array. - -:: - - int N = 7; - std::vector numbers; - typedef std::vector::iterator n_iter; - std::copy(boost::counting_iterator(0), - boost::counting_iterator(N), - std::back_inserter(numbers)); - - std::vector::iterator> pointers; - std::copy(boost::make_counting_iterator(numbers.begin()), - boost::make_counting_iterator(numbers.end()), - std::back_inserter(pointers)); - - std::cout << "indirectly printing out the numbers from 0 to " - << N << std::endl; - std::copy(boost::make_indirect_iterator(pointers.begin()), - boost::make_indirect_iterator(pointers.end()), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - -The output is:: - - indirectly printing out the numbers from 0 to 7 - 0 1 2 3 4 5 6 - -The source code for this example can be found `here`__. - -__ ../example/counting_iterator_example.cpp - diff --git a/doc/counting_iterator_ref.rst b/doc/counting_iterator_ref.rst deleted file mode 100644 index bc94db7..0000000 --- a/doc/counting_iterator_ref.rst +++ /dev/null @@ -1,145 +0,0 @@ -:: - - template < - class Incrementable - , class CategoryOrTraversal = use_default - , class Difference = use_default - > - class counting_iterator - { - public: - typedef Incrementable value_type; - typedef const Incrementable& reference; - typedef const Incrementable* pointer; - typedef /* see below */ difference_type; - typedef /* see below */ iterator_category; - - counting_iterator(); - counting_iterator(counting_iterator const& rhs); - explicit counting_iterator(Incrementable x); - Incrementable const& base() const; - reference operator*() const; - counting_iterator& operator++(); - counting_iterator& operator--(); - private: - Incrementable m_inc; // exposition - }; - - -If the ``Difference`` argument is ``use_default`` then -``difference_type`` is an unspecified signed integral -type. Otherwise ``difference_type`` is ``Difference``. - -``iterator_category`` is determined according to the following -algorithm: - -.. parsed-literal:: - - if (CategoryOrTraversal is not use_default) - return CategoryOrTraversal - else if (numeric_limits::is_specialized) - return |iterator-category|_\ ( - random_access_traversal_tag, Incrementable, const Incrementable&) - else - return |iterator-category|_\ ( - iterator_traversal::type, - Incrementable, const Incrementable&) - -[*Note:* implementers are encouraged to provide an implementation of - ``operator-`` and a ``difference_type`` that avoids overflows in - the cases where ``std::numeric_limits::is_specialized`` - is true.] - -``counting_iterator`` requirements -.................................. - -The ``Incrementable`` argument shall be Copy Constructible and Assignable. - -If ``iterator_category`` is convertible to ``forward_iterator_tag`` -or ``forward_traversal_tag``, the following must be well-formed:: - - Incrementable i, j; - ++i; // pre-increment - i == j; // operator equal - - -If ``iterator_category`` is convertible to -``bidirectional_iterator_tag`` or ``bidirectional_traversal_tag``, -the following expression must also be well-formed:: - - --i - -If ``iterator_category`` is convertible to -``random_access_iterator_tag`` or ``random_access_traversal_tag``, -the following must must also be valid:: - - counting_iterator::difference_type n; - i += n; - n = i - j; - i < j; - -``counting_iterator`` models -............................ - -Specializations of ``counting_iterator`` model Readable Lvalue -Iterator. In addition, they model the concepts corresponding to the -iterator tags to which their ``iterator_category`` is convertible. -Also, if ``CategoryOrTraversal`` is not ``use_default`` then -``counting_iterator`` models the concept corresponding to the iterator -tag ``CategoryOrTraversal``. Otherwise, if -``numeric_limits::is_specialized``, then -``counting_iterator`` models Random Access Traversal Iterator. -Otherwise, ``counting_iterator`` models the same iterator traversal -concepts modeled by ``Incrementable``. - -``counting_iterator`` is interoperable with -``counting_iterator`` if and only if ``X`` is -interoperable with ``Y``. - - - -``counting_iterator`` operations -................................ - -In addition to the operations required by the concepts modeled by -``counting_iterator``, ``counting_iterator`` provides the following -operations. - - -``counting_iterator();`` - -:Requires: ``Incrementable`` is Default Constructible. -:Effects: Default construct the member ``m_inc``. - - -``counting_iterator(counting_iterator const& rhs);`` - -:Effects: Construct member ``m_inc`` from ``rhs.m_inc``. - - - -``explicit counting_iterator(Incrementable x);`` - -:Effects: Construct member ``m_inc`` from ``x``. - - -``reference operator*() const;`` - -:Returns: ``m_inc`` - - -``counting_iterator& operator++();`` - -:Effects: ``++m_inc`` -:Returns: ``*this`` - - -``counting_iterator& operator--();`` - -:Effects: ``--m_inc`` -:Returns: ``*this`` - - -``Incrementable const& base() const;`` - -:Returns: ``m_inc`` diff --git a/doc/default.css b/doc/default.css deleted file mode 100644 index 0e4226a..0000000 --- a/doc/default.css +++ /dev/null @@ -1,224 +0,0 @@ -/* -:Author: David Goodger -:Contact: goodger@users.sourceforge.net -:date: $Date$ -:version: $Revision$ -:copyright: This stylesheet has been placed in the public domain. - -Default cascading style sheet for the HTML output of Docutils. -*/ - -.first { - margin-top: 0 } - -.last { - margin-bottom: 0 } - -a.toc-backref { - text-decoration: none ; - color: black } - -dd { - margin-bottom: 0.5em } - -div.abstract { - margin: 2em 5em } - -div.abstract p.topic-title { - font-weight: bold ; - text-align: center } - -div.attention, div.caution, div.danger, div.error, div.hint, -div.important, div.note, div.tip, div.warning, div.admonition { - margin: 2em ; - border: medium outset ; - padding: 1em } - -div.attention p.admonition-title, div.caution p.admonition-title, -div.danger p.admonition-title, div.error p.admonition-title, -div.warning p.admonition-title { - color: red ; - font-weight: bold ; - font-family: sans-serif } - -div.hint p.admonition-title, div.important p.admonition-title, -div.note p.admonition-title, div.tip p.admonition-title, -div.admonition p.admonition-title { - font-weight: bold ; - font-family: sans-serif } - -div.dedication { - margin: 2em 5em ; - text-align: center ; - font-style: italic } - -div.dedication p.topic-title { - font-weight: bold ; - font-style: normal } - -div.figure { - margin-left: 2em } - -div.footer, div.header { - font-size: smaller } - -div.sidebar { - margin-left: 1em ; - border: medium outset ; - padding: 0em 1em ; - background-color: #ffffee ; - width: 40% ; - float: right ; - clear: right } - -div.sidebar p.rubric { - font-family: sans-serif ; - font-size: medium } - -div.system-messages { - margin: 5em } - -div.system-messages h1 { - color: red } - -div.system-message { - border: medium outset ; - padding: 1em } - -div.system-message p.system-message-title { - color: red ; - font-weight: bold } - -div.topic { - margin: 2em } - -h1.title { - text-align: center } - -h2.subtitle { - text-align: center } - -hr { - width: 75% } - -ol.simple, ul.simple { - margin-bottom: 1em } - -ol.arabic { - list-style: decimal } - -ol.loweralpha { - list-style: lower-alpha } - -ol.upperalpha { - list-style: upper-alpha } - -ol.lowerroman { - list-style: lower-roman } - -ol.upperroman { - list-style: upper-roman } - -p.attribution { - text-align: right ; - margin-left: 50% } - -p.caption { - font-style: italic } - -p.credits { - font-style: italic ; - font-size: smaller } - -p.label { - white-space: nowrap } - -p.rubric { - font-weight: bold ; - font-size: larger ; - color: maroon ; - text-align: center } - -p.sidebar-title { - font-family: sans-serif ; - font-weight: bold ; - font-size: larger } - -p.sidebar-subtitle { - font-family: sans-serif ; - font-weight: bold } - -p.topic-title { - font-weight: bold } - -pre.address { - margin-bottom: 0 ; - margin-top: 0 ; - font-family: serif ; - font-size: 100% } - -pre.line-block { - font-family: serif ; - font-size: 100% } - -pre.literal-block, pre.doctest-block { - margin-left: 2em ; - margin-right: 2em ; - background-color: #eeeeee } - -span.classifier { - font-family: sans-serif ; - font-style: oblique } - -span.classifier-delimiter { - font-family: sans-serif ; - font-weight: bold } - -span.interpreted { - font-family: sans-serif } - -span.option { - white-space: nowrap } - -span.option-argument { - font-style: italic } - -span.pre { - white-space: pre } - -span.problematic { - color: red } - -table { - margin-top: 0.5em ; - margin-bottom: 0.5em } - -table.citation { - border-left: solid thin gray ; - padding-left: 0.5ex } - -table.docinfo { - margin: 2em 4em } - -table.footnote { - border-left: solid thin black ; - padding-left: 0.5ex } - -td, th { - padding-left: 0.5em ; - padding-right: 0.5em ; - vertical-align: top } - -th.docinfo-name, th.field-name { - font-weight: bold ; - text-align: left ; - white-space: nowrap } - -h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt { - font-size: 100% } - -tt { - background-color: #eeeeee } - -ul.auto-toc { - list-style-type: none } diff --git a/doc/facade-and-adaptor.diff b/doc/facade-and-adaptor.diff deleted file mode 100755 index 07f0e40..0000000 --- a/doc/facade-and-adaptor.diff +++ /dev/null @@ -1,228 +0,0 @@ -Index: facade-and-adaptor.rst -=================================================================== -RCS file: /cvsroot/boost/boost/libs/iterator/doc/facade-and-adaptor.rst,v -retrieving revision 1.9 -retrieving revision 1.14 -diff -b -d -u -r1.9 -r1.14 ---- facade-and-adaptor.rst 22 Sep 2003 19:55:00 -0000 1.9 -+++ facade-and-adaptor.rst 18 Jan 2004 15:51:06 -0000 1.14 -@@ -3,17 +3,25 @@ None - +++++++++++++++++++++++++++++ - - :Author: David Abrahams, Jeremy Siek, Thomas Witt --:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@acm.org -+:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com - :organization: `Boost Consulting`_, Indiana University `Open Systems -- Lab`_, University of Hanover `Institute for Transport -- Railway Operation and Construction`_ --:date: $Date: 2004/01/18 19:56:39 $ --:Number: N1530=03-0113 -+ Lab`_, `Zephyr Associates, Inc.`_ -+:date: $Date: 2004/01/18 19:56:39 $ -+ -+:Number: This is a revised version of N1530_\ =03-0113, which was -+ accepted for Technical Report 1 by the C++ standard -+ committee's library working group. -+ -+.. Version 1.9 of this ReStructuredText document corresponds to -+ n1530_, the paper accepted by the LWG. -+ -+.. _n1530: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1530.html -+ - :copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved - - .. _`Boost Consulting`: http://www.boost-consulting.com - .. _`Open Systems Lab`: http://www.osl.iu.edu --.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de -+.. _`Zephyr Associates, Inc.`: http://www.styleadvisor.com - - :abstract: We propose a set of class templates that help programmers - build standard-conforming iterators, both from scratch and -@@ -124,15 +132,15 @@ None - ================= - - This proposal is formulated in terms of the new ``iterator concepts`` --as proposed in `n1477`_, since user-defined and especially adapted -+as proposed in n1550_, since user-defined and especially adapted - iterators suffer from the well known categorization problems that are - inherent to the current iterator categories. - --.. _`n1477`: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/papers/2003/n1477.html -+.. _n1550: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/papers/2003/n1550.html - --This proposal does not strictly depend on proposal `n1477`_, as there -+This proposal does not strictly depend on proposal n1550_, as there - is a direct mapping between new and old categories. This proposal --could be reformulated using this mapping if `n1477`_ was not accepted. -+could be reformulated using this mapping if n1550_ was not accepted. - - Interoperability - ================ -@@ -141,24 +149,24 @@ None - current standard. There are currently two defect reports that are - concerned with interoperability issues. - --Issue `179`_ concerns the fact that mutable container iterator types -+Issue 179_ concerns the fact that mutable container iterator types - are only required to be convertible to the corresponding constant - iterator types, but objects of these types are not required to - interoperate in comparison or subtraction expressions. This situation - is tedious in practice and out of line with the way built in types - work. This proposal implements the proposed resolution to issue --`179`_, as most standard library implementations do nowadays. In other -+179_, as most standard library implementations do nowadays. In other - words, if an iterator type A has an implicit or user defined - conversion to an iterator type B, the iterator types are interoperable - and the usual set of operators are available. - --Issue `280`_ concerns the current lack of interoperability between -+Issue 280_ concerns the current lack of interoperability between - reverse iterator types. The proposed new reverse_iterator template - fixes the issues raised in 280. It provides the desired - interoperability without introducing unwanted overloads. - --.. _`179`: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#179 --.. _`280`: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#280 -+.. _179: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#179 -+.. _280: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#280 - - - Iterator Facade -@@ -195,7 +203,7 @@ None - * ``filter_iterator``, which provides a view of an iterator range in - which some elements of the underlying range are skipped. - --.. _counting_iterator: -+.. _counting: - - * ``counting_iterator``, which adapts any incrementable type - (e.g. integers, iterators) so that incrementing/decrementing the -@@ -226,15 +234,13 @@ Issue 9.1 et al - :: - - struct use_default; -- const unsigned use_default_access = -1; - - struct iterator_core_access { /* implementation detail */ }; - - template < - class Derived - , class Value -- , unsigned AccessCategory -- , class TraversalCategory -+ , class CategoryOrTraversal - , class Reference = Value& - , class Difference = ptrdiff_t - > -@@ -244,8 +250,7 @@ Issue 9.1 et al. - class Derived - , class Base - , class Value = use_default -- , unsigned Access = use_default_access -- , class Traversal = use_default -+ , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > -@@ -254,10 +259,9 @@ Issue 9.1 et al. - template < - class Iterator - , class Value = use_default -- , unsigned Access = use_default_access -- , class Traversal = use_default -+ , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class indirect_iterator; - -Issue 9.44y - -+ template -+ struct pointee; -+ -+ template -+ struct indirect_reference; -+ - template - class reverse_iterator; - -@@ -277,8 +287,7 @@ Issue 9.1 et al. - - template < - class Incrementable -- , unsigned Access = use_default_access -- , class Traversal = use_default -+ , class CategoryOrTraversal = use_default - , class Difference = use_default - > - class counting_iterator -@@ -312,17 +321,35 @@ Issue 9.8 - Specialized adaptors [lib.iterator.special.adaptors] - ==================================================== - --.. The requirements for all of these need to be written *much* more -- formally -DWA -- - --[*Note:* The ``enable_if_convertible::type`` expression used in -+The ``enable_if_convertible::type`` expression used in - this section is for exposition purposes. The converting constructors - for specialized adaptors should be only be in an overload set provided - that an object of type ``X`` is implicitly convertible to an object of --type ``Y``. The ``enable_if_convertible`` approach uses SFINAE to -+type ``Y``. -+The signatures involving ``enable_if_convertible`` should behave -+*as-if* ``enable_if_convertible`` were defined to be:: -+ -+ template enable_if_convertible_impl -+ {}; -+ -+ template <> enable_if_convertible_impl -+ { struct type; }; -+ -+ template -+ struct enable_if_convertible -+ : enable_if_convertible_impl::value> -+ {}; -+ -+If an expression other than the default argument is used to supply -+the value of a function parameter whose type is written in terms -+of ``enable_if_convertible``, the program is ill-formed, no -+diagnostic required. -+ -+[*Note:* The ``enable_if_convertible`` approach uses SFINAE to - take the constructor out of the overload set when the types are not --implicitly convertible.] -+implicitly convertible. -+] - - - Indirect iterator -@@ -330,6 +357,16 @@ Issue 9.44y - - .. include:: indirect_iterator_abstract.rst - -+Class template ``pointee`` -+.................................... -+ -+.. include:: pointee_ref.rst -+ -+Class template ``indirect_reference`` -+..................................... -+ -+.. include:: indirect_reference_ref.rst -+ - Class template ``indirect_iterator`` - .................................... - -@@ -393,8 +430,7 @@ - - - --.. -- LocalWords: Abrahams Siek Witt istream ostream iter MTL strided interoperate -+.. LocalWords: Abrahams Siek Witt istream ostream iter MTL strided interoperate - LocalWords: CRTP metafunctions inlining lvalue JGS incrementable BGL LEDA cv - LocalWords: GraphBase struct ptrdiff UnaryFunction const int typename bool pp - LocalWords: lhs rhs SFINAE markup iff tmp OtherDerived OtherIterator DWA foo diff --git a/doc/facade-and-adaptor.html b/doc/facade-and-adaptor.html deleted file mode 100755 index 250b781..0000000 --- a/doc/facade-and-adaptor.html +++ /dev/null @@ -1,2581 +0,0 @@ - - - - - - -Iterator Facade and Adaptor - - - - - - -
-

Iterator Facade and Adaptor

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com
Organization:Boost Consulting, Indiana University Open Systems -Lab, Zephyr Associates, Inc.
Date:2004-01-19
Number:This is a revised version of N1530=03-0113, which was -accepted for Technical Report 1 by the C++ standard -committee's library working group.
- - --- - - - -
copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved
- --- - - - -
abstract:We propose a set of class templates that help programmers -build standard-conforming iterators, both from scratch and -by adapting other iterators.
-
-

Table of Contents

- -
-
-

Motivation

-

Iterators play an important role in modern C++ programming. The -iterator is the central abstraction of the algorithms of the Standard -Library, allowing algorithms to be re-used in in a wide variety of -contexts. The C++ Standard Library contains a wide variety of useful -iterators. Every one of the standard containers comes with constant -and mutable iterators 2, and also reverse versions of those -same iterators which traverse the container in the opposite direction. -The Standard also supplies istream_iterator and -ostream_iterator for reading from and writing to streams, -insert_iterator, front_insert_iterator and -back_insert_iterator for inserting elements into containers, and -raw_storage_iterator for initializing raw memory [7].

-

Despite the many iterators supplied by the Standard Library, obvious -and useful iterators are missing, and creating new iterator types is -still a common task for C++ programmers. The literature documents -several of these, for example line_iterator [3] and Constant_iterator -[9]. The iterator abstraction is so powerful that we expect -programmers will always need to invent new iterator types.

-

Although it is easy to create iterators that almost conform to the -standard, the iterator requirements contain subtleties which can make -creating an iterator which actually conforms quite difficult. -Further, the iterator interface is rich, containing many operators -that are technically redundant and tedious to implement. To automate -the repetitive work of constructing iterators, we propose -iterator_facade, an iterator base class template which provides -the rich interface of standard iterators and delegates its -implementation to member functions of the derived class. In addition -to reducing the amount of code necessary to create an iterator, the -iterator_facade also provides compile-time error detection. -Iterator implementation mistakes that often go unnoticed are turned -into compile-time errors because the derived class implementation must -match the expectations of the iterator_facade.

-

A common pattern of iterator construction is the adaptation of one -iterator to form a new one. The functionality of an iterator is -composed of four orthogonal aspects: traversal, indirection, equality -comparison and distance measurement. Adapting an old iterator to -create a new one often saves work because one can reuse one aspect of -functionality while redefining the other. For example, the Standard -provides reverse_iterator, which adapts any Bidirectional Iterator -by inverting its direction of traversal. As with plain iterators, -iterator adaptors defined outside the Standard have become commonplace -in the literature:

-
    -
  • Checked iter[13] adds bounds-checking to an existing iterator.
  • -
  • The iterators of the View Template Library[14], which adapts -containers, are themselves adaptors over the underlying iterators.
  • -
  • Smart iterators [5] adapt an iterator's dereferencing behavior by -applying a function object to the object being referenced and -returning the result.
  • -
  • Custom iterators [4], in which a variety of adaptor types are enumerated.
  • -
  • Compound iterators [1], which access a slice out of a container of containers.
  • -
  • Several iterator adaptors from the MTL [12]. The MTL contains a -strided iterator, where each call to operator++() moves the -iterator ahead by some constant factor, and a scaled iterator, which -multiplies the dereferenced value by some constant.
  • -
- - - - - -
[1]We use the term concept to mean a set of requirements -that a type must satisfy to be used with a particular template -parameter.
- - - - - -
[2]The term mutable iterator refers to iterators over objects that -can be changed by assigning to the dereferenced iterator, while -constant iterator refers to iterators over objects that cannot be -modified.
-

To fulfill the need for constructing adaptors, we propose the -iterator_adaptor class template. Instantiations of -iterator_adaptor serve as a base classes for new iterators, -providing the default behavior of forwarding all operations to the -underlying iterator. The user can selectively replace these features -in the derived iterator class. This proposal also includes a number -of more specialized adaptors, such as the transform_iterator that -applies some user-specified function during the dereference of the -iterator.

-
-
-

Impact on the Standard

-

This proposal is purely an addition to the C++ standard library. -However, note that this proposal relies on the proposal for New -Iterator Concepts.

-
-
-

Design

-
-

Iterator Concepts

-

This proposal is formulated in terms of the new iterator concepts -as proposed in n1550, since user-defined and especially adapted -iterators suffer from the well known categorization problems that are -inherent to the current iterator categories.

-

This proposal does not strictly depend on proposal n1550, as there -is a direct mapping between new and old categories. This proposal -could be reformulated using this mapping if n1550 was not accepted.

-
-
-

Interoperability

-

The question of iterator interoperability is poorly addressed in the -current standard. There are currently two defect reports that are -concerned with interoperability issues.

-

Issue 179 concerns the fact that mutable container iterator types -are only required to be convertible to the corresponding constant -iterator types, but objects of these types are not required to -interoperate in comparison or subtraction expressions. This situation -is tedious in practice and out of line with the way built in types -work. This proposal implements the proposed resolution to issue -179, as most standard library implementations do nowadays. In other -words, if an iterator type A has an implicit or user defined -conversion to an iterator type B, the iterator types are interoperable -and the usual set of operators are available.

-

Issue 280 concerns the current lack of interoperability between -reverse iterator types. The proposed new reverse_iterator template -fixes the issues raised in 280. It provides the desired -interoperability without introducing unwanted overloads.

-
-
-

Iterator Facade

- - -

While the iterator interface is rich, there is a core subset of the -interface that is necessary for all the functionality. We have -identified the following core behaviors for iterators:

-
    -
  • dereferencing
  • -
  • incrementing
  • -
  • decrementing
  • -
  • equality comparison
  • -
  • random-access motion
  • -
  • distance measurement
  • -
-

In addition to the behaviors listed above, the core interface elements -include the associated types exposed through iterator traits: -value_type, reference, difference_type, and -iterator_category.

-

Iterator facade uses the Curiously Recurring Template -Pattern (CRTP) [Cop95] so that the user can specify the behavior -of iterator_facade in a derived class. Former designs used -policy objects to specify the behavior, but that approach was -discarded for several reasons:

-
-
    -
  1. the creation and eventual copying of the policy object may create -overhead that can be avoided with the current approach.
  2. -
  3. The policy object approach does not allow for custom constructors -on the created iterator types, an essential feature if -iterator_facade should be used in other library -implementations.
  4. -
  5. Without the use of CRTP, the standard requirement that an -iterator's operator++ returns the iterator type itself -would mean that all iterators built with the library would -have to be specializations of iterator_facade<...>, rather -than something more descriptive like -indirect_iterator<T*>. Cumbersome type generator -metafunctions would be needed to build new parameterized -iterators, and a separate iterator_adaptor layer would be -impossible.
  6. -
-
-
-

Usage

-

The user of iterator_facade derives his iterator class from a -specialization of iterator_facade and passes the derived -iterator class as iterator_facade's first template parameter. -The order of the other template parameters have been carefully -chosen to take advantage of useful defaults. For example, when -defining a constant lvalue iterator, the user can pass a -const-qualified version of the iterator's value_type as -iterator_facade's Value parameter and omit the -Reference parameter which follows.

-

The derived iterator class must define member functions implementing -the iterator's core behaviors. The following table describes -expressions which are required to be valid depending on the category -of the derived iterator type. These member functions are described -briefly below and in more detail in the iterator facade -requirements.

-
- ---- - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionEffects
i.dereference()Access the value referred to
i.equal(j)Compare for equality with j
i.increment()Advance by one position
i.decrement()Retreat by one position
i.advance(n)Advance by n positions
i.distance_to(j)Measure the distance to j
-
- -

In addition to implementing the core interface functions, an iterator -derived from iterator_facade typically defines several -constructors. To model any of the standard iterator concepts, the -iterator must at least have a copy constructor. Also, if the iterator -type X is meant to be automatically interoperate with another -iterator type Y (as with constant and mutable iterators) then -there must be an implicit conversion from X to Y or from Y -to X (but not both), typically implemented as a conversion -constructor. Finally, if the iterator is to model Forward Traversal -Iterator or a more-refined iterator concept, a default constructor is -required.

-
-
-

Iterator Core Access

-

iterator_facade and the operator implementations need to be able -to access the core member functions in the derived class. Making the -core member functions public would expose an implementation detail to -the user. The design used here ensures that implementation details do -not appear in the public interface of the derived iterator type.

-

Preventing direct access to the core member functions has two -advantages. First, there is no possibility for the user to accidently -use a member function of the iterator when a member of the value_type -was intended. This has been an issue with smart pointer -implementations in the past. The second and main advantage is that -library implementers can freely exchange a hand-rolled iterator -implementation for one based on iterator_facade without fear of -breaking code that was accessing the public core member functions -directly.

-

In a naive implementation, keeping the derived class' core member -functions private would require it to grant friendship to -iterator_facade and each of the seven operators. In order to -reduce the burden of limiting access, iterator_core_access is -provided, a class that acts as a gateway to the core member functions -in the derived iterator class. The author of the derived class only -needs to grant friendship to iterator_core_access to make his core -member functions available to the library.

- - -

iterator_core_access will be typically implemented as an empty -class containing only private static member functions which invoke the -iterator core member functions. There is, however, no need to -standardize the gateway protocol. Note that even if -iterator_core_access used public member functions it would not -open a safety loophole, as every core member function preserves the -invariants of the iterator.

-
-
-

operator[]

-

The indexing operator for a generalized iterator presents special -challenges. A random access iterator's operator[] is only -required to return something convertible to its value_type. -Requiring that it return an lvalue would rule out currently-legal -random-access iterators which hold the referenced value in a data -member (e.g. counting_iterator), because *(p+n) is a reference -into the temporary iterator p+n, which is destroyed when -operator[] returns.

-

Writable iterators built with iterator_facade implement the -semantics required by the preferred resolution to issue 299 and -adopted by proposal n1550: the result of p[n] is an object -convertible to the iterator's value_type, and p[n] = x is -equivalent to *(p + n) = x (Note: This result object may be -implemented as a proxy containing a copy of p+n). This approach -will work properly for any random-access iterator regardless of the -other details of its implementation. A user who knows more about -the implementation of her iterator is free to implement an -operator[] that returns an lvalue in the derived iterator -class; it will hide the one supplied by iterator_facade from -clients of her iterator.

-
-
-

operator->

-

The reference type of a readable iterator (and today's input -iterator) need not in fact be a reference, so long as it is -convertible to the iterator's value_type. When the value_type -is a class, however, it must still be possible to access members -through operator->. Therefore, an iterator whose reference -type is not in fact a reference must return a proxy containing a copy -of the referenced value from its operator->.

-

The return types for iterator_facade's operator-> and -operator[] are not explicitly specified. Instead, those types -are described in terms of a set of requirements, which must be -satisfied by the iterator_facade implementation.

- - -- - - -
[Cop95][Coplien, 1995] Coplien, J., Curiously Recurring Template -Patterns, C++ Report, February 1995, pp. 24-27.
-
-
-
-

Iterator Adaptor

- - -

The iterator_adaptor class template adapts some Base 3 -type to create a new iterator. Instantiations of iterator_adaptor -are derived from a corresponding instantiation of iterator_facade -and implement the core behaviors in terms of the Base type. In -essence, iterator_adaptor merely forwards all operations to an -instance of the Base type, which it stores as a member.

- - - - - -
[3]The term "Base" here does not refer to a base class and is -not meant to imply the use of derivation. We have followed the lead -of the standard library, which provides a base() function to access -the underlying iterator object of a reverse_iterator adaptor.
-

The user of iterator_adaptor creates a class derived from an -instantiation of iterator_adaptor and then selectively -redefines some of the core member functions described in the table -above. The Base type need not meet the full requirements for an -iterator. It need only support the operations used by the core -interface functions of iterator_adaptor that have not been -redefined in the user's derived class.

-

Several of the template parameters of iterator_adaptor default -to use_default. This allows the -user to make use of a default parameter even when she wants to -specify a parameter later in the parameter list. Also, the -defaults for the corresponding associated types are somewhat -complicated, so metaprogramming is required to compute them, and -use_default can help to simplify the implementation. Finally, -the identity of the use_default type is not left unspecified -because specification helps to highlight that the Reference -template parameter may not always be identical to the iterator's -reference type, and will keep users from making mistakes based on -that assumption.

-
-
-

Specialized Adaptors

-

This proposal also contains several examples of specialized adaptors -which were easily implemented using iterator_adaptor:

-
    -
  • indirect_iterator, which iterates over iterators, pointers, -or smart pointers and applies an extra level of dereferencing.
  • -
  • A new reverse_iterator, which inverts the direction of a Base -iterator's motion, while allowing adapted constant and mutable -iterators to interact in the expected ways (unlike those in most -implementations of C++98).
  • -
  • transform_iterator, which applies a user-defined function object -to the underlying values when dereferenced.
  • -
  • projection_iterator, which is similar to transform_iterator -except that when dereferenced it returns a reference instead of -a value.
  • -
  • filter_iterator, which provides a view of an iterator range in -which some elements of the underlying range are skipped.
  • -
-
    -
  • counting_iterator, which adapts any incrementable type -(e.g. integers, iterators) so that incrementing/decrementing the -adapted iterator and dereferencing it produces successive values of -the Base type.
  • -
  • function_output_iterator, which makes it easier to create custom -output iterators.
  • -
-

Based on examples in the Boost library, users have generated many new -adaptors, among them a permutation adaptor which applies some -permutation to a random access iterator, and a strided adaptor, which -adapts a random access iterator by multiplying its unit of motion by a -constant factor. In addition, the Boost Graph Library (BGL) uses -iterator adaptors to adapt other graph libraries, such as LEDA [10] -and Stanford GraphBase [8], to the BGL interface (which requires C++ -Standard compliant iterators).

-
-
-
-

Proposed Text

-
-

Header <iterator_helper> synopsis [lib.iterator.helper.synopsis]

-
-struct use_default;
-
-struct iterator_core_access { /* implementation detail */ };
-
-template <
-    class Derived
-  , class Value
-  , class CategoryOrTraversal
-  , class Reference  = Value&
-  , class Difference = ptrdiff_t
->
-class iterator_facade;
-
-template <
-    class Derived
-  , class Base
-  , class Value      = use_default
-  , class CategoryOrTraversal  = use_default
-  , class Reference  = use_default
-  , class Difference = use_default
->
-class iterator_adaptor;
-
-template <
-    class Iterator
-  , class Value = use_default
-  , class CategoryOrTraversal = use_default
-  , class Reference = use_default
-  , class Difference = use_default
->
-class indirect_iterator;
-
-template <class Dereferenceable>
-struct pointee;
-
-template <class Dereferenceable>
-struct indirect_reference;
-
-template <class Iterator>
-class reverse_iterator;
-
-template <
-    class UnaryFunction
-  , class Iterator
-  , class Reference = use_default
-  , class Value = use_default
->
-class transform_iterator;
-
-template <class Predicate, class Iterator>
-class filter_iterator;
-
-template <
-    class Incrementable
-  , class CategoryOrTraversal  = use_default
-  , class Difference = use_default
->
-class counting_iterator;
-
-template <class UnaryFunction>
-class function_output_iterator;
-
-
-
-

Iterator facade [lib.iterator.facade]

-

iterator_facade is a base class template that implements the -interface of standard iterators in terms of a few core functions -and associated types, to be supplied by a derived iterator class.

-
-

Class template iterator_facade

- - -
-template <
-    class Derived
-  , class Value
-  , class CategoryOrTraversal
-  , class Reference  = Value&
-  , class Difference = ptrdiff_t
->
-class iterator_facade {
-public:
-    typedef remove_const<Value>::type value_type;
-    typedef Reference reference;
-    typedef Value* pointer;
-    typedef Difference difference_type;
-    typedef /* see below */ iterator_category;
-
-    reference operator*() const;
-    /* see below */ operator->() const;
-    /* see below */ operator[](difference_type n) const;
-    Derived& operator++();
-    Derived operator++(int);
-    Derived& operator--();
-    Derived operator--(int);
-    Derived& operator+=(difference_type n);
-    Derived& operator-=(difference_type n);
-    Derived operator-(difference_type n) const;
-};
-
-// Comparison operators
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type // exposition
-operator ==(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator !=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-// Iterator difference
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-/* see below */
-operator-(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-          iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-// Iterator addition
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (iterator_facade<Dr,V,TC,R,D> const&,
-                   typename Derived::difference_type n);
-
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (typename Derived::difference_type n,
-                   iterator_facade<Dr,V,TC,R,D> const&);
-
-

The iterator_category member of iterator_facade is

-
-iterator-category(CategoryOrTraversal, value_type, reference)
-
-

where iterator-category is defined as follows:

-
-iterator-category(C,R,V) :=
-   if (C is convertible to std::input_iterator_tag
-       || C is convertible to std::output_iterator_tag
-   )
-       return C
-
-   else if (C is not convertible to incrementable_traversal_tag)
-       the program is ill-formed
-
-   else return a type X satisfying the following two constraints:
-
-      1. X is convertible to X1, and not to any more-derived
-         type, where X1 is defined by:
-
-           if (R is a reference type
-               && C is convertible to forward_traversal_tag)
-           {
-               if (C is convertible to random_access_traversal_tag)
-                   X1 = random_access_iterator_tag
-               else if (C is convertible to bidirectional_traversal_tag)
-                   X1 = bidirectional_iterator_tag
-               else
-                   X1 = forward_iterator_tag
-           }
-           else
-           {
-               if (C is convertible to single_pass_traversal_tag
-                   && R is convertible to V)
-                   X1 = input_iterator_tag
-               else
-                   X1 = C
-           }
-
-      2. category-to-traversal(X) is convertible to the most
-         derived traversal tag type to which X is also
-         convertible, and not to any more-derived traversal tag
-         type.
-
-

[Note: the intention is to allow iterator_category to be one of -the five original category tags when convertibility to one of the -traversal tags would add no information]

- - - -

The enable_if_interoperable template used above is for exposition -purposes. The member operators should only be in an overload set -provided the derived types Dr1 and Dr2 are interoperable, -meaning that at least one of the types is convertible to the other. The -enable_if_interoperable approach uses SFINAE to take the operators -out of the overload set when the types are not interoperable. -The operators should behave as-if enable_if_interoperable -were defined to be:

-
-template <bool, typename> enable_if_interoperable_impl
-{};
-
-template <typename T> enable_if_interoperable_impl<true,T>
-{ typedef T type; };
-
-template<typename Dr1, typename Dr2, typename T>
-struct enable_if_interoperable
-  : enable_if_interoperable_impl<
-        is_convertible<Dr1,Dr2>::value || is_convertible<Dr2,Dr1>::value
-      , T
-    >
-{};
-
-
-
-

iterator_facade Requirements

-

The following table describes the typical valid expressions on -iterator_facade's Derived parameter, depending on the -iterator concept(s) it will model. The operations in the first -column must be made accessible to member functions of class -iterator_core_access. In addition, -static_cast<Derived*>(iterator_facade*) shall be well-formed.

-

In the table below, F is iterator_facade<X,V,C,R,D>, a is an -object of type X, b and c are objects of type const X, -n is an object of F::difference_type, y is a constant -object of a single pass iterator type interoperable with X, and z -is a constant object of a random access traversal iterator type -interoperable with X.

-
-

iterator_facade Core Operations

- ------ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionReturn TypeAssertion/NoteUsed to implement Iterator -Concept(s)
c.dereference()F::reference Readable Iterator, Writable -Iterator
c.equal(y)convertible to booltrue iff c and y -refer to the same -position.Single Pass Iterator
a.increment()unused Incrementable Iterator
a.decrement()unused Bidirectional Traversal -Iterator
a.advance(n)unused Random Access Traversal -Iterator
c.distance_to(z)convertible to -F::difference_typeequivalent to -distance(c, X(z)).Random Access Traversal -Iterator
-
-
-
-

iterator_facade operations

-

The operations in this section are described in terms of operations on -the core interface of Derived which may be inaccessible -(i.e. private). The implementation should access these operations -through member functions of class iterator_core_access.

-

reference operator*() const;

- --- - - - -
Returns:static_cast<Derived const*>(this)->dereference()
-

operator->() const; (see below)

- --- - - - -
Returns:

If reference is a reference type, an object -of type pointer equal to:

-
-&static_cast<Derived const*>(this)->dereference()
-
-

Otherwise returns an object of unspecified type such that, -(*static_cast<Derived const*>(this))->m is equivalent to (w = **static_cast<Derived const*>(this), -w.m) for some temporary object w of type value_type.

-
-

unspecified operator[](difference_type n) const;

- --- - - - -
Returns:an object convertible to value_type. For constant -objects v of type value_type, and n of type -difference_type, (*this)[n] = v is equivalent to -*(*this + n) = v, and static_cast<value_type -const&>((*this)[n]) is equivalent to -static_cast<value_type const&>(*(*this + n))
-

Derived& operator++();

- --- - - - -
Effects:
-static_cast<Derived*>(this)->increment();
-return *static_cast<Derived*>(this);
-
-
-

Derived operator++(int);

- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
-++*this;
-return tmp;
-
-
-

Derived& operator--();

- --- - - - -
Effects:
-static_cast<Derived*>(this)->decrement();
-return *static_cast<Derived*>(this);
-
-
-

Derived operator--(int);

- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
---*this;
-return tmp;
-
-
-

Derived& operator+=(difference_type n);

- --- - - - -
Effects:
-static_cast<Derived*>(this)->advance(n);
-return *static_cast<Derived*>(this);
-
-
-

Derived& operator-=(difference_type n);

- --- - - - -
Effects:
-static_cast<Derived*>(this)->advance(-n);
-return *static_cast<Derived*>(this);
-
-
-

Derived operator-(difference_type n) const;

- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
-return tmp -= n;
-
-
-
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (iterator_facade<Dr,V,TC,R,D> const&,
-                   typename Derived::difference_type n);
-
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (typename Derived::difference_type n,
-                   iterator_facade<Dr,V,TC,R,D> const&);
-
- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
-return tmp += n;
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator ==(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:if is_convertible<Dr2,Dr1>::value, then -lhs.equal(rhs). Otherwise, rhs.equal(lhs).
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator !=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:if is_convertible<Dr2,Dr1>::value, then -!lhs.equal(rhs). Otherwise, !rhs.equal(lhs).
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:if is_convertible<Dr2,Dr1>::value, then -lhs.distance_to(rhs) < 0. Otherwise, rhs.distance_to(lhs) > -0.
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:if is_convertible<Dr2,Dr1>::value, then -lhs.distance_to(rhs) <= 0. Otherwise, rhs.distance_to(lhs) ->= 0.
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:if is_convertible<Dr2,Dr1>::value, then -lhs.distance_to(rhs) > 0. Otherwise, -rhs.distance_to(lhs) < 0.
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:if is_convertible<Dr2,Dr1>::value, then -lhs.distance_to(rhs) >= 0. Otherwise, -rhs.distance_to(lhs) <= 0.
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,difference_type>::type
-operator -(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - - - -
Return Type:if is_convertible<Dr2,Dr1>::value, then difference_type shall be -iterator_traits<Dr1>::difference_type. Otherwise, -difference_type shall be -iterator_traits<Dr2>::difference_type.
Returns:if is_convertible<Dr2,Dr1>::value, then --lhs.distance_to(rhs). Otherwise, -rhs.distance_to(lhs).
-
-
-
-

Iterator adaptor [lib.iterator.adaptor]

- - -

Each specialization of the iterator_adaptor class template is derived from -a specialization of iterator_facade. The core interface functions -expected by iterator_facade are implemented in terms of the -iterator_adaptor's Base template parameter. A class derived -from iterator_adaptor typically redefines some of the core -interface functions to adapt the behavior of the Base type. -Whether the derived class models any of the standard iterator concepts -depends on the operations supported by the Base type and which -core interface functions of iterator_facade are redefined in the -Derived class.

-
-

Class template iterator_adaptor

- - -
-template <
-    class Derived
-  , class Base
-  , class Value               = use_default
-  , class CategoryOrTraversal = use_default
-  , class Reference           = use_default
-  , class Difference = use_default
->
-class iterator_adaptor 
-  : public iterator_facade<Derived, V', C', R', D'> // see details
-{
-    friend class iterator_core_access;
- public:
-    iterator_adaptor();
-    explicit iterator_adaptor(Base iter);
-    Base const& base() const;
- protected:
-    Base const& base_reference() const;
-    Base& base_reference();
- private: // Core iterator interface for iterator_facade.  
-    typename iterator_adaptor::reference dereference() const;
-
-    template <
-    class OtherDerived, class OtherIterator, class V, class C, class R, class D
-    >   
-    bool equal(iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& x) const;
-
-    void advance(typename iterator_adaptor::difference_type n);
-    void increment();
-    void decrement();
-
-    template <
-        class OtherDerived, class OtherIterator, class V, class C, class R, class D
-    >   
-    typename iterator_adaptor::difference_type distance_to(
-        iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& y) const;
-
- private:
-    Base m_iterator; // exposition only
-};
-
-
-
-

iterator_adaptor requirements

-

static_cast<Derived*>(iterator_adaptor*) shall be well-formed. -The Base argument shall be Assignable and Copy Constructible.

-
-
-

iterator_adaptor base class parameters

-

The V', C', R', and D' parameters of the iterator_facade -used as a base class in the summary of iterator_adaptor -above are defined as follows:

-
-V' = if (Value is use_default)
-          return iterator_traits<Base>::value_type
-      else
-          return Value
-
-C' = if (CategoryOrTraversal is use_default)
-          return iterator_traversal<Base>::type
-      else
-          return CategoryOrTraversal
-
-R' = if (Reference is use_default)
-          if (Value is use_default)
-              return iterator_traits<Base>::reference
-          else
-              return Value&
-      else
-          return Reference
-
-D' = if (Difference is use_default)
-          return iterator_traits<Base>::difference_type
-      else
-          return Difference
-
- - - -
-
-

iterator_adaptor public operations

-

iterator_adaptor();

- --- - - - - - -
Requires:The Base type must be Default Constructible.
Returns:An instance of iterator_adaptor with -m_iterator default constructed.
-

explicit iterator_adaptor(Base iter);

- --- - - - -
Returns:An instance of iterator_adaptor with -m_iterator copy constructed from iter.
-

Base const& base() const;

- --- - - - -
Returns:m_iterator
-
-
-

iterator_adaptor protected member functions

-

Base const& base_reference() const;

- --- - - - -
Returns:A const reference to m_iterator.
-

Base& base_reference();

- --- - - - -
Returns:A non-const reference to m_iterator.
-
-
-

iterator_adaptor private member functions

-

typename iterator_adaptor::reference dereference() const;

- --- - - - -
Returns:*m_iterator
-
-template <
-class OtherDerived, class OtherIterator, class V, class C, class R, class D
->   
-bool equal(iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& x) const;
-
- --- - - - -
Returns:m_iterator == x.base()
-

void advance(typename iterator_adaptor::difference_type n);

- --- - - - -
Effects:m_iterator += n;
-

void increment();

- --- - - - -
Effects:++m_iterator;
-

void decrement();

- --- - - - -
Effects:--m_iterator;
-
-template <
-    class OtherDerived, class OtherIterator, class V, class C, class R, class D
->   
-typename iterator_adaptor::difference_type distance_to(
-    iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& y) const;
-
- --- - - - -
Returns:y.base() - m_iterator
-
-
-
-

Specialized adaptors [lib.iterator.special.adaptors]

-

The enable_if_convertible<X,Y>::type expression used in -this section is for exposition purposes. The converting constructors -for specialized adaptors should be only be in an overload set provided -that an object of type X is implicitly convertible to an object of -type Y. -The signatures involving enable_if_convertible should behave -as-if enable_if_convertible were defined to be:

-
-template <bool> enable_if_convertible_impl
-{};
-
-template <> enable_if_convertible_impl<true>
-{ struct type; };
-
-template<typename From, typename To>
-struct enable_if_convertible
-  : enable_if_convertible_impl<is_convertible<From,To>::value>
-{};
-
-

If an expression other than the default argument is used to supply -the value of a function parameter whose type is written in terms -of enable_if_convertible, the program is ill-formed, no -diagnostic required.

-

[Note: The enable_if_convertible approach uses SFINAE to -take the constructor out of the overload set when the types are not -implicitly convertible. -]

-
-

Indirect iterator

-

indirect_iterator adapts an iterator by applying an -extra dereference inside of operator*(). For example, this -iterator adaptor makes it possible to view a container of pointers -(e.g. list<foo*>) as if it were a container of the pointed-to type -(e.g. list<foo>). indirect_iterator depends on two -auxiliary traits, pointee and indirect_reference, to -provide support for underlying iterators whose value_type is -not an iterator.

-
-

Class template pointee

- - - -
-template <class Dereferenceable>
-struct pointee
-{
-    typedef /* see below */ type;
-};
-
- --- - - - -
Requires:For an object x of type Dereferenceable, *x -is well-formed. If ++x is ill-formed it shall neither be -ambiguous nor shall it violate access control, and -Dereferenceable::element_type shall be an accessible type. -Otherwise iterator_traits<Dereferenceable>::value_type shall -be well formed. [Note: These requirements need not apply to -explicit or partial specializations of pointee]
-

type is determined according to the following algorithm, where -x is an object of type Dereferenceable:

-
-if ( ++x is ill-formed )
-{
-    return ``Dereferenceable::element_type``
-}
-else if (``*x`` is a mutable reference to
-         std::iterator_traits<Dereferenceable>::value_type)
-{
-    return iterator_traits<Dereferenceable>::value_type
-}
-else
-{
-    return iterator_traits<Dereferenceable>::value_type const
-}
-
-
-
-

Class template indirect_reference

- - - -
-template <class Dereferenceable>
-struct indirect_reference
-{
-    typedef /* see below */ type;
-};
-
- --- - - - -
Requires:For an object x of type Dereferenceable, *x -is well-formed. If ++x is ill-formed it shall neither be -ambiguous nor shall it violate access control, and -pointee<Dereferenceable>::type& shall be well-formed. -Otherwise iterator_traits<Dereferenceable>::reference shall -be well formed. [Note: These requirements need not apply to -explicit or partial specializations of indirect_reference]
-

type is determined according to the following algorithm, where -x is an object of type Dereferenceable:

-
-if ( ++x is ill-formed )
-    return ``pointee<Dereferenceable>::type&``
-else
-    std::iterator_traits<Dereferenceable>::reference
-
-
-
-

Class template indirect_iterator

-
-template <
-    class Iterator
-  , class Value = use_default
-  , class CategoryOrTraversal = use_default
-  , class Reference = use_default
-  , class Difference = use_default
->
-class indirect_iterator
-{
- public:
-    typedef /* see below */ value_type;
-    typedef /* see below */ reference;
-    typedef /* see below */ pointer;
-    typedef /* see below */ difference_type;
-    typedef /* see below */ iterator_category;
-
-    indirect_iterator();
-    indirect_iterator(Iterator x);
-
-    template <
-        class Iterator2, class Value2, class Category2
-      , class Reference2, class Difference2
-    >
-    indirect_iterator(
-        indirect_iterator<
-             Iterator2, Value2, Category2, Reference2, Difference2
-        > const& y
-      , typename enable_if_convertible<Iterator2, Iterator>::type* = 0 // exposition
-    );
-
-    Iterator const& base() const;
-    reference operator*() const;
-    indirect_iterator& operator++();
-    indirect_iterator& operator--();
-private:
-   Iterator m_iterator; // exposition
-};
-
-

The member types of indirect_iterator are defined according to -the following pseudo-code, where V is -iterator_traits<Iterator>::value_type

-
-if (Value is use_default) then
-    typedef remove_const<pointee<V>::type>::type value_type;
-else
-    typedef remove_const<Value>::type value_type;
-
-if (Reference is use_default) then
-    if (Value is use_default) then
-        typedef indirect_reference<V>::type reference;
-    else
-        typedef Value& reference;
-else
-    typedef Reference reference;
-
-if (Value is use_default) then 
-    typedef pointee<V>::type* pointer;
-else 
-    typedef Value* pointer;
-
-if (Difference is use_default)
-    typedef iterator_traits<Iterator>::difference_type difference_type;
-else
-    typedef Difference difference_type;
-
-if (CategoryOrTraversal is use_default)
-    typedef iterator-category (
-        iterator_traversal<Iterator>::type,``reference``,``value_type``
-    ) iterator_category;
-else
-    typedef iterator-category (
-        CategoryOrTraversal,``reference``,``value_type``
-    ) iterator_category;
-
-
-
-

indirect_iterator requirements

-

The expression *v, where v is an object of -iterator_traits<Iterator>::value_type, shall be valid -expression and convertible to reference. Iterator shall -model the traversal concept indicated by iterator_category. -Value, Reference, and Difference shall be chosen so -that value_type, reference, and difference_type meet -the requirements indicated by iterator_category.

-

[Note: there are further requirements on the -iterator_traits<Iterator>::value_type if the Value -parameter is not use_default, as implied by the algorithm for -deducing the default for the value_type member.]

-
-
-

indirect_iterator models

-

In addition to the concepts indicated by iterator_category -and by iterator_traversal<indirect_iterator>::type, a -specialization of indirect_iterator models the following -concepts, Where v is an object of -iterator_traits<Iterator>::value_type:

-
-
    -
  • Readable Iterator if reference(*v) is convertible to -value_type.
  • -
  • Writable Iterator if reference(*v) = t is a valid -expression (where t is an object of type -indirect_iterator::value_type)
  • -
  • Lvalue Iterator if reference is a reference type.
  • -
-
-

indirect_iterator<X,V1,C1,R1,D1> is interoperable with -indirect_iterator<Y,V2,C2,R2,D2> if and only if X is -interoperable with Y.

-
-
-

indirect_iterator operations

-

In addition to the operations required by the concepts described -above, specializations of indirect_iterator provide the -following operations.

-

indirect_iterator();

- --- - - - - - -
Requires:Iterator must be Default Constructible.
Effects:Constructs an instance of indirect_iterator with -a default-constructed m_iterator.
-

indirect_iterator(Iterator x);

- --- - - - -
Effects:Constructs an instance of indirect_iterator with -m_iterator copy constructed from x.
-
-template <
-    class Iterator2, class Value2, unsigned Access, class Traversal
-  , class Reference2, class Difference2
->
-indirect_iterator(
-    indirect_iterator<
-         Iterator2, Value2, Access, Traversal, Reference2, Difference2
-    > const& y
-  , typename enable_if_convertible<Iterator2, Iterator>::type* = 0 // exposition
-);
-
- --- - - - - - -
Requires:Iterator2 is implicitly convertible to Iterator.
Effects:Constructs an instance of indirect_iterator whose -m_iterator subobject is constructed from y.base().
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Returns:**m_iterator
-

indirect_iterator& operator++();

- --- - - - - - -
Effects:++m_iterator
Returns:*this
-

indirect_iterator& operator--();

- --- - - - - - -
Effects:--m_iterator
Returns:*this
-
-
-
-

Reverse iterator

-

The reverse iterator adaptor iterates through the adapted iterator -range in the opposite direction.

-
-

Class template reverse_iterator

-
-template <class Iterator>
-class reverse_iterator
-{
-public:
-  typedef iterator_traits<Iterator>::value_type value_type;
-  typedef iterator_traits<Iterator>::reference reference;
-  typedef iterator_traits<Iterator>::pointer pointer;
-  typedef iterator_traits<Iterator>::difference_type difference_type;
-  typedef /* see below */ iterator_category;
-
-  reverse_iterator() {}
-  explicit reverse_iterator(Iterator x) ;
-
-  template<class OtherIterator>
-  reverse_iterator(
-      reverse_iterator<OtherIterator> const& r
-    , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-  );
-  Iterator const& base() const;
-  reference operator*() const;
-  reverse_iterator& operator++();
-  reverse_iterator& operator--();
-private:
-  Iterator m_iterator; // exposition
-};
-
-

If Iterator models Random Access Traversal Iterator and Readable -Lvalue Iterator, then iterator_category is convertible to -random_access_iterator_tag. Otherwise, if -Iterator models Bidirectional Traversal Iterator and Readable -Lvalue Iterator, then iterator_category is convertible to -bidirectional_iterator_tag. Otherwise, iterator_category is -convertible to input_iterator_tag.

-
-
-

reverse_iterator requirements

-

Iterator must be a model of Bidirectional Traversal Iterator.

-
-
-

reverse_iterator models

-

A specialization of reverse_iterator models the same iterator -traversal and iterator access concepts modeled by its Iterator -argument. In addition, it may model old iterator concepts -specified in the following table:

- ---- - - - - - - - - - - - - - - - - - - - -
If I modelsthen reverse_iterator<I> models
Readable Lvalue Iterator, -Bidirectional Traversal IteratorBidirectional Iterator
Writable Lvalue Iterator, -Bidirectional Traversal IteratorMutable Bidirectional Iterator
Readable Lvalue Iterator, -Random Access Traversal IteratorRandom Access Iterator
Writable Lvalue Iterator, -Random Access Traversal IteratorMutable Random Access Iterator
-

reverse_iterator<X> is interoperable with -reverse_iterator<Y> if and only if X is interoperable with -Y.

-
-
-

reverse_iterator operations

-

In addition to the operations required by the concepts modeled by -reverse_iterator, reverse_iterator provides the following -operations.

-

reverse_iterator();

- --- - - - - - -
Requires:Iterator must be Default Constructible.
Effects:Constructs an instance of reverse_iterator with m_iterator -default constructed.
-

explicit reverse_iterator(Iterator x);

- --- - - - -
Effects:Constructs an instance of reverse_iterator with -m_iterator copy constructed from x.
-
-template<class OtherIterator>
-reverse_iterator(
-    reverse_iterator<OtherIterator> const& r
-  , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-);
-
- --- - - - - - -
Requires:OtherIterator is implicitly convertible to Iterator.
Effects:Constructs instance of reverse_iterator whose -m_iterator subobject is constructed from y.base().
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Effects:
-
-Iterator tmp = m_iterator;
-return *--tmp;
-
-

reverse_iterator& operator++();

- --- - - - - - -
Effects:--m_iterator
Returns:*this
-

reverse_iterator& operator--();

- --- - - - - - -
Effects:++m_iterator
Returns:*this
-
-
-
-

Transform iterator

-

The transform iterator adapts an iterator by modifying the -operator* to apply a function object to the result of -dereferencing the iterator and returning the result.

-
-

Class template transform_iterator

- -
-template <class UnaryFunction,
-          class Iterator, 
-          class Reference = use_default, 
-          class Value = use_default>
-class transform_iterator
-{
-public:
-  typedef /* see below */ value_type;
-  typedef /* see below */ reference;
-  typedef /* see below */ pointer;
-  typedef iterator_traits<Iterator>::difference_type difference_type;
-  typedef /* see below */ iterator_category;
-
-  transform_iterator();
-  transform_iterator(Iterator const& x, UnaryFunction f);
-
-  template<class F2, class I2, class R2, class V2>
-  transform_iterator(
-        transform_iterator<F2, I2, R2, V2> const& t
-      , typename enable_if_convertible<I2, Iterator>::type* = 0      // exposition only
-      , typename enable_if_convertible<F2, UnaryFunction>::type* = 0 // exposition only
-  );
-  UnaryFunction functor() const;
-  Iterator const& base() const;
-  reference operator*() const;
-  transform_iterator& operator++();
-  transform_iterator& operator--();
-private:
-  Iterator m_iterator; // exposition only
-  UnaryFunction m_f;   // exposition only
-};
-
-

If Reference is use_default then the reference member of -transform_iterator is -result_of<UnaryFunction(iterator_traits<Iterator>::reference)>::type. -Otherwise, reference is Reference.

-

If Value is use_default then the value_type member is -remove_cv<remove_reference<reference> >::type. Otherwise, -value_type is Value.

-

If Iterator models Readable Lvalue Iterator and if Iterator -models Random Access Traversal Iterator, then iterator_category is -convertible to random_access_iterator_tag. Otherwise, if -Iterator models Bidirectional Traversal Iterator, then -iterator_category is convertible to -bidirectional_iterator_tag. Otherwise iterator_category is -convertible to forward_iterator_tag. If Iterator does not -model Readable Lvalue Iterator then iterator_category is -convertible to input_iterator_tag.

-
-
-

transform_iterator requirements

-

The type UnaryFunction must be Assignable, Copy Constructible, and -the expression f(*i) must be valid where f is an object of -type UnaryFunction, i is an object of type Iterator, and -where the type of f(*i) must be -result_of<UnaryFunction(iterator_traits<Iterator>::reference)>::type.

-

The argument Iterator shall model Readable Iterator.

-
-
-

transform_iterator models

-

The resulting transform_iterator models the most refined of the -following that is also modeled by Iterator.

-
-
    -
  • Writable Lvalue Iterator if transform_iterator::reference is a non-const reference.
  • -
  • Readable Lvalue Iterator if transform_iterator::reference is a const reference.
  • -
  • Readable Iterator otherwise.
  • -
-
-

The transform_iterator models the most refined standard traversal -concept that is modeled by the Iterator argument.

-

If transform_iterator is a model of Readable Lvalue Iterator then -it models the following original iterator concepts depending on what -the Iterator argument models.

- ---- - - - - - - - - - - - - - - - - - - - -
If Iterator modelsthen transform_iterator models
Single Pass IteratorInput Iterator
Forward Traversal IteratorForward Iterator
Bidirectional Traversal IteratorBidirectional Iterator
Random Access Traversal IteratorRandom Access Iterator
-

If transform_iterator models Writable Lvalue Iterator then it is a -mutable iterator (as defined in the old iterator requirements).

-

transform_iterator<F1, X, R1, V1> is interoperable with -transform_iterator<F2, Y, R2, V2> if and only if X is -interoperable with Y.

-
-
-

transform_iterator operations

-

In addition to the operations required by the concepts modeled by -transform_iterator, transform_iterator provides the following -operations.

-

transform_iterator();

- --- - - - -
Returns:An instance of transform_iterator with m_f -and m_iterator default constructed.
-

transform_iterator(Iterator const& x, UnaryFunction f);

- --- - - - -
Returns:An instance of transform_iterator with m_f -initialized to f and m_iterator initialized to x.
-
-template<class OtherIterator, class R2, class V2>
-transform_iterator(
-      transform_iterator<UnaryFunction, OtherIterator, R2, V2> const& t
-    , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-);
-
- --- - - - - - -
Returns:An instance of transform_iterator that is a copy of t.
Requires:OtherIterator is implicitly convertible to Iterator.
-

UnaryFunction functor() const;

- --- - - - -
Returns:m_f
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Returns:m_f(*m_iterator)
-

transform_iterator& operator++();

- --- - - - - - -
Effects:++m_iterator
Returns:*this
-

transform_iterator& operator--();

- --- - - - - - -
Effects:--m_iterator
Returns:*this
-
-
-
-

Filter iterator

-

The filter iterator adaptor creates a view of an iterator range in -which some elements of the range are skipped. A predicate function -object controls which elements are skipped. When the predicate is -applied to an element, if it returns true then the element is -retained and if it returns false then the element is skipped -over. When skipping over elements, it is necessary for the filter -adaptor to know when to stop so as to avoid going past the end of the -underlying range. A filter iterator is therefore constructed with pair -of iterators indicating the range of elements in the unfiltered -sequence to be traversed.

-
-

Class template filter_iterator

- - - - -
-template <class Predicate, class Iterator>
-class filter_iterator
-{
- public:
-    typedef iterator_traits<Iterator>::value_type value_type;
-    typedef iterator_traits<Iterator>::reference reference;
-    typedef iterator_traits<Iterator>::pointer pointer;
-    typedef iterator_traits<Iterator>::difference_type difference_type;
-    typedef /* see below */ iterator_category;
-
-    filter_iterator();
-    filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());
-    filter_iterator(Iterator x, Iterator end = Iterator());
-    template<class OtherIterator>
-    filter_iterator(
-        filter_iterator<Predicate, OtherIterator> const& t
-        , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-        );
-    Predicate predicate() const;
-    Iterator end() const;
-    Iterator const& base() const;
-    reference operator*() const;
-    filter_iterator& operator++();
-private:
-    Predicate m_pred; // exposition only
-    Iterator m_iter;  // exposition only
-    Iterator m_end;   // exposition only
-};
-
-

If Iterator models Readable Lvalue Iterator and Forward Traversal -Iterator then iterator_category is convertible to -std::forward_iterator_tag. Otherwise iterator_category is -convertible to std::input_iterator_tag.

-
-
-

filter_iterator requirements

-

The Iterator argument shall meet the requirements of Readable -Iterator and Single Pass Iterator or it shall meet the requirements of -Input Iterator.

-

The Predicate argument must be Assignable, Copy Constructible, and -the expression p(x) must be valid where p is an object of type -Predicate, x is an object of type -iterator_traits<Iterator>::value_type, and where the type of -p(x) must be convertible to bool.

-
-
-

filter_iterator models

-

The concepts that filter_iterator models are dependent on which -concepts the Iterator argument models, as specified in the -following tables.

- ---- - - - - - - - - - - - - - -
If Iterator modelsthen filter_iterator models
Single Pass IteratorSingle Pass Iterator
Forward Traversal IteratorForward Traversal Iterator
- ---- - - - - - - - - - - - - - - - - -
If Iterator modelsthen filter_iterator models
Readable IteratorReadable Iterator
Writable IteratorWritable Iterator
Lvalue IteratorLvalue Iterator
- ---- - - - - - - - - - - - - - - - - -
If Iterator modelsthen filter_iterator models
Readable Iterator, Single Pass IteratorInput Iterator
Readable Lvalue Iterator, Forward Traversal IteratorForward Iterator
Writable Lvalue Iterator, Forward Traversal IteratorMutable Forward Iterator
-

filter_iterator<P1, X> is interoperable with filter_iterator<P2, Y> -if and only if X is interoperable with Y.

-
-
-

filter_iterator operations

-

In addition to those operations required by the concepts that -filter_iterator models, filter_iterator provides the following -operations.

-

filter_iterator();

- --- - - - - - -
Requires:Predicate and Iterator must be Default Constructible.
Effects:Constructs a filter_iterator whose``m_pred``, m_iter, and m_end -members are a default constructed.
-

filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());

- --- - - - -
Effects:Constructs a filter_iterator where m_iter is either -the first position in the range [x,end) such that f(*m_iter) == true -or else``m_iter == end``. The member m_pred is constructed from -f and m_end from end.
-

filter_iterator(Iterator x, Iterator end = Iterator());

- --- - - - - - -
Requires:Predicate must be Default Constructible and -Predicate is a class type (not a function pointer).
Effects:Constructs a filter_iterator where m_iter is either -the first position in the range [x,end) such that m_pred(*m_iter) == true -or else``m_iter == end``. The member m_pred is default constructed.
-
-template <class OtherIterator>
-filter_iterator(
-    filter_iterator<Predicate, OtherIterator> const& t
-    , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-    );``
-
- --- - - - - - -
Requires:OtherIterator is implicitly convertible to Iterator.
Effects:Constructs a filter iterator whose members are copied from t.
-

Predicate predicate() const;

- --- - - - -
Returns:m_pred
-

Iterator end() const;

- --- - - - -
Returns:m_end
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Returns:*m_iter
-

filter_iterator& operator++();

- --- - - - - - -
Effects:Increments m_iter and then continues to -increment m_iter until either m_iter == m_end -or m_pred(*m_iter) == true.
Returns:*this
-
-
-
-

Counting iterator

-

counting_iterator adapts an object by adding an operator* that -returns the current value of the object. All other iterator operations -are forwarded to the adapted object.

-
-

Class template counting_iterator

-
-template <
-    class Incrementable
-  , class CategoryOrTraversal = use_default
-  , class Difference = use_default
->
-class counting_iterator
-{
-public:
-    typedef Incrementable value_type;
-    typedef const Incrementable& reference;
-    typedef const Incrementable* pointer;
-    typedef /* see below */ difference_type;
-    typedef /* see below */ iterator_category;
-
-    counting_iterator();
-    counting_iterator(counting_iterator const& rhs);
-    explicit counting_iterator(Incrementable x);
-    Incrementable const& base() const;
-    reference operator*() const;
-    counting_iterator& operator++();
-    counting_iterator& operator--();
-private:
-    Incrementable m_inc; // exposition
-};
-
-

If the Difference argument is use_default then -difference_type is an unspecified signed integral -type. Otherwise difference_type is Difference.

-

iterator_category is determined according to the following -algorithm:

-
-if (CategoryOrTraversal is not use_default)
-    return CategoryOrTraversal
-else if (numeric_limits<Incrementable>::is_specialized)
-    return iterator-category(
-        random_access_traversal_tag, Incrementable, const Incrementable&)
-else
-    return iterator-category(
-         iterator_traversal<Incrementable>::type, 
-         Incrementable, const Incrementable&)
-
-
-
[Note: implementers are encouraged to provide an implementation of
-
operator- and a difference_type that avoids overflows in -the cases where std::numeric_limits<Incrementable>::is_specialized -is true.]
-
-
-
-

counting_iterator requirements

-

The Incrementable argument shall be Copy Constructible and Assignable.

-

If iterator_category is convertible to forward_iterator_tag -or forward_traversal_tag, the following must be well-formed:

-
-Incrementable i, j;
-++i;         // pre-increment
-i == j;      // operator equal
-
-

If iterator_category is convertible to -bidirectional_iterator_tag or bidirectional_traversal_tag, -the following expression must also be well-formed:

-
---i
-
-

If iterator_category is convertible to -random_access_iterator_tag or random_access_traversal_tag, -the following must must also be valid:

-
-counting_iterator::difference_type n;
-i += n;
-n = i - j;
-i < j;
-
-
-
-

counting_iterator models

-

Specializations of counting_iterator model Readable Lvalue -Iterator. In addition, they model the concepts corresponding to the -iterator tags to which their iterator_category is convertible. -Also, if CategoryOrTraversal is not use_default then -counting_iterator models the concept corresponding to the iterator -tag CategoryOrTraversal. Otherwise, if -numeric_limits<Incrementable>::is_specialized, then -counting_iterator models Random Access Traversal Iterator. -Otherwise, counting_iterator models the same iterator traversal -concepts modeled by Incrementable.

-

counting_iterator<X,C1,D1> is interoperable with -counting_iterator<Y,C2,D2> if and only if X is -interoperable with Y.

-
-
-

counting_iterator operations

-

In addition to the operations required by the concepts modeled by -counting_iterator, counting_iterator provides the following -operations.

-

counting_iterator();

- --- - - - - - -
Requires:Incrementable is Default Constructible.
Effects:Default construct the member m_inc.
-

counting_iterator(counting_iterator const& rhs);

- --- - - - -
Effects:Construct member m_inc from rhs.m_inc.
-

explicit counting_iterator(Incrementable x);

- --- - - - -
Effects:Construct member m_inc from x.
-

reference operator*() const;

- --- - - - -
Returns:m_inc
-

counting_iterator& operator++();

- --- - - - - - -
Effects:++m_inc
Returns:*this
-

counting_iterator& operator--();

- --- - - - - - -
Effects:--m_inc
Returns:*this
-

Incrementable const& base() const;

- --- - - - -
Returns:m_inc
-
-
-
-

Function output iterator

-

The function output iterator adaptor makes it easier to create custom -output iterators. The adaptor takes a unary function and creates a -model of Output Iterator. Each item assigned to the output iterator is -passed as an argument to the unary function. The motivation for this -iterator is that creating a conforming output iterator is non-trivial, -particularly because the proper implementation usually requires a -proxy object.

-
-

Class template function_output_iterator

-
-template <class UnaryFunction>
-class function_output_iterator {
-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());
-
-  /* see below */ operator*();
-  function_output_iterator& operator++();
-  function_output_iterator& operator++(int);
-private:
-  UnaryFunction m_f;     // exposition only
-};
-
-
-
-

function_output_iterator requirements

-

UnaryFunction must be Assignable and Copy Constructible.

-
-
-

function_output_iterator models

-

function_output_iterator is a model of the Writable and -Incrementable Iterator concepts.

-
-
-

function_output_iterator operations

-

explicit function_output_iterator(const UnaryFunction& f = UnaryFunction());

- --- - - - -
Effects:Constructs an instance of function_output_iterator -with m_f constructed from f.
-

operator*();

- --- - - - -
Returns:An object r of unspecified type such that r = t -is equivalent to m_f(t) for all t.
-

function_output_iterator& operator++();

- --- - - - -
Returns:*this
-

function_output_iterator& operator++(int);

- --- - - - -
Returns:*this
- -
-
-
-
-
- - - - diff --git a/doc/facade-and-adaptor.rst b/doc/facade-and-adaptor.rst deleted file mode 100644 index f53db72..0000000 --- a/doc/facade-and-adaptor.rst +++ /dev/null @@ -1,438 +0,0 @@ -+++++++++++++++++++++++++++++ - Iterator Facade and Adaptor -+++++++++++++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, `Zephyr Associates, Inc.`_ -:date: $Date$ - -:Number: This is a revised version of N1530_\ =03-0113, which was - accepted for Technical Report 1 by the C++ standard - committee's library working group. - -.. Version 1.9 of this ReStructuredText document corresponds to - n1530_, the paper accepted by the LWG. - -.. _n1530: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1530.html - -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Zephyr Associates, Inc.`: http://www.styleadvisor.com - -:abstract: We propose a set of class templates that help programmers - build standard-conforming iterators, both from scratch and - by adapting other iterators. - -.. contents:: Table of Contents - -============ - Motivation -============ - -Iterators play an important role in modern C++ programming. The -iterator is the central abstraction of the algorithms of the Standard -Library, allowing algorithms to be re-used in in a wide variety of -contexts. The C++ Standard Library contains a wide variety of useful -iterators. Every one of the standard containers comes with constant -and mutable iterators [#mutable]_, and also reverse versions of those -same iterators which traverse the container in the opposite direction. -The Standard also supplies ``istream_iterator`` and -``ostream_iterator`` for reading from and writing to streams, -``insert_iterator``, ``front_insert_iterator`` and -``back_insert_iterator`` for inserting elements into containers, and -``raw_storage_iterator`` for initializing raw memory [7]. - -Despite the many iterators supplied by the Standard Library, obvious -and useful iterators are missing, and creating new iterator types is -still a common task for C++ programmers. The literature documents -several of these, for example line_iterator [3] and Constant_iterator -[9]. The iterator abstraction is so powerful that we expect -programmers will always need to invent new iterator types. - -Although it is easy to create iterators that *almost* conform to the -standard, the iterator requirements contain subtleties which can make -creating an iterator which *actually* conforms quite difficult. -Further, the iterator interface is rich, containing many operators -that are technically redundant and tedious to implement. To automate -the repetitive work of constructing iterators, we propose -``iterator_facade``, an iterator base class template which provides -the rich interface of standard iterators and delegates its -implementation to member functions of the derived class. In addition -to reducing the amount of code necessary to create an iterator, the -``iterator_facade`` also provides compile-time error detection. -Iterator implementation mistakes that often go unnoticed are turned -into compile-time errors because the derived class implementation must -match the expectations of the ``iterator_facade``. - -A common pattern of iterator construction is the adaptation of one -iterator to form a new one. The functionality of an iterator is -composed of four orthogonal aspects: traversal, indirection, equality -comparison and distance measurement. Adapting an old iterator to -create a new one often saves work because one can reuse one aspect of -functionality while redefining the other. For example, the Standard -provides ``reverse_iterator``, which adapts any Bidirectional Iterator -by inverting its direction of traversal. As with plain iterators, -iterator adaptors defined outside the Standard have become commonplace -in the literature: - -* Checked iter[13] adds bounds-checking to an existing iterator. - -* The iterators of the View Template Library[14], which adapts - containers, are themselves adaptors over the underlying iterators. - -* Smart iterators [5] adapt an iterator's dereferencing behavior by - applying a function object to the object being referenced and - returning the result. - -* Custom iterators [4], in which a variety of adaptor types are enumerated. - -* Compound iterators [1], which access a slice out of a container of containers. - -* Several iterator adaptors from the MTL [12]. The MTL contains a - strided iterator, where each call to ``operator++()`` moves the - iterator ahead by some constant factor, and a scaled iterator, which - multiplies the dereferenced value by some constant. - -.. [#concept] We use the term concept to mean a set of requirements - that a type must satisfy to be used with a particular template - parameter. - -.. [#mutable] The term mutable iterator refers to iterators over objects that - can be changed by assigning to the dereferenced iterator, while - constant iterator refers to iterators over objects that cannot be - modified. - -To fulfill the need for constructing adaptors, we propose the -``iterator_adaptor`` class template. Instantiations of -``iterator_adaptor`` serve as a base classes for new iterators, -providing the default behavior of forwarding all operations to the -underlying iterator. The user can selectively replace these features -in the derived iterator class. This proposal also includes a number -of more specialized adaptors, such as the ``transform_iterator`` that -applies some user-specified function during the dereference of the -iterator. - -======================== - Impact on the Standard -======================== - -This proposal is purely an addition to the C++ standard library. -However, note that this proposal relies on the proposal for New -Iterator Concepts. - -======== - Design -======== - -Iterator Concepts -================= - -This proposal is formulated in terms of the new ``iterator concepts`` -as proposed in n1550_, since user-defined and especially adapted -iterators suffer from the well known categorization problems that are -inherent to the current iterator categories. - -.. _n1550: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/papers/2003/n1550.html - -This proposal does not strictly depend on proposal n1550_, as there -is a direct mapping between new and old categories. This proposal -could be reformulated using this mapping if n1550_ was not accepted. - -Interoperability -================ - -The question of iterator interoperability is poorly addressed in the -current standard. There are currently two defect reports that are -concerned with interoperability issues. - -Issue 179_ concerns the fact that mutable container iterator types -are only required to be convertible to the corresponding constant -iterator types, but objects of these types are not required to -interoperate in comparison or subtraction expressions. This situation -is tedious in practice and out of line with the way built in types -work. This proposal implements the proposed resolution to issue -179_, as most standard library implementations do nowadays. In other -words, if an iterator type A has an implicit or user defined -conversion to an iterator type B, the iterator types are interoperable -and the usual set of operators are available. - -Issue 280_ concerns the current lack of interoperability between -reverse iterator types. The proposed new reverse_iterator template -fixes the issues raised in 280. It provides the desired -interoperability without introducing unwanted overloads. - -.. _179: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#179 -.. _280: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#280 - - -Iterator Facade -=============== - -.. include:: iterator_facade_body.rst - -Iterator Adaptor -================ - -.. include:: iterator_adaptor_body.rst - -Specialized Adaptors -==================== - -This proposal also contains several examples of specialized adaptors -which were easily implemented using ``iterator_adaptor``: - -* ``indirect_iterator``, which iterates over iterators, pointers, - or smart pointers and applies an extra level of dereferencing. - -* A new ``reverse_iterator``, which inverts the direction of a Base - iterator's motion, while allowing adapted constant and mutable - iterators to interact in the expected ways (unlike those in most - implementations of C++98). - -* ``transform_iterator``, which applies a user-defined function object - to the underlying values when dereferenced. - -* ``projection_iterator``, which is similar to ``transform_iterator`` - except that when dereferenced it returns a reference instead of - a value. - -* ``filter_iterator``, which provides a view of an iterator range in - which some elements of the underlying range are skipped. - -.. _counting: - -* ``counting_iterator``, which adapts any incrementable type - (e.g. integers, iterators) so that incrementing/decrementing the - adapted iterator and dereferencing it produces successive values of - the Base type. - -* ``function_output_iterator``, which makes it easier to create custom - output iterators. - -Based on examples in the Boost library, users have generated many new -adaptors, among them a permutation adaptor which applies some -permutation to a random access iterator, and a strided adaptor, which -adapts a random access iterator by multiplying its unit of motion by a -constant factor. In addition, the Boost Graph Library (BGL) uses -iterator adaptors to adapt other graph libraries, such as LEDA [10] -and Stanford GraphBase [8], to the BGL interface (which requires C++ -Standard compliant iterators). - -=============== - Proposed Text -=============== - - -Header ```` synopsis [lib.iterator.helper.synopsis] -======================================================================= - - -:: - - struct use_default; - - struct iterator_core_access { /* implementation detail */ }; - - template < - class Derived - , class Value - , class CategoryOrTraversal - , class Reference = Value& - , class Difference = ptrdiff_t - > - class iterator_facade; - - template < - class Derived - , class Base - , class Value = use_default - , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class iterator_adaptor; - - template < - class Iterator - , class Value = use_default - , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class indirect_iterator; - - template - struct pointee; - - template - struct indirect_reference; - - template - class reverse_iterator; - - template < - class UnaryFunction - , class Iterator - , class Reference = use_default - , class Value = use_default - > - class transform_iterator; - - template - class filter_iterator; - - template < - class Incrementable - , class CategoryOrTraversal = use_default - , class Difference = use_default - > - class counting_iterator; - - template - class function_output_iterator; - - - -Iterator facade [lib.iterator.facade] -===================================== - -.. include:: iterator_facade_abstract.rst - -Class template ``iterator_facade`` ----------------------------------- - -.. include:: iterator_facade_ref.rst - -Iterator adaptor [lib.iterator.adaptor] -======================================= - -.. include:: iterator_adaptor_abstract.rst - -Class template ``iterator_adaptor`` ------------------------------------ - -.. include:: iterator_adaptor_ref.rst - - -Specialized adaptors [lib.iterator.special.adaptors] -==================================================== - - -The ``enable_if_convertible::type`` expression used in -this section is for exposition purposes. The converting constructors -for specialized adaptors should be only be in an overload set provided -that an object of type ``X`` is implicitly convertible to an object of -type ``Y``. -The signatures involving ``enable_if_convertible`` should behave -*as-if* ``enable_if_convertible`` were defined to be:: - - template enable_if_convertible_impl - {}; - - template <> enable_if_convertible_impl - { struct type; }; - - template - struct enable_if_convertible - : enable_if_convertible_impl::value> - {}; - -If an expression other than the default argument is used to supply -the value of a function parameter whose type is written in terms -of ``enable_if_convertible``, the program is ill-formed, no -diagnostic required. - -[*Note:* The ``enable_if_convertible`` approach uses SFINAE to -take the constructor out of the overload set when the types are not -implicitly convertible. -] - - -Indirect iterator ------------------ - -.. include:: indirect_iterator_abstract.rst - -Class template ``pointee`` -.................................... - -.. include:: pointee_ref.rst - -Class template ``indirect_reference`` -..................................... - -.. include:: indirect_reference_ref.rst - -Class template ``indirect_iterator`` -.................................... - -.. include:: indirect_iterator_ref.rst - -Reverse iterator ----------------- - -.. include:: reverse_iterator_abstract.rst - -Class template ``reverse_iterator`` -................................... - -.. include:: reverse_iterator_ref.rst - - -Transform iterator ------------------- - -.. include:: transform_iterator_abstract.rst - -Class template ``transform_iterator`` -..................................... - -.. include:: transform_iterator_ref.rst - - -Filter iterator ---------------- - -.. include:: filter_iterator_abstract.rst - - -Class template ``filter_iterator`` -.................................. - -.. include:: filter_iterator_ref.rst - - -Counting iterator ------------------ - -.. include:: counting_iterator_abstract.rst - -Class template ``counting_iterator`` -.................................... - -.. include:: counting_iterator_ref.rst - - -Function output iterator ------------------------- - -.. include:: function_output_iterator_abstract.rst - -Class template ``function_output_iterator`` -........................................... - -.. include:: function_output_iterator_ref.rst - - - - -.. LocalWords: Abrahams Siek Witt istream ostream iter MTL strided interoperate - LocalWords: CRTP metafunctions inlining lvalue JGS incrementable BGL LEDA cv - LocalWords: GraphBase struct ptrdiff UnaryFunction const int typename bool pp - LocalWords: lhs rhs SFINAE markup iff tmp OtherDerived OtherIterator DWA foo - LocalWords: dereferenceable subobject AdaptableUnaryFunction impl pre ifdef'd - LocalWords: OtherIncrementable Coplien diff --git a/doc/facade_iterator_category.rst b/doc/facade_iterator_category.rst deleted file mode 100755 index 6b60d85..0000000 --- a/doc/facade_iterator_category.rst +++ /dev/null @@ -1,53 +0,0 @@ -.. |iterator-category| replace:: *iterator-category* -.. _iterator-category: - -.. parsed-literal:: - - *iterator-category*\ (C,R,V) := - if (C is convertible to std::input_iterator_tag - || C is convertible to std::output_iterator_tag - ) - return C - - else if (C is not convertible to incrementable_traversal_tag) - *the program is ill-formed* - - else return a type X satisfying the following two constraints: - - 1. X is convertible to X1, and not to any more-derived - type, where X1 is defined by: - - if (R is a reference type - && C is convertible to forward_traversal_tag) - { - if (C is convertible to random_access_traversal_tag) - X1 = random_access_iterator_tag - else if (C is convertible to bidirectional_traversal_tag) - X1 = bidirectional_iterator_tag - else - X1 = forward_iterator_tag - } - else - { - if (C is convertible to single_pass_traversal_tag - && R is convertible to V) - X1 = input_iterator_tag - else - X1 = C - } - - 2. |category-to-traversal|_\ (X) is convertible to the most - derived traversal tag type to which X is also - convertible, and not to any more-derived traversal tag - type. - -.. |category-to-traversal| replace:: *category-to-traversal* -.. _`category-to-traversal`: new-iter-concepts.html#category-to-traversal - -[Note: the intention is to allow ``iterator_category`` to be one of -the five original category tags when convertibility to one of the -traversal tags would add no information] - -.. 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) diff --git a/doc/filter_iterator.html b/doc/filter_iterator.html deleted file mode 100644 index d1d90a7..0000000 --- a/doc/filter_iterator.html +++ /dev/null @@ -1,390 +0,0 @@ - - - - - - -Filter Iterator - - - - - - - -
-

Filter Iterator

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-01-13
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved
- --- - - - -
abstract:The filter iterator adaptor creates a view of an iterator range in -which some elements of the range are skipped. A predicate function -object controls which elements are skipped. When the predicate is -applied to an element, if it returns true then the element is -retained and if it returns false then the element is skipped -over. When skipping over elements, it is necessary for the filter -adaptor to know when to stop so as to avoid going past the end of the -underlying range. A filter iterator is therefore constructed with pair -of iterators indicating the range of elements in the unfiltered -sequence to be traversed.
- -
-

filter_iterator synopsis

- - - - -
-template <class Predicate, class Iterator>
-class filter_iterator
-{
- public:
-    typedef iterator_traits<Iterator>::value_type value_type;
-    typedef iterator_traits<Iterator>::reference reference;
-    typedef iterator_traits<Iterator>::pointer pointer;
-    typedef iterator_traits<Iterator>::difference_type difference_type;
-    typedef /* see below */ iterator_category;
-
-    filter_iterator();
-    filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());
-    filter_iterator(Iterator x, Iterator end = Iterator());
-    template<class OtherIterator>
-    filter_iterator(
-        filter_iterator<Predicate, OtherIterator> const& t
-        , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-        );
-    Predicate predicate() const;
-    Iterator end() const;
-    Iterator const& base() const;
-    reference operator*() const;
-    filter_iterator& operator++();
-private:
-    Predicate m_pred; // exposition only
-    Iterator m_iter;  // exposition only
-    Iterator m_end;   // exposition only
-};
-
-

If Iterator models Readable Lvalue Iterator and Forward Traversal -Iterator then iterator_category is convertible to -std::forward_iterator_tag. Otherwise iterator_category is -convertible to std::input_iterator_tag.

-
-
-

filter_iterator requirements

-

The Iterator argument shall meet the requirements of Readable -Iterator and Single Pass Iterator or it shall meet the requirements of -Input Iterator.

-

The Predicate argument must be Assignable, Copy Constructible, and -the expression p(x) must be valid where p is an object of type -Predicate, x is an object of type -iterator_traits<Iterator>::value_type, and where the type of -p(x) must be convertible to bool.

-
-
-

filter_iterator models

-

The concepts that filter_iterator models are dependent on which -concepts the Iterator argument models, as specified in the -following tables.

- ---- - - - - - - - - - - - - - -
If Iterator modelsthen filter_iterator models
Single Pass IteratorSingle Pass Iterator
Forward Traversal IteratorForward Traversal Iterator
- ---- - - - - - - - - - - - - - - - - -
If Iterator modelsthen filter_iterator models
Readable IteratorReadable Iterator
Writable IteratorWritable Iterator
Lvalue IteratorLvalue Iterator
- ---- - - - - - - - - - - - - - - - - -
If Iterator modelsthen filter_iterator models
Readable Iterator, Single Pass IteratorInput Iterator
Readable Lvalue Iterator, Forward Traversal IteratorForward Iterator
Writable Lvalue Iterator, Forward Traversal IteratorMutable Forward Iterator
-

filter_iterator<P1, X> is interoperable with filter_iterator<P2, Y> -if and only if X is interoperable with Y.

-
-
-

filter_iterator operations

-

In addition to those operations required by the concepts that -filter_iterator models, filter_iterator provides the following -operations.

-

filter_iterator();

- --- - - - - - -
Requires:Predicate and Iterator must be Default Constructible.
Effects:Constructs a filter_iterator whose``m_pred``, m_iter, and m_end -members are a default constructed.
-

filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());

- --- - - - -
Effects:Constructs a filter_iterator where m_iter is either -the first position in the range [x,end) such that f(*m_iter) == true -or else``m_iter == end``. The member m_pred is constructed from -f and m_end from end.
-

filter_iterator(Iterator x, Iterator end = Iterator());

- --- - - - - - -
Requires:Predicate must be Default Constructible and -Predicate is a class type (not a function pointer).
Effects:Constructs a filter_iterator where m_iter is either -the first position in the range [x,end) such that m_pred(*m_iter) == true -or else``m_iter == end``. The member m_pred is default constructed.
-
-template <class OtherIterator>
-filter_iterator(
-    filter_iterator<Predicate, OtherIterator> const& t
-    , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-    );``
-
- --- - - - - - -
Requires:OtherIterator is implicitly convertible to Iterator.
Effects:Constructs a filter iterator whose members are copied from t.
-

Predicate predicate() const;

- --- - - - -
Returns:m_pred
-

Iterator end() const;

- --- - - - -
Returns:m_end
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Returns:*m_iter
-

filter_iterator& operator++();

- --- - - - - - -
Effects:Increments m_iter and then continues to -increment m_iter until either m_iter == m_end -or m_pred(*m_iter) == true.
Returns:*this
-
-template <class Predicate, class Iterator>
-filter_iterator<Predicate,Iterator>
-make_filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());
-
- --- - - - -
Returns:filter_iterator<Predicate,Iterator>(f, x, end)
-
-template <class Predicate, class Iterator>
-filter_iterator<Predicate,Iterator>
-make_filter_iterator(Iterator x, Iterator end = Iterator());
-
- --- - - - -
Returns:filter_iterator<Predicate,Iterator>(x, end)
-
-
-

Example

-

This example uses filter_iterator and then -make_filter_iterator to output only the positive integers from an -array of integers. Then make_filter_iterator is is used to output -the integers greater than -2.

-
-struct is_positive_number {
-  bool operator()(int x) { return 0 < x; }
-};
-
-int main()
-{
-  int numbers_[] = { 0, -1, 4, -3, 5, 8, -2 };
-  const int N = sizeof(numbers_)/sizeof(int);
-
-  typedef int* base_iterator;
-  base_iterator numbers(numbers_);
-
-  // Example using filter_iterator
-  typedef boost::filter_iterator<is_positive_number, base_iterator>
-    FilterIter;
-
-  is_positive_number predicate;
-  FilterIter filter_iter_first(predicate, numbers, numbers + N);
-  FilterIter filter_iter_last(predicate, numbers + N, numbers + N);
-
-  std::copy(filter_iter_first, filter_iter_last, std::ostream_iterator<int>(std::cout, " "));
-  std::cout << std::endl;
-
-  // Example using make_filter_iterator()
-  std::copy(boost::make_filter_iterator<is_positive_number>(numbers, numbers + N),
-            boost::make_filter_iterator<is_positive_number>(numbers + N, numbers + N),
-            std::ostream_iterator<int>(std::cout, " "));
-  std::cout << std::endl;
-
-  // Another example using make_filter_iterator()
-  std::copy(
-      boost::make_filter_iterator(
-          std::bind2nd(std::greater<int>(), -2)
-        , numbers, numbers + N)
-
-    , boost::make_filter_iterator(
-          std::bind2nd(std::greater<int>(), -2)
-        , numbers + N, numbers + N)
-
-    , std::ostream_iterator<int>(std::cout, " ")
-  );
-
-  std::cout << std::endl;
-
-  return boost::exit_success;
-}
-
-

The output is:

-
-4 5 8 
-4 5 8 
-0 -1 4 5 8 
-
-

The source code for this example can be found here.

-
-
- - - - diff --git a/doc/filter_iterator.rst b/doc/filter_iterator.rst deleted file mode 100644 index ceb7adc..0000000 --- a/doc/filter_iterator.rst +++ /dev/null @@ -1,29 +0,0 @@ -+++++++++++++++++ - Filter Iterator -+++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: - - .. include:: filter_iterator_abstract.rst - -.. contents:: Table of Contents - -``filter_iterator`` synopsis -............................ - -.. include:: filter_iterator_ref.rst -.. include:: make_filter_iterator.rst - -.. include:: filter_iterator_eg.rst diff --git a/doc/filter_iterator_abstract.rst b/doc/filter_iterator_abstract.rst deleted file mode 100644 index 4695478..0000000 --- a/doc/filter_iterator_abstract.rst +++ /dev/null @@ -1,11 +0,0 @@ -The filter iterator adaptor creates a view of an iterator range in -which some elements of the range are skipped. A predicate function -object controls which elements are skipped. When the predicate is -applied to an element, if it returns ``true`` then the element is -retained and if it returns ``false`` then the element is skipped -over. When skipping over elements, it is necessary for the filter -adaptor to know when to stop so as to avoid going past the end of the -underlying range. A filter iterator is therefore constructed with pair -of iterators indicating the range of elements in the unfiltered -sequence to be traversed. - diff --git a/doc/filter_iterator_eg.rst b/doc/filter_iterator_eg.rst deleted file mode 100644 index 36448fe..0000000 --- a/doc/filter_iterator_eg.rst +++ /dev/null @@ -1,69 +0,0 @@ - -Example -....... - -This example uses ``filter_iterator`` and then -``make_filter_iterator`` to output only the positive integers from an -array of integers. Then ``make_filter_iterator`` is is used to output -the integers greater than ``-2``. - -:: - - struct is_positive_number { - bool operator()(int x) { return 0 < x; } - }; - - int main() - { - int numbers_[] = { 0, -1, 4, -3, 5, 8, -2 }; - const int N = sizeof(numbers_)/sizeof(int); - - typedef int* base_iterator; - base_iterator numbers(numbers_); - - // Example using filter_iterator - typedef boost::filter_iterator - FilterIter; - - is_positive_number predicate; - FilterIter filter_iter_first(predicate, numbers, numbers + N); - FilterIter filter_iter_last(predicate, numbers + N, numbers + N); - - std::copy(filter_iter_first, filter_iter_last, std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - // Example using make_filter_iterator() - std::copy(boost::make_filter_iterator(numbers, numbers + N), - boost::make_filter_iterator(numbers + N, numbers + N), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - // Another example using make_filter_iterator() - std::copy( - boost::make_filter_iterator( - std::bind2nd(std::greater(), -2) - , numbers, numbers + N) - - , boost::make_filter_iterator( - std::bind2nd(std::greater(), -2) - , numbers + N, numbers + N) - - , std::ostream_iterator(std::cout, " ") - ); - - std::cout << std::endl; - - return boost::exit_success; - } - - -The output is:: - - 4 5 8 - 4 5 8 - 0 -1 4 5 8 - - -The source code for this example can be found `here`__. - -__ ../example/filter_iterator_example.cpp diff --git a/doc/filter_iterator_ref.rst b/doc/filter_iterator_ref.rst deleted file mode 100644 index 80c6182..0000000 --- a/doc/filter_iterator_ref.rst +++ /dev/null @@ -1,169 +0,0 @@ -.. Copyright David Abrahams, Jeremy Siek, and Thomas Witt -.. 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) - -:: - - template - class filter_iterator - { - public: - typedef iterator_traits::value_type value_type; - typedef iterator_traits::reference reference; - typedef iterator_traits::pointer pointer; - typedef iterator_traits::difference_type difference_type; - typedef /* see below */ iterator_category; - - filter_iterator(); - filter_iterator(Predicate f, Iterator x, Iterator end = Iterator()); - filter_iterator(Iterator x, Iterator end = Iterator()); - template - filter_iterator( - filter_iterator const& t - , typename enable_if_convertible::type* = 0 // exposition - ); - Predicate predicate() const; - Iterator end() const; - Iterator const& base() const; - reference operator*() const; - filter_iterator& operator++(); - private: - Predicate m_pred; // exposition only - Iterator m_iter; // exposition only - Iterator m_end; // exposition only - }; - - -If ``Iterator`` models Readable Lvalue Iterator and Forward Traversal -Iterator then ``iterator_category`` is convertible to -``std::forward_iterator_tag``. Otherwise ``iterator_category`` is -convertible to ``std::input_iterator_tag``. - - -``filter_iterator`` requirements -................................ - -The ``Iterator`` argument shall meet the requirements of Readable -Iterator and Single Pass Iterator or it shall meet the requirements of -Input Iterator. - -The ``Predicate`` argument must be Assignable, Copy Constructible, and -the expression ``p(x)`` must be valid where ``p`` is an object of type -``Predicate``, ``x`` is an object of type -``iterator_traits::value_type``, and where the type of -``p(x)`` must be convertible to ``bool``. - - -``filter_iterator`` models -.......................... - -The concepts that ``filter_iterator`` models are dependent on which -concepts the ``Iterator`` argument models, as specified in the -following tables. - -+-----------------------------+----------------------------------------------------------+ -| If ``Iterator`` models | then ``filter_iterator`` models | -+=============================+==========================================================+ -| Single Pass Iterator | Single Pass Iterator | -+-----------------------------+----------------------------------------------------------+ -| Forward Traversal Iterator | Forward Traversal Iterator | -+-----------------------------+----------------------------------------------------------+ - -+--------------------------------+----------------------------------------------+ -| If ``Iterator`` models | then ``filter_iterator`` models | -+================================+==============================================+ -| Readable Iterator | Readable Iterator | -+--------------------------------+----------------------------------------------+ -| Writable Iterator | Writable Iterator | -+--------------------------------+----------------------------------------------+ -| Lvalue Iterator | Lvalue Iterator | -+--------------------------------+----------------------------------------------+ - -+-------------------------------------------------------+---------------------------------+ -| If ``Iterator`` models | then ``filter_iterator`` models | -+=======================================================+=================================+ -| Readable Iterator, Single Pass Iterator | Input Iterator | -+-------------------------------------------------------+---------------------------------+ -| Readable Lvalue Iterator, Forward Traversal Iterator | Forward Iterator | -+-------------------------------------------------------+---------------------------------+ -| Writable Lvalue Iterator, Forward Traversal Iterator | Mutable Forward Iterator | -+-------------------------------------------------------+---------------------------------+ - - -``filter_iterator`` is interoperable with ``filter_iterator`` -if and only if ``X`` is interoperable with ``Y``. - - -``filter_iterator`` operations -.............................. - -In addition to those operations required by the concepts that -``filter_iterator`` models, ``filter_iterator`` provides the following -operations. - - -``filter_iterator();`` - -:Requires: ``Predicate`` and ``Iterator`` must be Default Constructible. -:Effects: Constructs a ``filter_iterator`` whose``m_pred``, ``m_iter``, and ``m_end`` - members are a default constructed. - - -``filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());`` - -:Effects: Constructs a ``filter_iterator`` where ``m_iter`` is either - the first position in the range ``[x,end)`` such that ``f(*m_iter) == true`` - or else``m_iter == end``. The member ``m_pred`` is constructed from - ``f`` and ``m_end`` from ``end``. - - - -``filter_iterator(Iterator x, Iterator end = Iterator());`` - -:Requires: ``Predicate`` must be Default Constructible and - ``Predicate`` is a class type (not a function pointer). -:Effects: Constructs a ``filter_iterator`` where ``m_iter`` is either - the first position in the range ``[x,end)`` such that ``m_pred(*m_iter) == true`` - or else``m_iter == end``. The member ``m_pred`` is default constructed. - - -:: - - template - filter_iterator( - filter_iterator const& t - , typename enable_if_convertible::type* = 0 // exposition - );`` - -:Requires: ``OtherIterator`` is implicitly convertible to ``Iterator``. -:Effects: Constructs a filter iterator whose members are copied from ``t``. - - -``Predicate predicate() const;`` - -:Returns: ``m_pred`` - - -``Iterator end() const;`` - -:Returns: ``m_end`` - - -``Iterator const& base() const;`` - -:Returns: ``m_iterator`` - - - -``reference operator*() const;`` - -:Returns: ``*m_iter`` - - -``filter_iterator& operator++();`` - -:Effects: Increments ``m_iter`` and then continues to - increment ``m_iter`` until either ``m_iter == m_end`` - or ``m_pred(*m_iter) == true``. -:Returns: ``*this`` diff --git a/doc/function_output_iterator.html b/doc/function_output_iterator.html deleted file mode 100644 index dc3d12d..0000000 --- a/doc/function_output_iterator.html +++ /dev/null @@ -1,164 +0,0 @@ - - - - - - -Function Output Iterator - - - - - - - -
-

Function Output Iterator

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-01-13
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved
- --- - - - -
abstract:The function output iterator adaptor makes it easier to create custom -output iterators. The adaptor takes a unary function and creates a -model of Output Iterator. Each item assigned to the output iterator is -passed as an argument to the unary function. The motivation for this -iterator is that creating a conforming output iterator is non-trivial, -particularly because the proper implementation usually requires a -proxy object.
- -
-template <class UnaryFunction>
-class function_output_iterator {
-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());
-
-  /* see below */ operator*();
-  function_output_iterator& operator++();
-  function_output_iterator& operator++(int);
-private:
-  UnaryFunction m_f;     // exposition only
-};
-
-
-

function_output_iterator requirements

-

UnaryFunction must be Assignable and Copy Constructible.

-
-
-

function_output_iterator models

-

function_output_iterator is a model of the Writable and -Incrementable Iterator concepts.

-
-
-

function_output_iterator operations

-

explicit function_output_iterator(const UnaryFunction& f = UnaryFunction());

- --- - - - -
Effects:Constructs an instance of function_output_iterator -with m_f constructed from f.
-

operator*();

- --- - - - -
Returns:An object r of unspecified type such that r = t -is equivalent to m_f(t) for all t.
-

function_output_iterator& operator++();

- --- - - - -
Returns:*this
-

function_output_iterator& operator++(int);

- --- - - - -
Returns:*this
-
-
-

Example

-
-struct string_appender
-{
-    string_appender(std::string& s)
-        : m_str(&s)
-    {}
-
-    void operator()(const std::string& x) const
-    {
-        *m_str += x;
-    }
-
-    std::string* m_str;
-};
-
-int main(int, char*[])
-{
-  std::vector<std::string> x;
-  x.push_back("hello");
-  x.push_back(" ");
-  x.push_back("world");
-  x.push_back("!");
-
-  std::string s = "";
-  std::copy(x.begin(), x.end(), 
-            boost::make_function_output_iterator(string_appender(s)));
-
-  std::cout << s << std::endl;
-
-  return 0;
-}
-
-
-
- - diff --git a/doc/function_output_iterator.rst b/doc/function_output_iterator.rst deleted file mode 100644 index 01ac022..0000000 --- a/doc/function_output_iterator.rst +++ /dev/null @@ -1,24 +0,0 @@ -++++++++++++++++++++++++++ - Function Output Iterator -++++++++++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: - - .. include:: function_output_iterator_abstract.rst - -.. contents:: Table of Contents - -.. include:: function_output_iterator_ref.rst -.. include:: function_output_iterator_eg.rst \ No newline at end of file diff --git a/doc/function_output_iterator_abstract.rst b/doc/function_output_iterator_abstract.rst deleted file mode 100644 index 11fb4f1..0000000 --- a/doc/function_output_iterator_abstract.rst +++ /dev/null @@ -1,8 +0,0 @@ -The function output iterator adaptor makes it easier to create custom -output iterators. The adaptor takes a unary function and creates a -model of Output Iterator. Each item assigned to the output iterator is -passed as an argument to the unary function. The motivation for this -iterator is that creating a conforming output iterator is non-trivial, -particularly because the proper implementation usually requires a -proxy object. - diff --git a/doc/function_output_iterator_eg.rst b/doc/function_output_iterator_eg.rst deleted file mode 100644 index eb635df..0000000 --- a/doc/function_output_iterator_eg.rst +++ /dev/null @@ -1,35 +0,0 @@ -Example -....... - -:: - - struct string_appender - { - string_appender(std::string& s) - : m_str(&s) - {} - - void operator()(const std::string& x) const - { - *m_str += x; - } - - std::string* m_str; - }; - - int main(int, char*[]) - { - std::vector x; - x.push_back("hello"); - x.push_back(" "); - x.push_back("world"); - x.push_back("!"); - - std::string s = ""; - std::copy(x.begin(), x.end(), - boost::make_function_output_iterator(string_appender(s))); - - std::cout << s << std::endl; - - return 0; - } diff --git a/doc/function_output_iterator_ref.rst b/doc/function_output_iterator_ref.rst deleted file mode 100644 index b346b0d..0000000 --- a/doc/function_output_iterator_ref.rst +++ /dev/null @@ -1,60 +0,0 @@ -:: - - template - class function_output_iterator { - 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()); - - /* see below */ operator*(); - function_output_iterator& operator++(); - function_output_iterator& operator++(int); - private: - UnaryFunction m_f; // exposition only - }; - - - -``function_output_iterator`` requirements -......................................... - -``UnaryFunction`` must be Assignable and Copy Constructible. - - - -``function_output_iterator`` models -................................... - -``function_output_iterator`` is a model of the Writable and -Incrementable Iterator concepts. - - - -``function_output_iterator`` operations -....................................... - -``explicit function_output_iterator(const UnaryFunction& f = UnaryFunction());`` - -:Effects: Constructs an instance of ``function_output_iterator`` - with ``m_f`` constructed from ``f``. - - -``operator*();`` - -:Returns: An object ``r`` of unspecified type such that ``r = t`` - is equivalent to ``m_f(t)`` for all ``t``. - - -``function_output_iterator& operator++();`` - -:Returns: ``*this`` - - -``function_output_iterator& operator++(int);`` - -:Returns: ``*this`` diff --git a/doc/generate.py b/doc/generate.py deleted file mode 100644 index a6d3f31..0000000 --- a/doc/generate.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/python - -# -# Generate html, TeX, and PDF versions of all the source files -# -import os -import sys - -from syscmd import syscmd -from sources import sources - -if 0: - for s in sources: - syscmd('boosthtml %s' % s) -else: - extensions = ('html', 'tex', 'pdf') - - if len(sys.argv) > 1: - extensions = sys.argv[1:] - - all = [ '%s.%s' % (os.path.splitext(s)[0],ext) - for ext in extensions - for s in sources - ] - - print 'make -k %s' % ' '.join(all) - syscmd('make -k %s' % ' '.join(all)) - - diff --git a/doc/index.html b/doc/index.html deleted file mode 100755 index 9cd1609..0000000 --- a/doc/index.html +++ /dev/null @@ -1,236 +0,0 @@ - - - - - - -The Boost.Iterator Library Boost - - - - - - - - diff --git a/doc/index.rst b/doc/index.rst deleted file mode 100755 index 9ff1508..0000000 --- a/doc/index.rst +++ /dev/null @@ -1,286 +0,0 @@ -+++++++++++++++++++++++++++++++++++++++++++++++++ - The Boost.Iterator Library |(logo)|__ -+++++++++++++++++++++++++++++++++++++++++++++++++ - -.. |(logo)| image:: ../../../c++boost.gif - :alt: Boost - -__ ../../../index.htm - - -------------------------------------- - - -:Authors: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com -:organizations: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, `Zephyr Associates, Inc.`_ -:date: $Date$ - -:copyright: Copyright David Abrahams, Jeremy Siek, Thomas Witt 2003. All rights reserved - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Zephyr Associates, Inc.`: http://www.styleadvisor.com - -:Abstract: The Boost Iterator Library contains two parts. The first - is a system of concepts_ which extend the C++ standard - iterator requirements. The second is a framework of - components for building iterators based on these - extended concepts and includes several useful iterator - adaptors. The extended iterator concepts have been - carefully designed so that so that old-style iterators - can fit in the new concepts and so that new-style - iterators will be compatible with old-style algorithms, - though algorithms may need to be updated if they want to - take full advantage of the new-style iterator - capabilities. Several components of this library have - been accepted into the C++ standard technical report. - The components of the Boost Iterator Library replace the - older Boost Iterator Adaptor Library. - -.. _concepts: ../../../more/generic_programming.html#concept - -.. contents:: **Table of Contents** - - -------------------------------------- - - -===================== - New-Style Iterators -===================== - -The iterator categories defined in C++98 are extremely limiting -because they bind together two orthogonal concepts: traversal and -element access. For example, because a random access iterator is -required to return a reference (and not a proxy) when dereferenced, -it is impossible to capture the capabilities of -``vector::iterator`` using the C++98 categories. This is the -infamous "``vector`` is not a container, and its iterators -aren't random access iterators", debacle about which Herb Sutter -wrote two papers for the standards comittee (n1185_ and n1211_), -and a `Guru of the Week`__. New-style iterators go well beyond -patching up ``vector``, though: there are lots of other -iterators already in use which can't be adequately represented by -the existing concepts. For details about the new iterator -concepts, see our - -.. _n1185: http://www.gotw.ca/publications/N1185.pdf -.. _n1211: http://www.gotw.ca/publications/N1211.pdf -__ http://www.gotw.ca/gotw/050.htm - - - `Standard Proposal For New-Style Iterators`__ - -__ new-iter-concepts.html - -============================= - Iterator Facade and Adaptor -============================= - -Writing standard-conforming iterators is tricky, but the need comes -up often. In order to ease the implementation of new iterators, -the Boost.Iterator library provides the |facade| class template, -which implements many useful defaults and compile-time checks -designed to help the iterator author ensure that his iterator is -correct. - -It is also common to define a new iterator that is similar to some -underlying iterator or iterator-like type, but that modifies some -aspect of the underlying type's behavior. For that purpose, the -library supplies the |adaptor| class template, which is specially -designed to take advantage of as much of the underlying type's -behavior as possible. - -The documentation for these two classes can be found at the following -web pages: - -* |facade|_ - -* |adaptor|_ - - -.. |facade| replace:: ``iterator_facade`` -.. _facade: iterator_facade.html -.. |adaptor| replace:: ``iterator_adaptor`` -.. _adaptor: iterator_adaptor.html - -Both |facade| and |adaptor| as well as many of the `specialized -adaptors`_ mentioned below have been proposed for standardization, -and accepted into the first C++ technical report; see our - - `Standard Proposal For Iterator Facade and Adaptor`__ - -for more details. - -__ facade-and-adaptor.html - -====================== - Specialized Adaptors -====================== - -The iterator library supplies a useful suite of standard-conforming -iterator templates based on the Boost `iterator facade and adaptor`_. - -* |counting|_: an iterator over a sequence of consecutive values. - Implements a "lazy sequence" - -* |filter|_: an iterator over the subset of elements of some - sequence which satisfy a given predicate - -* |indirect|_: an iterator over the objects *pointed-to* by the - elements of some sequence. - -* |permutation|_: an iterator over the elements of some random-access - sequence, rearranged according to some sequence of integer indices. - -* |reverse|_: an iterator which traverses the elements of some - bidirectional sequence in reverse. Corrects many of the - shortcomings of C++98's ``std::reverse_iterator``. - -* |transform|_: an iterator over elements which are the result of - applying some functional transformation to the elements of an - underlying sequence. This component also replaces the old - ``projection_iterator_adaptor``. - -* |zip|_: an iterator over tuples of the elements at corresponding - positions of heterogeneous underlying iterators. - -.. |counting| replace:: ``counting_iterator`` -.. _counting: counting_iterator.html - -.. |filter| replace:: ``filter_iterator`` -.. _filter: filter_iterator.html - -.. |indirect| replace:: ``indirect_iterator`` -.. _indirect: indirect_iterator.html - -.. |permutation| replace:: ``permutation_iterator`` -.. _permutation: permutation_iterator.html - -.. |reverse| replace:: ``reverse_iterator`` -.. _reverse: reverse_iterator.html - -.. |transform| replace:: ``transform_iterator`` -.. _transform: transform_iterator.html - -.. |zip| replace:: ``zip_iterator`` -.. _zip: zip_iterator.html - -==================== - Iterator Utilities -==================== - -Traits ------- - -* |pointee|_: Provides the capability to deduce the referent types - of pointers, smart pointers and iterators in generic code. Used - in |indirect|. - -* |iterator_traits|_: Provides MPL_\ -compatible metafunctions which - retrieve an iterator's traits. Also corrects for the deficiencies - of broken implementations of ``std::iterator_traits``. - -* |interoperable|_: Provides an MPL_\ -compatible metafunction for - testing iterator interoperability - -.. |pointee| replace:: ``pointee.hpp`` -.. _pointee: pointee.html - -.. |iterator_traits| replace:: ``iterator_traits.hpp`` -.. _iterator_traits: iterator_traits.html - -.. |interoperable| replace:: ``interoperable.hpp`` -.. _interoperable: interoperable.html - -.. _MPL: ../../mpl/doc/index.html - -Testing and Concept Checking ----------------------------- - -* |iterator_concepts|_: Concept checking classes for the new iterator concepts. - -* |iterator_archetypes|_: Concept archetype classes for the new iterators concepts. - -.. |iterator_concepts| replace:: ``iterator_concepts.hpp`` -.. _iterator_concepts: iterator_concepts.html - -.. |iterator_archetypes| replace:: ``iterator_archetypes.hpp`` -.. _iterator_archetypes: iterator_archetypes.html - - -======================================================= - Upgrading from the old Boost Iterator Adaptor Library -======================================================= - -.. _Upgrading: - -If you have been using the old Boost Iterator Adaptor library to -implement iterators, you probably wrote a ``Policies`` class which -captures the core operations of your iterator. In the new library -design, you'll move those same core operations into the body of the -iterator class itself. If you were writing a family of iterators, -you probably wrote a `type generator`_ to build the -``iterator_adaptor`` specialization you needed; in the new library -design you don't need a type generator (though may want to keep it -around as a compatibility aid for older code) because, due to the -use of the Curiously Recurring Template Pattern (CRTP) [Cop95]_, -you can now define the iterator class yourself and acquire -functionality through inheritance from ``iterator_facade`` or -``iterator_adaptor``. As a result, you also get much finer control -over how your iterator works: you can add additional constructors, -or even override the iterator functionality provided by the -library. - -.. _`type generator`: ../../../more/generic_programming.html#type_generator - -If you're looking for the old ``projection_iterator`` component, -its functionality has been merged into ``transform_iterator``: as -long as the function object's ``result_type`` (or the ``Reference`` -template argument, if explicitly specified) is a true reference -type, ``transform_iterator`` will behave like -``projection_iterator`` used to. - -========= - History -========= - -In 2000 Dave Abrahams was writing an iterator for a container of -pointers, which would access the pointed-to elements when -dereferenced. Naturally, being a library writer, he decided to -generalize the idea and the Boost Iterator Adaptor library was born. -Dave was inspired by some writings of Andrei Alexandrescu and chose a -policy based design (though he probably didn't capture Andrei's idea -very well - there was only one policy class for all the iterator's -orthogonal properties). Soon Jeremy Siek realized he would need the -library and they worked together to produce a "Boostified" version, -which was reviewed and accepted into the library. They wrote a paper -and made several important revisions of the code. - -Eventually, several shortcomings of the older library began to make -the need for a rewrite apparent. Dave and Jeremy started working -at the Santa Cruz C++ committee meeting in 2002, and had quickly -generated a working prototype. At the urging of Mat Marcus, they -decided to use the GenVoca/CRTP pattern approach, and moved the -policies into the iterator class itself. Thomas Witt expressed -interest and became the voice of strict compile-time checking for -the project, adding uses of the SFINAE technique to eliminate false -converting constructors and operators from the overload set. He -also recognized the need for a separate ``iterator_facade``, and -factored it out of ``iterator_adaptor``. Finally, after a -near-complete rewrite of the prototype, they came up with the -library you see today. - -.. [Cop95] [Coplien, 1995] Coplien, J., Curiously Recurring Template - Patterns, C++ Report, February 1995, pp. 24-27. - -.. - LocalWords: Abrahams Siek Witt const bool Sutter's WG int UL LI href Lvalue - LocalWords: ReadableIterator WritableIterator SwappableIterator cv pre iter - LocalWords: ConstantLvalueIterator MutableLvalueIterator CopyConstructible TR - LocalWords: ForwardTraversalIterator BidirectionalTraversalIterator lvalue - LocalWords: RandomAccessTraversalIterator dereferenceable Incrementable tmp - LocalWords: incrementable xxx min prev inplace png oldeqnew AccessTag struct - LocalWords: TraversalTag typename lvalues DWA Hmm JGS diff --git a/doc/indirect_iterator.html b/doc/indirect_iterator.html deleted file mode 100644 index c1fe764..0000000 --- a/doc/indirect_iterator.html +++ /dev/null @@ -1,332 +0,0 @@ - - - - - - -Indirect Iterator - - - - - - - -
-

Indirect Iterator

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-01-15
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved
- --- - - - -
abstract:indirect_iterator adapts an iterator by applying an -extra dereference inside of operator*(). For example, this -iterator adaptor makes it possible to view a container of pointers -(e.g. list<foo*>) as if it were a container of the pointed-to type -(e.g. list<foo>). indirect_iterator depends on two -auxiliary traits, pointee and indirect_reference, to -provide support for underlying iterators whose value_type is -not an iterator.
- -
-

indirect_iterator synopsis

-
-template <
-    class Iterator
-  , class Value = use_default
-  , class CategoryOrTraversal = use_default
-  , class Reference = use_default
-  , class Difference = use_default
->
-class indirect_iterator
-{
- public:
-    typedef /* see below */ value_type;
-    typedef /* see below */ reference;
-    typedef /* see below */ pointer;
-    typedef /* see below */ difference_type;
-    typedef /* see below */ iterator_category;
-
-    indirect_iterator();
-    indirect_iterator(Iterator x);
-
-    template <
-        class Iterator2, class Value2, class Category2
-      , class Reference2, class Difference2
-    >
-    indirect_iterator(
-        indirect_iterator<
-             Iterator2, Value2, Category2, Reference2, Difference2
-        > const& y
-      , typename enable_if_convertible<Iterator2, Iterator>::type* = 0 // exposition
-    );
-
-    Iterator const& base() const;
-    reference operator*() const;
-    indirect_iterator& operator++();
-    indirect_iterator& operator--();
-private:
-   Iterator m_iterator; // exposition
-};
-
-

The member types of indirect_iterator are defined according to -the following pseudo-code, where V is -iterator_traits<Iterator>::value_type

-
-if (Value is use_default) then
-    typedef remove_const<pointee<V>::type>::type value_type;
-else
-    typedef remove_const<Value>::type value_type;
-
-if (Reference is use_default) then
-    if (Value is use_default) then
-        typedef indirect_reference<V>::type reference;
-    else
-        typedef Value& reference;
-else
-    typedef Reference reference;
-
-if (Value is use_default) then 
-    typedef pointee<V>::type* pointer;
-else 
-    typedef Value* pointer;
-
-if (Difference is use_default)
-    typedef iterator_traits<Iterator>::difference_type difference_type;
-else
-    typedef Difference difference_type;
-
-if (CategoryOrTraversal is use_default)
-    typedef iterator-category (
-        iterator_traversal<Iterator>::type,``reference``,``value_type``
-    ) iterator_category;
-else
-    typedef iterator-category (
-        CategoryOrTraversal,``reference``,``value_type``
-    ) iterator_category;
-
-
-
-

indirect_iterator requirements

-

The expression *v, where v is an object of -iterator_traits<Iterator>::value_type, shall be valid -expression and convertible to reference. Iterator shall -model the traversal concept indicated by iterator_category. -Value, Reference, and Difference shall be chosen so -that value_type, reference, and difference_type meet -the requirements indicated by iterator_category.

-

[Note: there are further requirements on the -iterator_traits<Iterator>::value_type if the Value -parameter is not use_default, as implied by the algorithm for -deducing the default for the value_type member.]

-
-
-

indirect_iterator models

-

In addition to the concepts indicated by iterator_category -and by iterator_traversal<indirect_iterator>::type, a -specialization of indirect_iterator models the following -concepts, Where v is an object of -iterator_traits<Iterator>::value_type:

-
-
    -
  • Readable Iterator if reference(*v) is convertible to -value_type.
  • -
  • Writable Iterator if reference(*v) = t is a valid -expression (where t is an object of type -indirect_iterator::value_type)
  • -
  • Lvalue Iterator if reference is a reference type.
  • -
-
-

indirect_iterator<X,V1,C1,R1,D1> is interoperable with -indirect_iterator<Y,V2,C2,R2,D2> if and only if X is -interoperable with Y.

-
-
-

indirect_iterator operations

-

In addition to the operations required by the concepts described -above, specializations of indirect_iterator provide the -following operations.

-

indirect_iterator();

- --- - - - - - -
Requires:Iterator must be Default Constructible.
Effects:Constructs an instance of indirect_iterator with -a default-constructed m_iterator.
-

indirect_iterator(Iterator x);

- --- - - - -
Effects:Constructs an instance of indirect_iterator with -m_iterator copy constructed from x.
-
-template <
-    class Iterator2, class Value2, unsigned Access, class Traversal
-  , class Reference2, class Difference2
->
-indirect_iterator(
-    indirect_iterator<
-         Iterator2, Value2, Access, Traversal, Reference2, Difference2
-    > const& y
-  , typename enable_if_convertible<Iterator2, Iterator>::type* = 0 // exposition
-);
-
- --- - - - - - -
Requires:Iterator2 is implicitly convertible to Iterator.
Effects:Constructs an instance of indirect_iterator whose -m_iterator subobject is constructed from y.base().
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Returns:**m_iterator
-

indirect_iterator& operator++();

- --- - - - - - -
Effects:++m_iterator
Returns:*this
-

indirect_iterator& operator--();

- --- - - - - - -
Effects:--m_iterator
Returns:*this
-
-
-

Example

-

This example prints an array of characters, using -indirect_iterator to access the array of characters through an -array of pointers. Next indirect_iterator is used with the -transform algorithm to copy the characters (incremented by one) to -another array. A constant indirect iterator is used for the source and -a mutable indirect iterator is used for the destination. The last part -of the example prints the original array of characters, but this time -using the make_indirect_iterator helper function.

-
-char characters[] = "abcdefg";
-const int N = sizeof(characters)/sizeof(char) - 1; // -1 since characters has a null char
-char* pointers_to_chars[N];                        // at the end.
-for (int i = 0; i < N; ++i)
-  pointers_to_chars[i] = &characters[i];
-
-// Example of using indirect_iterator
-
-boost::indirect_iterator<char**, char>
-  indirect_first(pointers_to_chars), indirect_last(pointers_to_chars + N);
-
-std::copy(indirect_first, indirect_last, std::ostream_iterator<char>(std::cout, ","));
-std::cout << std::endl;
-
-
-// Example of making mutable and constant indirect iterators
-
-char mutable_characters[N];
-char* pointers_to_mutable_chars[N];
-for (int j = 0; j < N; ++j)
-  pointers_to_mutable_chars[j] = &mutable_characters[j];
-
-boost::indirect_iterator<char* const*> mutable_indirect_first(pointers_to_mutable_chars),
-  mutable_indirect_last(pointers_to_mutable_chars + N);
-boost::indirect_iterator<char* const*, char const> const_indirect_first(pointers_to_chars),
-  const_indirect_last(pointers_to_chars + N);
-
-std::transform(const_indirect_first, const_indirect_last,
-               mutable_indirect_first, std::bind1st(std::plus<char>(), 1));
-
-std::copy(mutable_indirect_first, mutable_indirect_last,
-          std::ostream_iterator<char>(std::cout, ","));
-std::cout << std::endl;
-
-
-// Example of using make_indirect_iterator()
-
-std::copy(boost::make_indirect_iterator(pointers_to_chars), 
-          boost::make_indirect_iterator(pointers_to_chars + N),
-          std::ostream_iterator<char>(std::cout, ","));
-std::cout << std::endl;
-
-

The output is:

-
-a,b,c,d,e,f,g,
-b,c,d,e,f,g,h,
-a,b,c,d,e,f,g,
-
-

The source code for this example can be found here.

-
-
- - - - diff --git a/doc/indirect_iterator.rst b/doc/indirect_iterator.rst deleted file mode 100644 index ad3778d..0000000 --- a/doc/indirect_iterator.rst +++ /dev/null @@ -1,30 +0,0 @@ -+++++++++++++++++++ - Indirect Iterator -+++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: - - .. include:: indirect_iterator_abstract.rst - -.. contents:: Table of Contents - -``indirect_iterator`` synopsis -.............................. - -.. include:: indirect_iterator_ref.rst -.. include:: indirect_iterator_eg.rst - -.. _iterator-category: iterator_facade.html#iterator-category -.. |iterator-category| replace:: *iterator-category* diff --git a/doc/indirect_iterator_abstract.rst b/doc/indirect_iterator_abstract.rst deleted file mode 100644 index 448b734..0000000 --- a/doc/indirect_iterator_abstract.rst +++ /dev/null @@ -1,11 +0,0 @@ -``indirect_iterator`` adapts an iterator by applying an -*extra* dereference inside of ``operator*()``. For example, this -iterator adaptor makes it possible to view a container of pointers -(e.g. ``list``) as if it were a container of the pointed-to type -(e.g. ``list``). ``indirect_iterator`` depends on two -auxiliary traits, ``pointee`` and ``indirect_reference``, to -provide support for underlying iterators whose ``value_type`` is -not an iterator. - - - diff --git a/doc/indirect_iterator_eg.rst b/doc/indirect_iterator_eg.rst deleted file mode 100644 index 356a2dd..0000000 --- a/doc/indirect_iterator_eg.rst +++ /dev/null @@ -1,69 +0,0 @@ -Example -....... - -This example prints an array of characters, using -``indirect_iterator`` to access the array of characters through an -array of pointers. Next ``indirect_iterator`` is used with the -``transform`` algorithm to copy the characters (incremented by one) to -another array. A constant indirect iterator is used for the source and -a mutable indirect iterator is used for the destination. The last part -of the example prints the original array of characters, but this time -using the ``make_indirect_iterator`` helper function. - - -:: - - char characters[] = "abcdefg"; - const int N = sizeof(characters)/sizeof(char) - 1; // -1 since characters has a null char - char* pointers_to_chars[N]; // at the end. - for (int i = 0; i < N; ++i) - pointers_to_chars[i] = &characters[i]; - - // Example of using indirect_iterator - - boost::indirect_iterator - indirect_first(pointers_to_chars), indirect_last(pointers_to_chars + N); - - std::copy(indirect_first, indirect_last, std::ostream_iterator(std::cout, ",")); - std::cout << std::endl; - - - // Example of making mutable and constant indirect iterators - - char mutable_characters[N]; - char* pointers_to_mutable_chars[N]; - for (int j = 0; j < N; ++j) - pointers_to_mutable_chars[j] = &mutable_characters[j]; - - boost::indirect_iterator mutable_indirect_first(pointers_to_mutable_chars), - mutable_indirect_last(pointers_to_mutable_chars + N); - boost::indirect_iterator const_indirect_first(pointers_to_chars), - const_indirect_last(pointers_to_chars + N); - - std::transform(const_indirect_first, const_indirect_last, - mutable_indirect_first, std::bind1st(std::plus(), 1)); - - std::copy(mutable_indirect_first, mutable_indirect_last, - std::ostream_iterator(std::cout, ",")); - std::cout << std::endl; - - - // Example of using make_indirect_iterator() - - std::copy(boost::make_indirect_iterator(pointers_to_chars), - boost::make_indirect_iterator(pointers_to_chars + N), - std::ostream_iterator(std::cout, ",")); - std::cout << std::endl; - - -The output is:: - - a,b,c,d,e,f,g, - b,c,d,e,f,g,h, - a,b,c,d,e,f,g, - - -The source code for this example can be found `here`__. - -__ ../example/indirect_iterator_example.cpp - diff --git a/doc/indirect_iterator_ref.diff b/doc/indirect_iterator_ref.diff deleted file mode 100644 index 0c1bf5c..0000000 --- a/doc/indirect_iterator_ref.diff +++ /dev/null @@ -1,245 +0,0 @@ -Index: indirect_iterator_ref.rst -=================================================================== -RCS file: /cvsroot/boost/boost/libs/iterator/doc/indirect_iterator_ref.rst,v -retrieving revision 1.2 -retrieving revision 1.21 -diff -w -d -u -b -r1.2 -r1.21 ---- indirect_iterator_ref.rst 22 Sep 2003 19:55:00 -0000 1.2 -+++ indirect_iterator_ref.rst 15 Jan 2004 00:01:33 -0000 1.21 - - - -@@ -3,82 +3,139 @@ - template < - class Iterator - , class Value = use_default - -Issue 9.15 - -- , unsigned Access = use_default_access -- , class Traversal = use_default -+ , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class indirect_iterator - -Issue 9.37x - -- : public iterator_adaptor - { -- friend class iterator_core_access; - public: -+ typedef /* see below */ value_type; -+ typedef /* see below */ reference; -+ typedef /* see below */ pointer; -+ typedef /* see below */ difference_type; -+ typedef /* see below */ iterator_category; -+ - indirect_iterator(); - indirect_iterator(Iterator x); -+ - -Issue 9.15 - - template < -- class Iterator2, class Value2, unsigned Access2, class Traversal2 -+ class Iterator2, class Value2, class Category2 - , class Reference2, class Difference2 - > - indirect_iterator( - indirect_iterator< -- Iterator2, Value2, Access2, Traversal2, Reference2, Difference2 -+ Iterator2, Value2, Category2, Reference2, Difference2 - > const& y - , typename enable_if_convertible::type* = 0 // exposition - ); - -Issue 9.37x - -- private: // as-if specification -- typename indirect_iterator::reference dereference() const -- { -- return **this->base(); -- } -+ -+ Iterator const& base() const; -+ reference operator*() const; -+ indirect_iterator& operator++(); -+ indirect_iterator& operator--(); -+ private: -+ Iterator m_iterator; // exposition - }; - -+ -+The member types of ``indirect_iterator`` are defined according to -+the following pseudo-code, where ``V`` is -+``iterator_traits::value_type`` -+ -+.. parsed-literal:: -+ -+ if (Value is use_default) then -+ typedef remove_const::type>::type value_type; -+ else -+ typedef remove_const::type value_type; -+ -+ if (Reference is use_default) then -+ if (Value is use_default) then -+ typedef indirect_reference::type reference; -+ else -+ typedef Value& reference; -+ else -+ typedef Reference reference; -+ -+ if (Value is use_default) then -+ typedef pointee::type\* pointer; -+ else -+ typedef Value\* pointer; -+ -+ if (Difference is use_default) -+ typedef iterator_traits::difference_type difference_type; -+ else -+ typedef Difference difference_type; -+ -+ if (CategoryOrTraversal is use_default) -+ typedef |iterator-category|_\ ( -+ iterator_traversal::type,``reference``,``value_type`` -+ ) iterator_category; -+ else -+ typedef |iterator-category|_\ ( -+ CategoryOrTraversal,``reference``,``value_type`` -+ ) iterator_category; -+ -+ - - ``indirect_iterator`` requirements - .................................. - -Issue 9.40x - --The ``value_type`` of the ``Iterator`` template parameter should --itself be dereferenceable. The return type of the ``operator*`` for --the ``value_type`` must be the same type as the ``Reference`` template --parameter. The ``Value`` template parameter will be the ``value_type`` --for the ``indirect_iterator``, unless ``Value`` is const. If ``Value`` --is ``const X``, then ``value_type`` will be *non-* ``const X``. The --default for ``Value`` is -+The expression ``*v``, where ``v`` is an object of -+``iterator_traits::value_type``, shall be valid -+expression and convertible to ``reference``. ``Iterator`` shall -+model the traversal concept indicated by ``iterator_category``. -+``Value``, ``Reference``, and ``Difference`` shall be chosen so -+that ``value_type``, ``reference``, and ``difference_type`` meet -+the requirements indicated by ``iterator_category``. - --:: -+[Note: there are further requirements on the -+``iterator_traits::value_type`` if the ``Value`` -+parameter is not ``use_default``, as implied by the algorithm for -+deducing the default for the ``value_type`` member.] - -- iterator_traits< iterator_traits::value_type >::value_type - -Issue 9.37x - -+``indirect_iterator`` models -+............................ - --If the default is used for ``Value``, then there must be a valid --specialization of ``iterator_traits`` for the value type of the base --iterator. -+In addition to the concepts indicated by ``iterator_category`` -+and by ``iterator_traversal::type``, a -+specialization of ``indirect_iterator`` models the following -+concepts, Where ``v`` is an object of -+``iterator_traits::value_type``: - --The ``Reference`` parameter will be the ``reference`` type of the --``indirect_iterator``. The default is ``Value&``. -+ * Readable Iterator if ``reference(*v)`` is convertible to -+ ``value_type``. - --The ``Access`` and ``Traversal`` parameters are passed unchanged to --the corresponding parameters of the ``iterator_adaptor`` base --class, and the ``Iterator`` parameter is passed unchanged as the --``Base`` parameter to the ``iterator_adaptor`` base class. -+ * Writable Iterator if ``reference(*v) = t`` is a valid -+ expression (where ``t`` is an object of type -+ ``indirect_iterator::value_type``) - --The indirect iterator will model the most refined standard traversal --concept that is modeled by the ``Iterator`` type. The indirect --iterator will model the most refined standard access concept that is --modeled by the value type of ``Iterator``. -+ * Lvalue Iterator if ``reference`` is a reference type. -+ -+``indirect_iterator`` is interoperable with -+``indirect_iterator`` if and only if ``X`` is -+interoperable with ``Y``. - - - ``indirect_iterator`` operations - ................................ - -Issue 9.37x - -+In addition to the operations required by the concepts described -+above, specializations of ``indirect_iterator`` provide the -+following operations. -+ -+ - -Issue 9.28 and 9.37x - - ``indirect_iterator();`` - - :Requires: ``Iterator`` must be Default Constructible. - :Returns: An instance of ``indirect_iterator`` with -- a default constructed base object. -+ a default-constructed ``m_iterator``. - - -Issue 9.37x - - ``indirect_iterator(Iterator x);`` - - :Returns: An instance of ``indirect_iterator`` with -- the ``iterator_adaptor`` subobject copy constructed from ``x``. -+ ``m_iterator`` copy constructed from ``x``. - - :: - - -Issue 9.29 - -@@ -94,5 +151,27 @@ - ); - - :Requires: ``Iterator2`` is implicitly convertible to ``Iterator``. --:Returns: An instance of ``indirect_iterator`` that is a copy of ``y``. -+:Returns: An instance of ``indirect_iterator`` whose -+ ``m_iterator`` subobject is constructed from ``y.base()``. -+ - -Issue 9.37x - -+``Iterator const& base() const;`` - -+:Returns: ``m_iterator`` -+ -+ -+``reference operator*() const;`` -+ -+:Returns: ``**m_iterator`` -+ -+ -+``indirect_iterator& operator++();`` -+ -+:Effects: ``++m_iterator`` -+:Returns: ``*this`` -+ -+ -+``indirect_iterator& operator--();`` -+ -+:Effects: ``--m_iterator`` -+:Returns: ``*this`` diff --git a/doc/indirect_iterator_ref.rst b/doc/indirect_iterator_ref.rst deleted file mode 100644 index 1065659..0000000 --- a/doc/indirect_iterator_ref.rst +++ /dev/null @@ -1,177 +0,0 @@ -:: - - template < - class Iterator - , class Value = use_default - , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class indirect_iterator - { - public: - typedef /* see below */ value_type; - typedef /* see below */ reference; - typedef /* see below */ pointer; - typedef /* see below */ difference_type; - typedef /* see below */ iterator_category; - - indirect_iterator(); - indirect_iterator(Iterator x); - - template < - class Iterator2, class Value2, class Category2 - , class Reference2, class Difference2 - > - indirect_iterator( - indirect_iterator< - Iterator2, Value2, Category2, Reference2, Difference2 - > const& y - , typename enable_if_convertible::type* = 0 // exposition - ); - - Iterator const& base() const; - reference operator*() const; - indirect_iterator& operator++(); - indirect_iterator& operator--(); - private: - Iterator m_iterator; // exposition - }; - - -The member types of ``indirect_iterator`` are defined according to -the following pseudo-code, where ``V`` is -``iterator_traits::value_type`` - -.. parsed-literal:: - - if (Value is use_default) then - typedef remove_const::type>::type value_type; - else - typedef remove_const::type value_type; - - if (Reference is use_default) then - if (Value is use_default) then - typedef indirect_reference::type reference; - else - typedef Value& reference; - else - typedef Reference reference; - - if (Value is use_default) then - typedef pointee::type\* pointer; - else - typedef Value\* pointer; - - if (Difference is use_default) - typedef iterator_traits::difference_type difference_type; - else - typedef Difference difference_type; - - if (CategoryOrTraversal is use_default) - typedef *iterator-category* ( - iterator_traversal::type,``reference``,``value_type`` - ) iterator_category; - else - typedef *iterator-category* ( - CategoryOrTraversal,``reference``,``value_type`` - ) iterator_category; - - -``indirect_iterator`` requirements -.................................. - -The expression ``*v``, where ``v`` is an object of -``iterator_traits::value_type``, shall be valid -expression and convertible to ``reference``. ``Iterator`` shall -model the traversal concept indicated by ``iterator_category``. -``Value``, ``Reference``, and ``Difference`` shall be chosen so -that ``value_type``, ``reference``, and ``difference_type`` meet -the requirements indicated by ``iterator_category``. - -[Note: there are further requirements on the -``iterator_traits::value_type`` if the ``Value`` -parameter is not ``use_default``, as implied by the algorithm for -deducing the default for the ``value_type`` member.] - -``indirect_iterator`` models -............................ - -In addition to the concepts indicated by ``iterator_category`` -and by ``iterator_traversal::type``, a -specialization of ``indirect_iterator`` models the following -concepts, Where ``v`` is an object of -``iterator_traits::value_type``: - - * Readable Iterator if ``reference(*v)`` is convertible to - ``value_type``. - - * Writable Iterator if ``reference(*v) = t`` is a valid - expression (where ``t`` is an object of type - ``indirect_iterator::value_type``) - - * Lvalue Iterator if ``reference`` is a reference type. - -``indirect_iterator`` is interoperable with -``indirect_iterator`` if and only if ``X`` is -interoperable with ``Y``. - - -``indirect_iterator`` operations -................................ - -In addition to the operations required by the concepts described -above, specializations of ``indirect_iterator`` provide the -following operations. - - -``indirect_iterator();`` - -:Requires: ``Iterator`` must be Default Constructible. -:Effects: Constructs an instance of ``indirect_iterator`` with - a default-constructed ``m_iterator``. - - -``indirect_iterator(Iterator x);`` - -:Effects: Constructs an instance of ``indirect_iterator`` with - ``m_iterator`` copy constructed from ``x``. - -:: - - template < - class Iterator2, class Value2, unsigned Access, class Traversal - , class Reference2, class Difference2 - > - indirect_iterator( - indirect_iterator< - Iterator2, Value2, Access, Traversal, Reference2, Difference2 - > const& y - , typename enable_if_convertible::type* = 0 // exposition - ); - -:Requires: ``Iterator2`` is implicitly convertible to ``Iterator``. -:Effects: Constructs an instance of ``indirect_iterator`` whose - ``m_iterator`` subobject is constructed from ``y.base()``. - - -``Iterator const& base() const;`` - -:Returns: ``m_iterator`` - - -``reference operator*() const;`` - -:Returns: ``**m_iterator`` - - -``indirect_iterator& operator++();`` - -:Effects: ``++m_iterator`` -:Returns: ``*this`` - - -``indirect_iterator& operator--();`` - -:Effects: ``--m_iterator`` -:Returns: ``*this`` diff --git a/doc/indirect_reference_ref.rst b/doc/indirect_reference_ref.rst deleted file mode 100755 index f222d7e..0000000 --- a/doc/indirect_reference_ref.rst +++ /dev/null @@ -1,29 +0,0 @@ -.. 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) - -:: - - template - struct indirect_reference - { - typedef /* see below */ type; - }; - -:Requires: For an object ``x`` of type ``Dereferenceable``, ``*x`` - is well-formed. If ``++x`` is ill-formed it shall neither be - ambiguous nor shall it violate access control, and - ``pointee::type&`` shall be well-formed. - Otherwise ``iterator_traits::reference`` shall - be well formed. [Note: These requirements need not apply to - explicit or partial specializations of ``indirect_reference``] - -``type`` is determined according to the following algorithm, where -``x`` is an object of type ``Dereferenceable``:: - - if ( ++x is ill-formed ) - return ``pointee::type&`` - else - std::iterator_traits::reference - - \ No newline at end of file diff --git a/doc/interoperability-revisited.rst b/doc/interoperability-revisited.rst deleted file mode 100755 index 6754b9c..0000000 --- a/doc/interoperability-revisited.rst +++ /dev/null @@ -1,232 +0,0 @@ -++++++++++++++++++++++++++++ - Interoperability Revisited -++++++++++++++++++++++++++++ - -:date: $Date$ -:copyright: Copyright Thomas Witt 2004. - - -Problem -======= - -The current iterator_facade specification makes it unneccessarily tedious to -implement interoperable iterators. - -In the following text a simplified example of the current iterator_facade specification is used to -illustrate the problem. - -In the current specification binary operators are implemented in the following way: - -template -struct Facade -{ -}; - -template -struct is_interoperable : - or_< - is_convertible - , is_convertible - > -{}; - -template< - class Derived1 - , class Derived2 -> -enable_if, bool> operator==( - Derived1 const& lhs - , Derived2 const& rhs -) -{ - return static_cast(lhs).equal_to(static_cast -{ - bool equal_to(Mutable const&); -}; - -struct Constant : Facade -{ - Constant(); - Constant(Constant const&); - Constant(Mutable const&); - - ... - - bool equal_to(Constant const&); -}; - -Constant c; -Mutable m; - -c == m; // ok, dispatched to Constant::equal_to -m == c; // !! error, dispatched to Mutable::equal_to - -Instead the following "slightly" more complicated implementation is neccessary - -struct Mutable : Facade -{ - template - enable_if || is_convertible, bool>::type equal_to(T const&); -}; - -struct Constant : Tag -{ - Constant(); - Constant(Constant const&); - Constant(Mutable const&); - - template - enable_if || is_convertible, bool>::type equal_to(T const&); -}; - -Beside the fact that the code is significantly more complex to understand and to teach there is -a major design problem lurking here. Note that in both types equal_to is a function template with -an unconstrained argument T. This is neccessary so that further types can be made interoperable with -Mutable or Constant. Would Mutable be defined as - -struct Mutable : Facade -{ - bool equal_to(Mutable const&); - bool equal_to(Constant const&); -}; - -Constant and Mutable would still be interoperable but no further interoperable could be added -without changing Mutable. Even if this would be considered acceptable the current specification forces -a two way dependency between interoperable types. Note in the templated equal_to case this dependency -is implicitly created when specializing equal_to. - -Solution -======== - -The two way dependency can be avoided by enabling type conversion in the binary operator -implementation. Note that this is the usual way interoperability betwween types is achieved -for binary operators and one reason why binary operators are usually implemented as non-members. - -A simple implementation of this strategy would look like this - -template< - class T1 - , class T2 -> -struct interoperable_base : - if_< - is_convertible< - T2 - , T1 - > - , T1 - , T2> -{}; - - -template< - class Derived1 - , class Derived2 -> -enable_if, bool> operator==( - Derived1 const& lhs - , Derived2 const& rhs -) -{ - typedef interoperable_base< - Derived1 - , Derived2 - >::type Base; - - return static_cast(lhs).equal_to(static_cast -enable_if, bool> operator==( - Derived1 const& lhs - , Derived2 const& rhs -) -{ - return static_cast(lhs).equal_to(static_cast -enable_if, bool> operator==( - Derived1 const& lhs - , Derived2 const& rhs -) -{ - return static_cast(rhs).equal_to(static_cast -{ - Constant(); - Constant(Constant const&); - Constant(Mutable const&); - - ... - - bool equal_to(Constant const&); - bool equal_to(Mutable const&); -}; - -c == m; // ok, dispatched to Constant::equal_to(Mutable const&), no conversion -m == c; // ok, dispatched to Constant::equal_to(Mutable const&), no conversion - -This definition of operator== introduces a possible ambiguity when both types are convertible -to each other. I don't think this is a problem as this behaviour is the same with concrete types. -I.e. - -struct A {}; - -bool operator==(A, A); - -struct B { B(A); }; - -bool operator==(B, B); - -A a; -B b(a); - -a == b; // error, ambiguous overload - -Effect -====== - -Iterator implementations using iterator_facade look exactly as if they were -"hand-implemented" (I am working on better wording). - -a) Less burden for the user - -b) The definition (standardese) of specialized adpters might be easier - (This has to be proved yet) \ No newline at end of file diff --git a/doc/issues.html b/doc/issues.html deleted file mode 100755 index 8087b45..0000000 --- a/doc/issues.html +++ /dev/null @@ -1,165 +0,0 @@ - - - - - - -Problem with is_writable and is_swappable in N1550 - - - -
-

Problem with is_writable and is_swappable in N1550

- --- - - - - - - - - - - - -
Author:David Abrahams and Jeremy Siek
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu
Organization:Boost Consulting, Indiana University Bloomington
date:$Date$
Copyright:Copyright David Abrahams, Jeremy Siek 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)
- -
-

Introduction

-

The is_writable and is_swappable traits classes in N1550 -provide a mechanism for determining at compile time if an iterator -type is a model of the new Writable Iterator and Swappable Iterator -concepts, analogous to iterator_traits<X>::iterator_category -for the old iterator concepts. For backward compatibility, -is_writable and is_swappable not only work with new -iterators, but they also are intended to work for old -iterators (iterators that meet the requirements for one of the -iterator concepts in the current standard). In the case of old -iterators, the writability and swapability is deduced based on the -iterator_category and also the reference type. The -specification for this deduction gives false positives for forward -iterators that have non-assignable value types.

-

To review, the part of the is_writable trait definition which -applies to old iterators is:

-
-if (cat is convertible to output_iterator_tag)
-    return true;
-else if (cat is convertible to forward_iterator_tag
-         and iterator_traits<Iterator>::reference is a 
-             mutable reference)
-    return true;
-else
-    return false;
-
-

Suppose the value_type of the iterator It has a private -assignment operator:

-
-class B {
-public:
-  ...
-private:
-  B& operator=(const B&);
-};
-
-

and suppose the reference type of the iterator is B&. In -that case, is_writable<It>::value will be true when in fact -attempting to write into B will cause an error.

-

The same problem applies to is_swappable.

-
-
-

Proposed Resolution

-
    -
  1. Remove the is_writable and is_swappable traits, and remove the -requirements in the Writable Iterator and Swappable Iterator concepts -that require their models to support these traits.

    -
  2. -
  3. Change the is_readable specification to be: -is_readable<X>::type is true_type if the -result type of X::operator* is convertible to -iterator_traits<X>::value_type and is false_type -otherwise. Also, is_readable is required to satisfy -the requirements for the UnaryTypeTrait concept -(defined in the type traits proposal).

    -

    Remove the requirement for support of the is_readable trait from -the Readable Iterator concept.

    -
  4. -
  5. Remove the iterator_tag class.

    -
  6. -
  7. Change the specification of traversal_category to:

    -
    -traversal-category(Iterator) =
    -    let cat = iterator_traits<Iterator>::iterator_category
    -    if (cat is convertible to incrementable_iterator_tag)
    -      return cat; // Iterator is a new iterator
    -    else if (cat is convertible to random_access_iterator_tag)
    -        return random_access_traversal_tag;
    -    else if (cat is convertible to bidirectional_iterator_tag)
    -        return bidirectional_traversal_tag;
    -    else if (cat is convertible to forward_iterator_tag)
    -        return forward_traversal_tag;
    -    else if (cat is convertible to input_iterator_tag)
    -        return single_pass_iterator_tag;
    -    else if (cat is convertible to output_iterator_tag)
    -        return incrementable_iterator_tag;
    -    else
    -        return null_category_tag;
    -
    -
  8. -
-
-
-

Rationale

-
    -
  1. There are two reasons for removing is_writable -and is_swappable. The first is that we do not know of -a way to fix the specification so that it gives the correct -answer for all iterators. Second, there was only a weak -motivation for having is_writable and is_swappable -there in the first place. The main motivation was simply -uniformity: we have tags for the old iterator categories -so we should have tags for the new iterator categories. -While having tags and the capability to dispatch based -on the traversal categories is often used, we see -less of a need for dispatching based on writability -and swappability, since typically algorithms -that need these capabilities have no alternative if -they are not provided.
  2. -
  3. We discovered that the is_readable trait can be implemented -using only the iterator type itself and its value_type. -Therefore we remove the requirement for is_readable from the -Readable Iterator concept, and change the definition of -is_readable so that it works for any iterator type.
  4. -
  5. The purpose of the iterator_tag class was to -bundle the traversal and access category tags -into the iterator_category typedef. -With is_writable and is_swappable gone, and -is_readable no longer in need of special hints, -there is no reason for iterators to provide -information about the access capabilities of an iterator. -Thus there is no need for the iterator_tag. The -traversal tag can be directly used for the -iterator_category. If a new iterator is intended to be backward -compatible with old iterator concepts, a tag type -that is convertible to both one of the new traversal tags -and also to an old iterator tag can be created and use -for the iterator_category.
  6. -
  7. The changes to the specification of traversal_category are a -direct result of the removal of iterator_tag.
  8. -
-
-
- - diff --git a/doc/issues.rst b/doc/issues.rst deleted file mode 100755 index 5ddb61f..0000000 --- a/doc/issues.rst +++ /dev/null @@ -1,152 +0,0 @@ -++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - Problem with ``is_writable`` and ``is_swappable`` in N1550_ -++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -.. _N1550: http://www.boost-consulting.com/writing/n1550.html -.. _N1530: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1530.html - -:Author: David Abrahams and Jeremy Siek -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu -:Organization: `Boost Consulting`_, Indiana University Bloomington -:date: $Date$ -:Copyright: Copyright David Abrahams, Jeremy Siek 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) - -.. _`Boost Consulting`: http://www.boost-consulting.com - -.. contents:: Table of Contents - -============== - Introduction -============== - -The ``is_writable`` and ``is_swappable`` traits classes in N1550_ -provide a mechanism for determining at compile time if an iterator -type is a model of the new Writable Iterator and Swappable Iterator -concepts, analogous to ``iterator_traits::iterator_category`` -for the old iterator concepts. For backward compatibility, -``is_writable`` and ``is_swappable`` not only work with new -iterators, but they also are intended to work for old -iterators (iterators that meet the requirements for one of the -iterator concepts in the current standard). In the case of old -iterators, the writability and swapability is deduced based on the -``iterator_category`` and also the ``reference`` type. The -specification for this deduction gives false positives for forward -iterators that have non-assignable value types. - -To review, the part of the ``is_writable`` trait definition which -applies to old iterators is:: - - if (cat is convertible to output_iterator_tag) - return true; - else if (cat is convertible to forward_iterator_tag - and iterator_traits::reference is a - mutable reference) - return true; - else - return false; - -Suppose the ``value_type`` of the iterator ``It`` has a private -assignment operator:: - - class B { - public: - ... - private: - B& operator=(const B&); - }; - -and suppose the ``reference`` type of the iterator is ``B&``. In -that case, ``is_writable::value`` will be true when in fact -attempting to write into ``B`` will cause an error. - -The same problem applies to ``is_swappable``. - - -==================== - Proposed Resolution -==================== - -1. Remove the ``is_writable`` and ``is_swappable`` traits, and remove the - requirements in the Writable Iterator and Swappable Iterator concepts - that require their models to support these traits. - -2. Change the ``is_readable`` specification to be: - ``is_readable::type`` is ``true_type`` if the - result type of ``X::operator*`` is convertible to - ``iterator_traits::value_type`` and is ``false_type`` - otherwise. Also, ``is_readable`` is required to satisfy - the requirements for the UnaryTypeTrait concept - (defined in the type traits proposal). - - Remove the requirement for support of the ``is_readable`` trait from - the Readable Iterator concept. - - -3. Remove the ``iterator_tag`` class. - -4. Change the specification of ``traversal_category`` to:: - - traversal-category(Iterator) = - let cat = iterator_traits::iterator_category - if (cat is convertible to incrementable_iterator_tag) - return cat; // Iterator is a new iterator - else if (cat is convertible to random_access_iterator_tag) - return random_access_traversal_tag; - else if (cat is convertible to bidirectional_iterator_tag) - return bidirectional_traversal_tag; - else if (cat is convertible to forward_iterator_tag) - return forward_traversal_tag; - else if (cat is convertible to input_iterator_tag) - return single_pass_iterator_tag; - else if (cat is convertible to output_iterator_tag) - return incrementable_iterator_tag; - else - return null_category_tag; - - -========== - Rationale -========== - -1. There are two reasons for removing ``is_writable`` - and ``is_swappable``. The first is that we do not know of - a way to fix the specification so that it gives the correct - answer for all iterators. Second, there was only a weak - motivation for having ``is_writable`` and ``is_swappable`` - there in the first place. The main motivation was simply - uniformity: we have tags for the old iterator categories - so we should have tags for the new iterator categories. - While having tags and the capability to dispatch based - on the traversal categories is often used, we see - less of a need for dispatching based on writability - and swappability, since typically algorithms - that need these capabilities have no alternative if - they are not provided. - -2. We discovered that the ``is_readable`` trait can be implemented - using only the iterator type itself and its ``value_type``. - Therefore we remove the requirement for ``is_readable`` from the - Readable Iterator concept, and change the definition of - ``is_readable`` so that it works for any iterator type. - -3. The purpose of the ``iterator_tag`` class was to - bundle the traversal and access category tags - into the ``iterator_category`` typedef. - With ``is_writable`` and ``is_swappable`` gone, and - ``is_readable`` no longer in need of special hints, - there is no reason for iterators to provide - information about the access capabilities of an iterator. - Thus there is no need for the ``iterator_tag``. The - traversal tag can be directly used for the - ``iterator_category``. If a new iterator is intended to be backward - compatible with old iterator concepts, a tag type - that is convertible to both one of the new traversal tags - and also to an old iterator tag can be created and use - for the ``iterator_category``. - -4. The changes to the specification of ``traversal_category`` are a - direct result of the removal of ``iterator_tag``. - diff --git a/doc/iter-issue-list.rst b/doc/iter-issue-list.rst deleted file mode 100644 index ba514d0..0000000 --- a/doc/iter-issue-list.rst +++ /dev/null @@ -1,3798 +0,0 @@ -+++++++++++++++++++++++++++++++++++++ - Iterator concept and adapter issues -+++++++++++++++++++++++++++++++++++++ - -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. - -.. contents:: Index - -=================================== - Issues from Matt's TR issues list -=================================== - - -9.1 iterator_access overspecified? -================================== - -:Submitter: Pete Becker -:Status: New - -The proposal includes:: - - enum iterator_access { - readable_iterator = 1, writable_iterator = 2, - swappable_iterator = 4, lvalue_iterator = 8 - }; - -In general, the standard specifies thing like this as a bitmask -type with a list of defined names, and specifies neither the exact -type nor the specific values. Is there a reason for iterator_access -to be more specific? - -:Proposed resolution: The ``iterator_access`` enum will be removed, - so this is no longer an issue. See the resolution to 9.15. - - -9.2 operators of iterator_facade overspecified -============================================== - -:Submitter: Pete Becker -:Status: New - -In general, we've provided operational semantics for things like -operator++. That is, we've said that ++iter must work, without -requiring either a member function or a non-member function. -iterator_facade specifies most operators as member -functions. There's no inherent reason for these to be members, so -we should remove this requirement. Similarly, some operations are -specified as non-member functions but could be implemented as -members. Again, the standard doesn't make either of these choices, -and TR1 shouldn't, either. So: ``operator*()``, ``operator++()``, -``operator++(int)``, ``operator--()``, ``operator--(int)``, -``operator+=``, ``operator-=``, ``operator-(difference_type)``, -``operator-(iterator_facade instance)``, and ``operator+`` should -be specified with operational semantics and not explicitly required -to be members or non-members. - -:Proposed resolution: Not a defect. - -:Rationale: The standard uses valid expressions such as ``++iter`` - in requirements tables, such as for input iterator. However, for - classes, such as ``reverse_iterator``, the standard uses function - prototypes, as we have done here for - ``iterator_facade``. Further, the prototype specification does - not prevent the implementor from using members or non-members, - since nothing the user can do in a conforming program can detect - how the function is implemented. - - -9.3 enable_if_interoperable needs standardese -============================================= - -:Submitter: Pete Becker -:Status: New - -The only discussion of what this means is in a note, so is -non-normative. Further, the note seems to be incorrect. It says -that enable_if_interoperable only works for types that "are -interoperable, by which we mean they are convertible to each -other." This requirement is too strong: it should be that one of -the types is convertible to the other. N1541 48 - -:Proposed resolution: Add normative text. Relax requirements in the - proposed way. - - Change: - - [*Note:* The ``enable_if_interoperable`` template used above is - for exposition purposes. The member operators should be only be - in an overload set provided the derived types ``Dr1`` and - ``Dr2`` are interoperable, by which we mean they are - convertible to each other. The ``enable_if_interoperable`` - approach uses SFINAE to take the operators out of the overload - set when the types are not interoperable.] - - To: - - The ``enable_if_interoperable`` template used above is for - exposition purposes. The member operators should only be in an - overload set provided the derived types ``Dr1`` and ``Dr2`` are - interoperable, meaning that at least one of the types is - convertible to the other. The ``enable_if_interoperable`` - approach uses SFINAE to take the operators out of the overload - set when the types are not interoperable. The operators should - behave *as-if* ``enable_if_interoperable`` were defined to be:: - - template enable_if_interoperable_impl - {}; - - template enable_if_interoperable_impl - { typedef T type; }; - - template - struct enable_if_interoperable - : enable_if_interoperable_impl< - is_convertible::value || is_convertible::value - , T - > - {}; - -9.4 enable_if_convertible unspecified, conflicts with requires -============================================================== - -:Submitter: Pete Becker -:Status: New - -In every place where enable_if_convertible is used it's used like -this (simplified):: - - template - struct C - { - template - C(T1, enable_if_convertible::type* = 0); - }; - -The idea being that this constructor won't compile if T1 isn't -convertible to T. As a result, the constructor won't be considered -as a possible overload when constructing from an object x where the -type of x isn't convertible to T. In addition, however, each of -these constructors has a requires clause that requires -convertibility, so the behavior of a program that attempts such a -construction is undefined. Seems like the enable_if_convertible -part is irrelevant, and should be removed. There are two -problems. First, enable_if_convertible is never specified, so we -don't know what this is supposed to do. Second: we could reasonably -say that this overload should be disabled in certain cases or we -could reasonably say that behavior is undefined, but we can't say -both. - -Thomas Witt writes that the goal of putting in -enable_if_convertible here is to make sure that a specific overload -doesn't interfere with the generic case except when that overload -makes sense. He agrees that what we currently have is deficient. -Dave Abrahams writes that there is no conflict with the requires -cause because the requires clause only takes effect when the -function is actually called. The presence of the constructor -signature can/will be detected by is_convertible without violating -the requires clause, and thus it makes a difference to disable -those constructor instantiations that would be disabled by -enable_if_convertible even if calling them invokes undefined -behavior. There was more discussion on the reflector: -c++std-lib-12312, c++std-lib-12325, c++std-lib- 12330, -c++std-lib-12334, c++std-lib-12335, c++std-lib-12336, -c++std-lib-12338, c++std-lib- 12362. - -:Proposed resolution: - Change: - - [*Note:* The ``enable_if_convertible::type`` expression - used in this section is for exposition purposes. The converting - constructors for specialized adaptors should be only be in an - overload set provided that an object of type ``X`` is - implicitly convertible to an object of type ``Y``. The - ``enable_if_convertible`` approach uses SFINAE to take the - constructor out of the overload set when the types are not - implicitly convertible.] - - To: - - The ``enable_if_convertible::type`` expression used in - this section is for exposition purposes. The converting - constructors for specialized adaptors should be only be in an - overload set provided that an object of type ``X`` is - implicitly convertible to an object of type ``Y``. The - signatures involving ``enable_if_convertible`` should behave - *as-if* ``enable_if_convertible`` were defined to be:: - - template enable_if_convertible_impl - {}; - - template <> enable_if_convertible_impl - { struct type; }; - - template - struct enable_if_convertible - : enable_if_convertible_impl::value> - {}; - - If an expression other than the default argument is used to - supply the value of a function parameter whose type is written - in terms of ``enable_if_convertible``, the program is - ill-formed, no diagnostic required. - - [*Note:* The ``enable_if_convertible`` approach uses SFINAE to - take the constructor out of the overload set when the types are - not implicitly convertible. ] - -9.5 iterator_adaptor has an extraneous 'bool' at the start of the template definition -===================================================================================== - -:Submitter: Pete Becker -:Status: New - -The title says it all; this is probably just a typo. - -:Proposed resolution: Remove the 'bool'. - -9.6 Name of private member shouldn't be normative -================================================= - -:Submitter: Pete Becker -:Status: New - -iterator_adaptor has a private member named m_iterator. Presumably -this is for exposition only, since it's an implementation -detail. It needs to be marked as such. - -:Proposed resolution: Mark the member ``m_iterator`` as exposition - only. Note/DWA: I think this is NAD because the user can't - detect it, though I'm happy to mark it exposition only. - - In [lib.iterator.adaptor] - - Change:: - - Base m_iterator; - - to:: - - Base m_iterator; // exposition only - - -9.7 iterator_adaptor operations specifications are a bit inconsistent -===================================================================== - -:Submitter: Pete Becker -:Status: New - -iterator_adpator() has a Requires clause, that Base must be default -constructible. iterator_adaptor(Base) has no Requires clause, -although the Returns clause says that the Base member is copy -construced from the argument (this may actually be an oversight in -N1550, which doesn't require iterators to be copy constructible or -assignable). - -:Proposed resolution: Add a requirements section for the template - parameters of iterator_adaptor, and state that Base must be Copy - Constructible and Assignable. - - N1550 does in fact include requirements for copy constructible - and assignable in the requirements tables. To clarify, we've also - added the requirements to the text. - - -9.8 Specialized adaptors text should be normative -================================================= - -:Submitter: Pete Becker -:Status: New - -similar to 9.3, "Specialized Adaptors" has a note describing -enable_if_convertible. This should be normative text. - -:Proposed resolution: Changed it to normative - text. See the resolution of 9.4 - -9.9 Reverse_iterator text is too informal -========================================= - -:Submitter: Pete Becker -:Status: New - -reverse iterator "flips the direction of the base iterator's -motion". This needs to be more formal, as in the current -standard. Something like: "iterates through the controlled sequence -in the opposite direction" - -:Proposed resolution: - - Change: - - The reverse iterator adaptor flips the direction of a base - iterator's motion. Invoking ``operator++()`` moves the base - iterator backward and invoking ``operator--()`` moves the base - iterator forward. - - to: - - The reverse iterator adaptor iterates through the adapted iterator - range in the opposite direction. - - -9.10 'prior' is undefined -========================= - -:Submitter: Pete Becker -:Status: New - -reverse_iterator::dereference is specified as calling a function -named 'prior' which has no specification. - -:Proposed resolution: - Change the specification to avoid using ``prior`` as follows. - - Remove:: - - typename reverse_iterator::reference dereference() const { return *prior(this->base()); } - - And at the end of the operations section add: - - ``reference operator*() const;`` - - :Effects: - - :: - - Iterator tmp = m_iterator; - return *--tmp; - -:Rationale: - The style of specification has changed because of issue 9.37x. - - - -9.11 "In other words" is bad wording -==================================== - -:Submitter: Pete Becker -:Status: New - -Transform iterator has a two-part specification: it does this, in -other words, it does that. "In other words" always means "I didn't -say it right, so I'll try again." We need to say it once. - -:Proposed resolution: - Change: - - The transform iterator adapts an iterator by applying some function - object to the result of dereferencing the iterator. In other words, - the ``operator*`` of the transform iterator first dereferences the - base iterator, passes the result of this to the function object, and - then returns the result. - - to: - - The transform iterator adapts an iterator by modifying the - ``operator*`` to apply a function object to the result of - dereferencing the iterator and returning the result. - - -9.12 Transform_iterator shouldn't mandate private member -======================================================== - -:Submitter: Pete Becker -:Status: New - -transform_iterator has a private member named 'm_f' which should be -marked "exposition only." - -:Proposed resolution: Mark the member ``m_f`` as exposition - only. Note/DWA: I think this is NAD because the user can't - detect it, though I'm happy to mark it exposition only. - - Change:: - - UnaryFunction m_f; - - to:: - - UnaryFunction m_f; // exposition only - - - -9.13 Unclear description of counting iterator -============================================= - -:Submitter: Pete Becker -:Status: New - -The description of Counting iterator is unclear. "The counting -iterator adaptor implements dereference by returning a reference to -the base object. The other operations are implemented by the base -m_iterator, as per the inheritance from iterator_adaptor." - -:Proposed resolution: - Change: - - The counting iterator adaptor implements dereference by - returning a reference to the base object. The other operations - are implemented by the base ``m_iterator``, as per the - inheritance from ``iterator_adaptor``. - - to: - - ``counting_iterator`` adapts an object by adding an - ``operator*`` that returns the current value of the object. All - other iterator operations are forwarded to the adapted object. - - - -9.14 Counting_iterator's difference type -======================================== - -:Submitter: Pete Becker -:Status: New - -Counting iterator has the following note: - - [Note: implementers are encouraged to provide an implementation - of distance_to and a difference_type that avoids overflows in the - cases when the Incrementable type is a numeric type.] - -I'm not sure what this means. The user provides a template argument -named Difference, but there's no difference_type. I assume this is -just a glitch in the wording. But if implementors are encouraged to -ignore this argument if it won't work right, why is it there? - -:Proposed resolution: The ``difference_type`` was inherited from - ``iterator_adaptor``. However, we've removed the explicit - inheritance, so explicit typedefs have been added. See the - resolution of 9.37x. - - - -9.15 How to detect lvalueness? -============================== - -:Submitter: Dave Abrahams -:Status: New - -Shortly after N1550 was accepted, we discovered that an iterator's -lvalueness can be determined knowing only its value_type. This -predicate can be calculated even for old-style iterators (on whose -reference type the standard places few requirements). A trait in -the Boost iterator library does it by relying on the compiler's -unwillingness to bind an rvalue to a T& function template -parameter. Similarly, it is possible to detect an iterator's -readability knowing only its value_type. Thus, any interface which -asks the user to explicitly describe an iterator's lvalue-ness or -readability seems to introduce needless complexity. - - -:Proposed resolution: - - 1. Remove the ``is_writable`` and ``is_swappable`` traits, and - remove the requirements in the Writable Iterator and Swappable - Iterator concepts that require their models to support these - traits. - - 2. Change the ``is_readable`` specification. Remove the - requirement for support of the ``is_readable`` trait from the - Readable Iterator concept. - - 3. Remove the ``iterator_tag`` class and transplant the logic for - choosing an iterator category into ``iterator_facade``. - - 4. Change the specification of ``traversal_category``. - - 5. Remove Access parameters from N1530 - - In N1550: - - Remove: - - Since the access concepts are not related via refinement, but - instead cover orthogonal issues, we do not use tags for the - access concepts, but instead use the equivalent of a bit field. - - We provide an access mechanism for mapping iterator types to - the new traversal tags and access bit field. Our design reuses - ``iterator_traits::iterator_category`` as the access - mechanism. To that end, the access and traversal information is - bundled into a single type using the following `iterator_tag` - class. - - :: - - enum iterator_access { readable_iterator = 1, writable_iterator = 2, - swappable_iterator = 4, lvalue_iterator = 8 }; - - template - struct iterator_tag : /* appropriate old category or categories */ { - static const iterator_access access = - (iterator_access)access_bits & - (readable_iterator | writable_iterator | swappable_iterator); - typedef TraversalTag traversal; - }; - - The ``access_bits`` argument is declared to be ``unsigned int`` - instead of the enum ``iterator_access`` for convenience of - use. For example, the expression ``(readable_iterator | - writable_iterator)`` produces an unsigned int, not an - ``iterator_access``. The purpose of the ``lvalue_iterator`` - part of the ``iterator_access`` enum is to communicate to - ``iterator_tag`` whether the reference type is an lvalue so - that the appropriate old category can be chosen for the base - class. The ``lvalue_iterator`` bit is not recorded in the - ``iterator_tag::access`` data member. - - The ``iterator_tag`` class template is derived from the - appropriate iterator tag or tags from the old requirements - based on the access bits and traversal tag passed as template - parameters. The algorithm for determining the old tag or tags - picks the least refined old concepts that include all of the - requirements of the access and traversal concepts (that is, the - closest fit), if any such category exists. For example, the - category tag for a Readable Single Pass Iterator will always be - derived from ``input_iterator_tag``, while the category tag for - a Single Pass Iterator that is both Readable and Writable will - be derived from both ``input_iterator_tag`` and - ``output_iterator_tag``. - - We also provide several helper classes that make it convenient - to obtain the access and traversal characteristics of an - iterator. These helper classes work both for iterators whose - ``iterator_category`` is ``iterator_tag`` and also for - iterators using the original iterator categories. - - :: - - template struct is_readable { typedef ... type; }; - template struct is_writable { typedef ... type; }; - template struct is_swappable { typedef ... type; }; - template struct traversal_category { typedef ... type; }; - - - After: - - Like the old iterator requirements, we provide tags for - purposes of dispatching based on the traversal concepts. The - tags are related via inheritance so that a tag is convertible - to another tag if the concept associated with the first tag is - a refinement of the second tag. - - Add: - - Our design reuses ``iterator_traits::iterator_category`` - to indicate an iterator's traversal capability. To specify - capabilities not captured by any old-style iterator category, - an iterator designer can use an ``iterator_category`` type that - is convertible to both the the most-derived old iterator - category tag which fits, and the appropriate new iterator - traversal tag. - - We do not provide tags for the purposes of dispatching based on - the access concepts, in part because we could not find a way to - automatically infer the right access tags for old-style - iterators. An iterator's writability may be dependent on the - assignability of its ``value_type`` and there's no known way to - detect whether an arbitrary type is assignable. Fortunately, - the need for dispatching based on access capability is not as - great as the need for dispatching based on traversal - capability. - - - From the Readable Iterator Requirements table, remove: - - +-----------------------------------+-----------------------------------+-------------------------+ - |``is_readable::type`` |``true_type`` | | - +-----------------------------------+-----------------------------------+-------------------------+ - - From the Writable Iterator Requirements table, remove: - - +-------------------------+--------------+----------------------------+ - |``is_writable::type`` |``true_type`` | | - +-------------------------+--------------+----------------------------+ - - From the Swappable Iterator Requirements table, remove: - - +-------------------------+-------------+-----------------------------+ - |``is_swappable::type``|``true_type``| | - +-------------------------+-------------+-----------------------------+ - - - From [lib.iterator.synopsis] replace:: - - template struct is_readable; - template struct is_writable; - template struct is_swappable; - template struct traversal_category; - - enum iterator_access { readable_iterator = 1, writable_iterator = 2, - swappable_iterator = 4, lvalue_iterator = 8 }; - - template - struct iterator_tag : /* appropriate old category or categories */ { - static const iterator_access access = - (iterator_access)access_bits & - (readable_iterator | writable_iterator | swappable_iterator); - typedef TraversalTag traversal; - }; - - with:: - - template struct is_readable_iterator; - template struct iterator_traversal; - - - In [lib.iterator.traits], remove: - - The ``iterator_tag`` class template is an iterator category tag - that encodes the access enum and traversal tag in addition to - being compatible with the original iterator tags. The - ``iterator_tag`` class inherits from one of the original - iterator tags according to the following pseudo-code. - - :: - - inherit-category(access, traversal-tag) = - if ((access & readable_iterator) && (access & lvalue_iterator)) { - if (traversal-tag is convertible to random_access_traversal_tag) - return random_access_iterator_tag; - else if (traversal-tag is convertible to bidirectional_traversal_tag) - return bidirectional_iterator_tag; - else if (traversal-tag is convertible to forward_traversal_tag) - return forward_iterator_tag; - else if (traversal-tag is convertible to single_pass_traversal_tag) - if (access-tag is convertible to writable_iterator_tag) - return input_output_iterator_tag; - else - return input_iterator_tag; - else - return null_category_tag; - } else if ((access & readable_iterator) and (access & writable_iterator) - and traversal-tag is convertible to single_pass_iterator_tag) - return input_output_iterator_tag; - else if (access & readable_iterator - and traversal-tag is convertible to single_pass_iterator_tag) - return input_iterator_tag; - else if (access & writable_iterator - and traversal-tag is convertible to incrementable_iterator_tag) - return output_iterator_tag; - else - return null_category_tag; - - If the argument for ``TraversalTag`` is not convertible to - ``incrementable_iterator_tag`` then the program is ill-formed. - - Change: - - The ``is_readable``, ``is_writable``, ``is_swappable``, and - ``traversal_category`` class templates are traits classes. For - iterators whose ``iterator_traits::iterator_category`` - type is ``iterator_tag``, these traits obtain the ``access`` - enum and ``traversal`` member type from within - ``iterator_tag``. For iterators whose - ``iterator_traits::iterator_category`` type is not - ``iterator_tag`` and instead is a tag convertible to one of the - original tags, the appropriate traversal tag and access bits - are deduced. The following pseudo-code describes the - algorithm. - - :: - - is-readable(Iterator) = - cat = iterator_traits::iterator_category; - if (cat == iterator_tag) - return Access & readable_iterator; - else if (cat is convertible to input_iterator_tag) - return true; - else - return false; - - is-writable(Iterator) = - cat = iterator_traits::iterator_category; - if (cat == iterator_tag) - return Access & writable_iterator; - else if (cat is convertible to output_iterator_tag) - return true; - else if ( - cat is convertible to forward_iterator_tag - and iterator_traits::reference is a - mutable reference) - return true; - else - return false; - - is-swappable(Iterator) = - cat = iterator_traits::iterator_category; - if (cat == iterator_tag) - return Access & swappable_iterator; - else if (cat is convertible to forward_iterator_tag) { - if (iterator_traits::reference is a const reference) - return false; - else - return true; - } else - return false; - - traversal-category(Iterator) = - cat = iterator_traits::iterator_category; - if (cat == iterator_tag) - return Traversal; - else if (cat is convertible to random_access_iterator_tag) - return random_access_traversal_tag; - else if (cat is convertible to bidirectional_iterator_tag) - return bidirectional_traversal_tag; - else if (cat is convertible to forward_iterator_tag) - return forward_traversal_tag; - else if (cat is convertible to input_iterator_tag) - return single_pass_iterator_tag; - else if (cat is convertible to output_iterator_tag) - return incrementable_iterator_tag; - else - return null_category_tag; - - - The following specializations provide the access and traversal - category tags for pointer types. - - :: - - template - struct is_readable { typedef true_type type; }; - template - struct is_writable { typedef false_type type; }; - template - struct is_swappable { typedef false_type type; }; - - template - struct is_readable { typedef true_type type; }; - template - struct is_writable { typedef true_type type; }; - template - struct is_swappable { typedef true_type type; }; - - template - struct traversal_category - { - typedef random_access_traversal_tag type; - }; - - to: - - The ``is_readable_iterator`` class template satisfies the - UnaryTypeTrait requirements. - - Given an iterator type ``X``, - ``is_readable_iterator::value`` yields ``true`` if, for an - object ``a`` of type ``X``, ``*a`` is convertible to - ``iterator_traits::value_type``, and ``false`` otherwise. - - .. _`category-to-traversal`: - - ``iterator_traversal::type`` is - - .. parsed-literal:: - - *category-to-traversal*\ (iterator_traits::iterator_category) - - where *category-to-traversal* is defined as follows - - .. parsed-literal:: - - *category-to-traversal*\ (C) = - if (C is convertible to incrementable_traversal_tag) - return C; - else if (C is convertible to random_access_iterator_tag) - return random_access_traversal_tag; - else if (C is convertible to bidirectional_iterator_tag) - return bidirectional_traversal_tag; - else if (C is convertible to forward_iterator_tag) - return forward_traversal_tag; - else if (C is convertible to input_iterator_tag) - return single_pass_traversal_tag; - else if (C is convertible to output_iterator_tag) - return incrementable_traversal_tag; - else - *the program is ill-formed* - - In N1530: - - In [lib.iterator.helper.synopsis]: - - Change:: - - const unsigned use_default_access = -1; - - struct iterator_core_access { /* implementation detail */ }; - - template < - class Derived - , class Value - , unsigned AccessCategory - , class TraversalCategory - , class Reference = Value& - , class Difference = ptrdiff_t - > - class iterator_facade; - - template < - class Derived - , class Base - , class Value = use_default - , unsigned Access = use_default_access - , class Traversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class iterator_adaptor; - - template < - class Iterator - , class Value = use_default - , unsigned Access = use_default_access - , class Traversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class indirect_iterator; - - To:: - - struct iterator_core_access { /* implementation detail */ }; - - template < - class Derived - , class Value - , class CategoryOrTraversal - , class Reference = Value& - , class Difference = ptrdiff_t - > - class iterator_facade; - - template < - class Derived - , class Base - , class Value = use_default - , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class iterator_adaptor; - - template < - class Iterator - , class Value = use_default - , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class indirect_iterator; - - Change:: - - template < - class Incrementable - , unsigned Access = use_default_access - , class Traversal = use_default - , class Difference = use_default - > - class counting_iterator - - To:: - - template < - class Incrementable - , class CategoryOrTraversal = use_default - , class Difference = use_default - > - class counting_iterator; - - In [lib.iterator.facade]: - - Change:: - - template < - class Derived - , class Value - , unsigned AccessCategory - , class TraversalCategory - , class Reference = /* see below */ - , class Difference = ptrdiff_t - > - class iterator_facade { - - to:: - - template < - class Derived - , class Value - , class CategoryOrTraversal - , class Reference = Value& - , class Difference = ptrdiff_t - > - class iterator_facade { - - - Change:: - - typedef iterator_tag iterator_category; - - to:: - - typedef /* see below */ iterator_category; - - - Change:: - - // Comparison operators - template - typename enable_if_interoperable::type // exposition - operator ==(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator !=(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator <(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator <=(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator >(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator >=(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator >=(iterator_facade const& lhs, - iterator_facade const& rhs); - - // Iterator difference - template - typename enable_if_interoperable::type - operator -(iterator_facade const& lhs, - iterator_facade const& rhs); - - // Iterator addition - template - Derived operator+ (iterator_facade const&, - typename Derived::difference_type n) - - to:: - - // Comparison operators - template - typename enable_if_interoperable::type // exposition - operator ==(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator !=(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator <(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator <=(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator >(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator >=(iterator_facade const& lhs, - iterator_facade const& rhs); - - // Iterator difference - template - /* see below */ - operator-(iterator_facade const& lhs, - iterator_facade const& rhs); - - // Iterator addition - template - Derived operator+ (iterator_facade const&, - typename Derived::difference_type n); - - template - Derived operator+ (typename Derived::difference_type n, - iterator_facade const&); - - - After the ``iterator_facade`` synopsis, add: - - The ``iterator_category`` member of ``iterator_facade`` is - - .. parsed-literal:: - - *iterator-category*\ (CategoryOrTraversal, value_type, reference) - - where *iterator-category* is defined as follows: - - .. parsed-literal:: - - *iterator-category*\ (C,R,V) := - if (C is convertible to std::input_iterator_tag - || C is convertible to std::output_iterator_tag - ) - return C - - else if (C is not convertible to incrementable_traversal_tag) - *the program is ill-formed* - - else return a type X satisfying the following two constraints: - - 1. X is convertible to X1, and not to any more-derived - type, where X1 is defined by: - - if (R is a reference type - && C is convertible to forward_traversal_tag) - { - if (C is convertible to random_access_traversal_tag) - X1 = random_access_iterator_tag - else if (C is convertible to bidirectional_traversal_tag) - X1 = bidirectional_iterator_tag - else - X1 = forward_iterator_tag - } - else - { - if (C is convertible to single_pass_traversal_tag - && R is convertible to V) - X1 = input_iterator_tag - else - X1 = C - } - - 2. |category-to-traversal|_\ (X) is convertible to the most - derived traversal tag type to which X is also - convertible, and not to any more-derived traversal tag - type. - -.. |category-to-traversal| replace:: *category-to-traversal* - -.. |iterator-category| replace:: *iterator-category* -.. _iterator-category: - - In [lib.iterator.facade] ``iterator_facade`` requirements: - - Remove: - - ``AccessCategory`` must be an unsigned value which uses no more - bits than the greatest value of ``iterator_access``. - - In the **Iterator Adaptor** section, change: - - Several of the template parameters of ``iterator_adaptor`` default - to ``use_default`` (or ``use_default_access``). - - to: - - Several of the template parameters of ``iterator_adaptor`` default - to ``use_default``. - - In [lib.iterator.special.adaptors]: - - Change:: - - template < - class Iterator - , class Value = use_default - , unsigned Access = use_default_access - , class Traversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class indirect_iterator - - to:: - - template < - class Iterator - , class Value = use_default - , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class indirect_iterator - - Change:: - - template < - class Iterator2, class Value2, unsigned Access2, class Traversal2 - , class Reference2, class Difference2 - > - indirect_iterator( - - to:: - - template < - class Iterator2, class Value2, class Category2 - , class Reference2, class Difference2 - > - indirect_iterator( - - Change:: - - template < - class Incrementable - , unsigned Access = use_default_access - , class Traversal = use_default - , class Difference = use_default - > - class counting_iterator - - to:: - - template < - class Incrementable - , class CategoryOrTraversal = use_default - , class Difference = use_default - > - class counting_iterator - - - Change:: - - typedef iterator_tag< - writable_iterator - , incrementable_traversal_tag - > iterator_category; - - to: - - typedef std::output_iterator_tag iterator_category; - - In [lib.iterator.adaptor] - - Change:: - - template < - class Derived - , class Base - , class Value = use_default - , unsigned Access = use_default_access - , class Traversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class iterator_adaptor - - To:: - - template < - class Derived - , class Base - , class Value = use_default - , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class iterator_adaptor - -:Rationale: - -1. There are two reasons for removing ``is_writable`` - and ``is_swappable``. The first is that we do not know of - a way to fix the specification so that it gives the correct - answer for all iterators. Second, there was only a weak - motivation for having ``is_writable`` and ``is_swappable`` - there in the first place. The main motivation was simply - uniformity: we have tags for the old iterator categories - so we should have tags for the new iterator categories. - While having tags and the capability to dispatch based - on the traversal categories is often used, we see - less of a need for dispatching based on writability - and swappability, since typically algorithms - that need these capabilities have no alternative if - they are not provided. - -2. We discovered that the ``is_readable`` trait can be implemented - using only the iterator type itself and its ``value_type``. - Therefore we remove the requirement for ``is_readable`` from the - Readable Iterator concept, and change the definition of - ``is_readable`` so that it works for any iterator type. - -3. The purpose of the ``iterator_tag`` class was to bundle the - traversal and access category tags into the - ``iterator_category`` typedef. With ``is_writable`` and - ``is_swappable`` gone, and ``is_readable`` no longer in need of - special hints, there is no reason for iterators to provide - information about the access capabilities of an iterator. Thus - there is no need for the ``iterator_tag``. The traversal tag can - be directly used for the ``iterator_category``. If a new - iterator is intended to be backward compatible with old iterator - concepts, a tag type that is convertible to both one of the new - traversal tags and also to an old iterator tag can be created - and use for the ``iterator_category``. - -4. The changes to the specification of ``traversal_category`` are a - direct result of the removal of ``iterator_tag``. - - - -9.16 is_writable_iterator returns false positives -================================================= - -:Submitter: Dave Abrahams -:Status: New - -is_writable_iterator returns false positives for forward iterators -whose value_type has a private assignment operator, or whose -reference type is not a reference (currently legal). - -:Proposed Resolution: See the resolution to 9.15. - - -9.17 is_swappable_iterator returns false positives -================================================== - -:Submitter: Dave Abrahams -:Status: New - -is_swappable_iterator has the same problems as -is_writable_iterator. In addition, if we allow users to write their -own iter_swap functions it's easy to imagine old-style iterators -for which is_swappable returns false negatives. - -:Proposed Resolution: See the resolution to 9.15. - - -9.18 Are is_readable, is_writable, and is_swappable useful? -=========================================================== - -:Submitter: Dave Abrahams -:Status: New - -I am concerned that there is little use for any of is_readable, -is_writable, or is_swappable, and that not only do they unduly -constrain iterator implementors but they add overhead to -iterator_facade and iterator_adaptor in the form of a template -parameter which would otherwise be unneeded. Since we can't -implement two of them accurately for old-style iterators, I am -having a hard time justifying their impact on the rest of the -proposal(s). - -:Proposed Resolution: See the resolution to 9.15. - -9.19 Non-Uniformity of the "lvalue_iterator Bit" -================================================ - -:Submitter: Dave Abrahams -:Status: New - -The proposed iterator_tag class template accepts an "access bits" -parameter which includes a bit to indicate the iterator's -lvalueness (whether its dereference operator returns a reference to -its value_type. The relevant part of N1550 says: - - The purpose of the lvalue_iterator part of the iterator_access - enum is to communicate to iterator_tagwhether the reference type - is an lvalue so that the appropriate old category can be chosen - for the base class. The lvalue_iterator bit is not recorded in - the iterator_tag::access data member. - -The lvalue_iterator bit is not recorded because N1550 aims to -improve orthogonality of the iterator concepts, and a new-style -iterator's lvalueness is detectable by examining its reference -type. This inside/outside difference is awkward and confusing. - -:Proposed Resolution: The iterator_tag class will be removed, so this is no longer an issue. - See the resolution to 9.15. - - -9.20 Traversal Concepts and Tags -================================ - -:Submitter: Dave Abrahams -:Status: New - -Howard Hinnant pointed out some inconsistencies with the naming of -these tag types:: - - incrementable_iterator_tag // ++r, r++ - single_pass_iterator_tag // adds a == b, a != b - forward_traversal_iterator_tag // adds multi-pass - bidirectional_traversal_iterator_tag // adds --r, r-- - random_access_traversal_iterator_tag // adds r+n,n+r,etc. - -Howard thought that it might be better if all tag names contained -the word "traversal". It's not clear that would result in the best -possible names, though. For example, incrementable iterators can -only make a single pass over their input. What really distinguishes -single pass iterators from incrementable iterators is not that they -can make a single pass, but that they are equality -comparable. Forward traversal iterators really distinguish -themselves by introducing multi-pass capability. Without entering -a "Parkinson's Bicycle Shed" type of discussion, it might be worth -giving the names of these tags (and the associated concepts) some -extra attention. - -:Proposed resolution: Change the names of the traversal tags to the - following names:: - - incrementable_traversal_tag - single_pass_traversal_tag - forward_traversal_tag - bidirectional_traversal_tag - random_access_traversal_tag - - - In [lib.iterator.traversal]: - - - Change: - - +--------------------------------+-------------------------------+--------------------+ - |``traversal_category::type`` |Convertible to | | - | |``incrementable_iterator_tag`` | | - +--------------------------------+-------------------------------+--------------------+ - - to: - - +--------------------------------+-------------------------------+--------------------+ - |``iterator_traversal::type`` |Convertible to | | - | |``incrementable_traversal_tag``| | - +--------------------------------+-------------------------------+--------------------+ - - Change: - - +--------------------------------+-----------------------------+---------------------------+ - |``traversal_category::type`` |Convertible to | | - | |``single_pass_iterator_tag`` | | - +--------------------------------+-----------------------------+---------------------------+ - - to: - - +--------------------------------+-----------------------------+---------------------------+ - |``iterator_traversal::type`` |Convertible to | | - | |``single_pass_traversal_tag``| | - +--------------------------------+-----------------------------+---------------------------+ - - Change: - - +---------------------------------------+-----------------------------------+---------------+ - |``traversal_category::type`` |Convertible to | | - | |``forward_traversal_iterator_tag`` | | - +---------------------------------------+-----------------------------------+---------------+ - - to: - - +---------------------------------------+-----------------------------------+----------------------------+ - |``iterator_traversal::type`` |Convertible to | | - | |``forward_traversal_tag`` | | - +---------------------------------------+-----------------------------------+----------------------------+ - - Change: - - +------------------------------------+---------------------------------------------+---------------------+ - |``traversal_category::type`` |Convertible to | | - | |``bidirectional_traversal_iterator_tag`` | | - +------------------------------------+---------------------------------------------+---------------------+ - - to: - - +--------------------------------+-------------------------------+---------------------+ - |``iterator_traversal::type`` |Convertible to | | - | |``bidirectional_traversal_tag``| | - +--------------------------------+-------------------------------+---------------------+ - - Change: - - +-------------------------------------------+-------------------------------------------------+-------------------------+----------------------+ - |``traversal_category::type`` |Convertible to | | | - | |``random_access_traversal_iterator_tag`` | | | - +-------------------------------------------+-------------------------------------------------+-------------------------+----------------------+ - - to: - - +-------------------------------+---------------------------------+-------------------------+----------------------+ - |``iterator_traversal::type``|Convertible to | | | - | |``random_access_traversal_tag`` | | | - +-------------------------------+---------------------------------+-------------------------+----------------------+ - - - In [lib.iterator.synopsis], change:: - - struct incrementable_iterator_tag { }; - struct single_pass_iterator_tag : incrementable_iterator_tag { }; - struct forward_traversal_tag : single_pass_iterator_tag { }; - - to:: - - struct incrementable_traversal_tag { }; - struct single_pass_traversal_tag : incrementable_traversal_tag { }; - struct forward_traversal_tag : single_pass_traversal_tag { }; - - Remove:: - - struct null_category_tag { }; - struct input_output_iterator_tag : input_iterator_tag, output_iterator_tag {}; - - -9.21 iterator_facade Derived template argument underspecified -============================================================= - -:Submitter: Pete Becker -:Status: New - -The first template argument to iterator_facade is named Derived, -and the proposal says: - - The Derived template parameter must be a class derived from - iterator_facade. - -First, iterator_facade is a template, so cannot be derived -from. Rather, the class must be derived from a specialization of -iterator_facade. More important, isn't Derived required to be the -class that is being defined? That is, if I understand it right, the -definition of D here this is not valid:: - - class C : public iterator_facade { ... }; - class D : public iterator_facade { ... }; - -In the definition of D, the Derived argument to iterator_facade is -a class derived from a specialization of iterator_facade, so the -requirement is met. Shouldn't the requirement be more like "when -using iterator_facade to define an iterator class Iter, the class -Iter must be derived from a specialization of iterator_facade whose -first template argument is Iter." That's a bit awkward, but at the -moment I don't see a better way of phrasing it. - -:Proposed resolution: - - In [lib.iterator.facade] - - Remove: - - The ``Derived`` template parameter must be a class derived from - ``iterator_facade``. - - Change: - - The following table describes the other requirements on the - ``Derived`` parameter. Depending on the resulting iterator's - ``iterator_category``, a subset of the expressions listed in the table - are required to be valid. The operations in the first column must be - accessible to member functions of class ``iterator_core_access``. - - to: - - The following table describes the typical valid expressions on - ``iterator_facade``\ 's ``Derived`` parameter, depending on the - iterator concept(s) it will model. The operations in the first - column must be made accessible to member functions of class - ``iterator_core_access``. In addition, - ``static_cast(iterator_facade*)`` shall be well-formed. - - In [lib.iterator.adaptor] - - Change: - - The ``iterator_adaptor`` is a base class template derived from - an instantiation of ``iterator_facade``. - - to: - - Each specialization of the ``iterator_adaptor`` class template - is derived from a specialization of ``iterator_facade``. - - Change: - - The ``Derived`` template parameter must be a derived class of - ``iterator_adaptor``. - - To: - - ``static_cast(iterator_adaptor*)`` shall be well-formed. - -[Note: The proposed resolution to Issue 9.37 contains related -changes] - -9.22 return type of Iterator difference for iterator facade -=========================================================== - -:Submitter: Pete Becker -:Status: New - -The proposal says:: - - template - typename enable_if_interoperable::type - operator -(iterator_facade const& lhs, - iterator_facade const& rhs); - -Shouldn't the return type be one of the two iterator types? Which -one? The idea is that if one of the iterator types can be converted -to the other type, then the subtraction is okay. Seems like the -return type should then be the type that was converted to. Is that -right? - -:Proposed resolution: - - See resolution to 9.34. - -9.23 Iterator_facade: minor wording Issue -========================================= - -:Submitter: Pete Becker -:Status: New - -In the table that lists the required (sort of) member functions of -iterator types that are based on iterator_facade, the entry for -c.equal(y) says: - - true iff c and y refer to the same position. Implements c == y - and c != y. The second sentence is inside out. c.equal(y) does - not implement either of these operations. It is used to implement - them. Same thing in the description of c.distance_to(z). - -:Proposed resolution: remove "implements" descriptions from - table. See resolution to 9.34 - - -9.24 Use of undefined name in iterator_facade table -=================================================== - -:Submitter: Pete Becker -:Status: New - -Several of the descriptions use the name X without defining -it. This seems to be a carryover from the table immediately above -this section, but the text preceding that table says "In the table -below, X is the derived iterator type." Looks like the X:: -qualifiers aren't really needed; X::reference can simply be -reference, since that's defined by the iterator_facade -specialization itself. - -:Proposed resolution: - - Remove references to X. - - In [lib.iterator.facade] operations ``operator->() const;``: - - Change: - - :Returns: If ``X::reference`` is a reference type, an object - of type ``X::pointer`` equal to:: - - &static_cast(this)->dereference() - - Otherwise returns an object of unspecified type such that, - given an object ``a`` of type ``X``, ``a->m`` is equivalent - to ``(w = *a, w.m)`` for some temporary object ``w`` of type - ``X::value_type``. - - The type ``X::pointer`` is ``Value*`` if - ``is_writable_iterator::value`` is ``true``, and - ``Value const*`` otherwise. - - to: - - :Returns: If ``reference`` is a reference type, an object - of type ``pointer`` equal to:: - - &static_cast(this)->dereference() - - Otherwise returns an object of unspecified type such that, - ``(*static_cast(this))->m`` is equivalent - to ``(w = **static_cast(this), w.m)`` for - some temporary object ``w`` of type ``value_type``. - - Further changes are covered by issue 9.26. - -9.25 Iterator_facade: wrong return type -======================================= - -:Submitter: Pete Becker -:Status: New - -Several of the member functions return a Derived object or a -Derived&. Their Effects clauses end with:: - - return *this; - -This should be :: - - return *static_cast(this); - -:Proposed resolution: - - In [lib.iterator.facade], in the effects clause - of the following operations:: - - Derived& operator++() - Derived& operator--() - Derived& operator+=(difference_type n) - Derived& operator-=(difference_type n) - - Change: - ``return *this`` - - to: - ``return *static_cast(this);`` - -9.26 Iterator_facade: unclear returns clause for operator[] -=========================================================== - -:Submitter: Pete Becker -:Status: New - -The returns clause for ``operator[](difference_type n)`` const -says: - - Returns: an object convertible to X::reference and holding a copy - p of a+n such that, for a constant object v of type - X::value_type, X::reference(a[n] = v) is equivalent to p = v. - This needs to define 'a', but assuming it's supposed to be - ``*this`` (or maybe ``*(Derived*)this``), it still isn't clear - what this says. Presumably, the idea is that you can index off of - an iterator and assign to the result. But why the requirement - that it hold a copy of a+n? Granted, that's probably how it's - implemented, but it seems over-constrained. And the last phrase - seems wrong. p is an iterator; there's no requirement that you - can assign a value_type object to it. Should that be ``*p = v``? - But why the cast in reference(a[n] = v)? - -:Proposed resolution: - - In section operator[]: - - Change: - - Writable iterators built with ``iterator_facade`` implement - the semantics required by the preferred resolution to `issue - 299` and adopted by proposal `n1477`: the result of ``p[n]`` - is a proxy object containing a copy of ``p+n``, and ``p[n] = - x`` is equivalent to ``*(p + n) = x``. This approach will - work properly for any random-access iterator regardless of - the other details of its implementation. A user who knows - more about the implementation of her iterator is free to - implement an ``operator[]`` which returns an lvalue in the - derived iterator class; it will hide the one supplied by - ``iterator_facade`` from clients of her iterator. - - to: - - Writable iterators built with ``iterator_facade`` implement - the semantics required by the preferred resolution to `issue - 299` and adopted by proposal `n1550`: the result of ``p[n]`` - is an object convertible to the iterator's ``value_type``, - and ``p[n] = x`` is equivalent to ``*(p + n) = x`` (Note: - This result object may be implemented as a proxy containing a - copy of ``p+n``). This approach will work properly for any - random-access iterator regardless of the other details of its - implementation. A user who knows more about the - implementation of her iterator is free to implement an - ``operator[]`` that returns an lvalue in the derived iterator - class; it will hide the one supplied by ``iterator_facade`` - from clients of her iterator. - - In [lib.iterator.facade] operations: - - Change: - - :Returns: an object convertible to ``X::reference`` and - holding a copy *p* of ``a+n`` such that, for a constant - object ``v`` of type ``X::value_type``, ``X::reference(a[n] - = v)`` is equivalent to ``p = v``. - - to: - - :Returns: an object convertible to ``value_type``. For - constant objects ``v`` of type ``value_type``, and ``n`` of - type ``difference_type``, ``(*this)[n] = v`` is equivalent - to ``*(*this + n) = v``, and ``static_cast((*this)[n])`` is equivalent to - ``static_cast(*(*this + n))`` - - -9.27 Iterator_facade: redundant clause -====================================== - -:Submitter: Pete Becker -:Status: New - -``operator-`` has both an effects clause and a returns -clause. Looks like the returns clause should be removed. - -:Proposed resolution: - - Remove the returns clause. - - In [lib.iterator.facade] operations: - - Remove: - :Returns: ``static_cast(this)->advance(-n);`` - - - - -9.28 indirect_iterator: incorrect specification of default constructor -====================================================================== - -:Submitter: Pete Becker -:Status: New - -The default constructor returns "An instance of indirect_iterator -with a default constructed base object", but the constructor that -takes an Iterator object returns "An instance of indirect_iterator -with the iterator_adaptor subobject copy constructed from x." The -latter is the correct form, since it does not reach inside the base -class for its semantics. So the default constructor shoudl return -"An instance of indirect_iterator with a default-constructed -iterator_adaptor subobject." - -:Proposed resolution: - Change: - :Returns: An instance of ``indirect_iterator`` with - a default constructed base object. - - to: - :Returns: An instance of ``indirect_iterator`` with - a default-constructed ``m_iterator``. - -:Rationale: Inheritance from iterator_adaptor has been removed, so we instead - give the semantics in terms of the (exposition only) member - ``m_iterator``. - - -9.29 indirect_iterator: unclear specification of template constructor -===================================================================== - -:Submitter: Pete Becker -:Status: New - -The templated constructor that takes an indirect_iterator with a -different set of template arguments says that it returns "An -instance of indirect_iterator that is a copy of [the argument]". -But the type of the argument is different from the type of the -object being constructed, and there is no description of what -a "copy" means. The Iterator template parameter for the argument -must be convertible to the Iterator template parameter for the type -being constructed, which suggests that the argument's contained -Iterator object should be converted to the target type's Iterator -type. Is that what's meant here? -(Pete later writes: In fact, this problem is present in all of the -specialized adaptors that have a constructor like this: the -constructor returns "a copy" of the argument without saying what a -copy is.) - -:Proposed resolution: - - Change: - :Returns: An instance of ``indirect_iterator`` that is a copy of ``y``. - - to: - :Returns: An instance of ``indirect_iterator`` whose - ``m_iterator`` subobject is constructed from ``y.base()``. - - -:Rationale: Inheritance from iterator_adaptor has been removed, so we - instead give the semantics in terms of the member ``m_iterator``. - - -9.30 transform_iterator argument irregularity -============================================= - -:Submitter: Pete Becker -:Status: New - -The specialized adaptors that take both a Value and a Reference -template argument all take them in that order, i.e. Value precedes -Reference in the template argument list, with the exception of -transform_iterator, where Reference precedes Value. This seems like -a possible source of confusion. Is there a reason why this order is -preferable? - -:Proposed resolution: NAD - -:Rationale: defaults for Value depend on Reference. A sensible - Value can almost always be computed from Reference. The first - parameter is UnaryFunction, so the argument order is already - different from the other adapters. - - -9.31 function_output_iterator overconstrained -============================================= - -:Submitter: Pete Becker -:Status: New - -function_output_iterator requirements says: "The UnaryFunction must -be Assignable, Copy Constructible, and the expression f(x) must be -valid, where f is an object of type UnaryFunction and x is an -object of a type accepted by f." - -Everything starting with "and," somewhat reworded, is actually a -constraint on output_proxy::operator=. All that's needed to create -a function_output_iterator object is that the UnaryFunction type be -Assignable and CopyConstructible. That's also sufficient to -dereference and to increment such an object. It's only when you try -to assign through a dereferenced iterator that f(x) has to work, -and then only for the particular function object that the iterator -holds and for the particular value that is being assigned. - -:Proposed resolution: - - Change: - ``output_proxy operator*();`` - - to: - ``/* see below */ operator*();`` - - After ``function_output_iterator& operator++(int);`` add:: - - private: - UnaryFunction m_f; // exposition only - - Change: - The ``UnaryFunction`` must be Assignable, Copy Constructible, - and the expression ``f(x)`` must be valid, where ``f`` is an - object of type ``UnaryFunction`` and ``x`` is an object of a - type accepted by ``f``. The resulting - ``function_output_iterator`` is a model of the Writable and - Incrementable Iterator concepts. - - to: - ``UnaryFunction`` must be Assignable and Copy Constructible. - - After the requirements section, add: - -.. topic:: ``function_output_iterator`` models - - ``function_output_iterator`` is a model of the Writable and - Incrementable Iterator concepts. - - Change: - :Returns: An instance of ``function_output_iterator`` with - ``f`` stored as a data member. - - to: - :Effects: Constructs an instance of ``function_output_iterator`` - with ``m_f`` constructed from ``f``. - - Change: - ``output_proxy operator*();`` - - :Returns: An instance of ``output_proxy`` constructed with - a copy of the unary function ``f``. - - to: - ``operator*();`` - - :Returns: An object ``r`` of unspecified type such that ``r = t`` - is equivalent to ``m_f(t)`` for all ``t``. - - - Remove: - ``function_output_iterator::output_proxy`` operations - - ``output_proxy(UnaryFunction& f);`` - - :Returns: An instance of ``output_proxy`` with ``f`` stored as - a data member. - - - ``template output_proxy& operator=(const T& value);`` - - :Effects: - :: - - m_f(value); - return *this; - - - -9.32 Should output_proxy really be a named type? -================================================ - -:Submitter: Pete Becker -:Status: New - -This means someone can store an output_proxy object for later use, -whatever that means. It also constrains output_proxy to hold a copy -of the function object, rather than a pointer to the iterator -object. Is all this mechanism really necessary? - -:Proposed resolution: See issue 9.31. - - - -9.33 istreambuf_iterator isn't a Readable Iterator -================================================== - -:Submitter: Pete Becker -:Status: New - -c++std-lib-12333: - - N1550 requires that for a Readable Iterator a of type X, ``*a`` - returns an object of type - ``iterator_traits::reference``. ``istreambuf_iterator::operator*`` - returns ``charT``, but ``istreambuf_iterator::reference`` is - ``charT&``. So am I overlooking something, or is - ``istreambuf_iterator`` not Readable. - -:Proposed resolution: Remove all constraints on - ``iterator_traits::reference`` in Readable Iterator and Lvalue - Iterator. Change Lvalue Iterator to refer to ``T&`` instead of - ``iterator_traits::reference``. - - Change: - A class or built-in type ``X`` models the *Readable Iterator* - concept for the value type ``T`` if the following expressions - are valid and respect the stated semantics. ``U`` is the type - of any specified member of type ``T``. - - to: - A class or built-in type ``X`` models the *Readable Iterator* - concept for value type ``T`` if, in addition to ``X`` being - Assignable and Copy Constructible, the following expressions - are valid and respect the stated semantics. ``U`` is the type - of any specified member of type ``T``. - - From the Input Iterator Requirements table, remove: - - +-----------------------------------+-----------------------------------+-------------------------+ - |``iterator_traits::reference`` |Convertible to | | - | |``iterator_traits::value_type`` | | - +-----------------------------------+-----------------------------------+-------------------------+ - - Change: - - +-----------------------------------+-----------------------------------+-------------------------+ - |``*a`` |``iterator_traits::reference`` |pre: ``a`` is | - | | |dereferenceable. If ``a | - | | |== b`` then ``*a`` is | - | | |equivalent to ``*b`` | - +-----------------------------------+-----------------------------------+-------------------------+ - - to: - - +-----------------------------------+------------------------+----------------------------------------------------------------+ - |``*a`` | Convertible to ``T`` |pre: ``a`` is dereferenceable. If ``a == b`` then ``*a`` | - | | | is equivalent to ``*b``. | - +-----------------------------------+------------------------+----------------------------------------------------------------+ - - Change: - The *Lvalue Iterator* concept adds the requirement that the - ``reference`` type be a reference to the value type of the - iterator. - - to: - The *Lvalue Iterator* concept adds the requirement that the - return type of ``operator*`` type be a reference to the value - type of the iterator. - - Change: - - +---------------------------------------------------------------------------------+ - | Lvalue Iterator Requirements | - +---------------------------------+-----------+-----------------------------------+ - |Expression |Return Type|Assertion | - +=================================+===========+===================================+ - |``iterator_traits::reference``|``T&`` |``T`` is *cv* | - | | |``iterator_traits::value_type`` | - | | |where *cv* is an optional | - | | |cv-qualification | - +---------------------------------+-----------+-----------------------------------+ - - to: - - +-------------------------------------------------------------+ - | Lvalue Iterator Requirements | - +-------------+-----------+-----------------------------------+ - |Expression |Return Type|Note/Assertion | - +=============+===========+===================================+ - |``*a`` | ``T&`` |``T`` is *cv* | - | | |``iterator_traits::value_type`` | - | | |where *cv* is an optional | - | | |cv-qualification. | - | | |pre: ``a`` is | - | | |dereferenceable. If ``a | - | | |== b`` then ``*a`` is | - | | |equivalent to ``*b``. | - +-------------+-----------+-----------------------------------+ - - - -:Rationale: Ideally there should be requirements on the reference - type, however, since Readable Iterator is suppose to correspond - to the current standard iterator requirements (which do not place - requirements on the reference type) we will leave them off for - now. There is a DR in process with respect to the reference type - in the stadard iterator requirements. Once that is resolved we - will revisit this issue for Readable Iterator and Lvalue - Iterator. - - We added Assignable to the requirements for Readable - Iterator. This is needed to have Readable Iterator coincide with - the capabilities of Input Iterator. - - -9.34 iterator_facade free functions unspecified -=============================================== - -:Submitter: Pete Becker -:Status: New - -c++std-lib-12562: - - The template functions ``operator==``, ``operator!=``, - ``operator<``, ``operator<=``, ``operator>``, ``operator>=``, and - ``operator-`` that take two arguments that are specializations of - iterator_facade have no specification. The template function - operator+ that takes an argument that is a specialization of - iterator_facade and an argument of type difference_type has no - specification. - -:Proposed resolution: - Add the missing specifications. - - :: - - template - Derived operator+ (iterator_facade const&, - typename Derived::difference_type n); - - template - Derived operator+ (typename Derived::difference_type n, - iterator_facade const&); - - :Effects: - :: - - Derived tmp(static_cast(this)); - return tmp += n; - - - :: - - template - typename enable_if_interoperable::type - operator ==(iterator_facade const& lhs, - iterator_facade const& rhs); - - :Returns: if ``is_convertible::value``, then - ``lhs.equal(rhs)``. Otherwise, ``rhs.equal(lhs)``. - - :: - - template - typename enable_if_interoperable::type - operator !=(iterator_facade const& lhs, - iterator_facade const& rhs); - - :Returns: if ``is_convertible::value``, then - ``!lhs.equal(rhs)``. Otherwise, ``!rhs.equal(lhs)``. - - :: - - template - typename enable_if_interoperable::type - operator <(iterator_facade const& lhs, - iterator_facade const& rhs); - - :Returns: if ``is_convertible::value``, then - ``lhs.distance_to(rhs) < 0``. Otherwise, ``rhs.distance_to(lhs) > - 0``. - - :: - - template - typename enable_if_interoperable::type - operator <=(iterator_facade const& lhs, - iterator_facade const& rhs); - - :Returns: if ``is_convertible::value``, then - ``lhs.distance_to(rhs) <= 0``. Otherwise, ``rhs.distance_to(lhs) - >= 0``. - - :: - - template - typename enable_if_interoperable::type - operator >(iterator_facade const& lhs, - iterator_facade const& rhs); - - :Returns: if ``is_convertible::value``, then - ``lhs.distance_to(rhs) > 0``. Otherwise, - ``rhs.distance_to(lhs) < 0``. - - - :: - - template - typename enable_if_interoperable::type - operator >=(iterator_facade const& lhs, - iterator_facade const& rhs); - - :Returns: if ``is_convertible::value``, then - ``lhs.distance_to(rhs) >= 0``. Otherwise, - ``rhs.distance_to(lhs) <= 0``. - - :: - - template - typename enable_if_interoperable::type - operator -(iterator_facade const& lhs, - iterator_facade const& rhs); - - :Return Type: if ``is_convertible::value``, then - ``difference`` shall be - ``iterator_traits::difference_type``. Otherwise, - ``difference`` shall be - ``iterator_traits::difference_type``. - - :Returns: if ``is_convertible::value``, then - ``-lhs.distance_to(rhs)``. Otherwise, - ``rhs.distance_to(lhs)``. - - - -9.35 iterator_facade: too many equals? -====================================== - -:Submitter: Pete Becker -:Status: New - -c++std-lib-12563: - - The table listing the functions required for types derived from - iterator_facade has two functions named equal and two named - distance_to:: - - c.equal(b) - c.equal(y) - c.distance_to(b) - c.distance_to(z) - - where b and c are const objects of the derived type, y and z are - constant objects of certain iterator types that are interoperable - with the derived type. Seems like the 'b' versions are - redundant: in both cases, the other version will take a 'b'. In - fact, iterator_adaptor is specified to use iterator_facade, but - does not provide the 'b' versions of these functions. - - Are the 'b' versions needed? - -:Proposed resolution: Remove the 'b' versions. - - In ``iterator_facade`` requirements, remove: - - +--------------------+-------------------+-------------------------------------+---------------------------+ - |``c.equal(b)`` |convertible to bool|true iff ``b`` and ``c`` are |Single Pass Iterator | - | | |equivalent. | | - +--------------------+-------------------+-------------------------------------+---------------------------+ - - and remove: - - +--------------------+-------------------+-------------------------------------+---------------------------+ - |``c.distance_to(b)``|convertible to |equivalent to ``distance(c, b)`` |Random Access Traversal | - | |X::difference_type | |Iterator | - +--------------------+-------------------+-------------------------------------+---------------------------+ - - -9.36 iterator_facade function requirements -========================================== - -:Submitter: Pete Becker -:Status: New - -c++std-lib-12636: - - The table that lists required functions for the derived type X - passed to iterator_facade lists, among others: - - for a single pass iterator:: - - c.equal(b) - c.equal(y) - - where b and c are const X objects, and y is a const object of a - single pass iterator that is interoperable with X. Since X is - interoperable with itself, c.equal(b) is redundant. There is a - difference in their descriptions, but its meaning isn't - clear. The first is "true iff b and c are equivalent", and the - second is "true iff c and y refer to the same position." Is there - a difference between the undefined term "equivalent" and "refer - to the same position"? - - Similarly, for a random access traversal iterator:: - - c.distance_to(b) - c.distance_to(z) - - where z is a constant object of a random access traversal - iterator that is interoperable with X. Again, X is interoperable - with itself, so c.distance_to(b) is redundant. Also, the - specification for c.distance_to(z) isn't valid. It's written - as "equivalent to distance(c, z)". The template function distance - takes two arguments of the same type, so distance(c, z) isn't - valid if c and z are different types. Should it be - distance(c, (X)z)? - -:Proposed resolution: Removed the 'b' versions (see 9.35) and added the cast. - - Change: - - +--------------------+-------------------+-------------------------------------+---------------------------+ - |``c.distance_to(z)``|convertible to |equivalent to ``distance(c, z)``. |Random Access Traversal | - | |X::difference_type |Implements ``c - z``, ``c < z``, ``c |Iterator | - | | |<= z``, ``c > z``, and ``c >= c``. | | - +--------------------+-------------------+-------------------------------------+---------------------------+ - - to: - - +--------------------+----------------------+-------------------------+---------------------------+ - |``c.distance_to(z)``|convertible to |equivalent to |Random Access Traversal | - | |``F::difference_type``|``distance(c, X(z))``. |Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - - - -==================================== - More Issues (not from Matt's list) -==================================== - - - -9.37x Inheritance in iterator_adaptor and other adaptors is an overspecification -================================================================================ - -:Submitter: Pete Becker -:Status: New - -c++std-lib-12696: -The paper requires that iterator_adaptor be derived from an -appropriate instance of iterator_facade, and that most of the specific -forms of adaptors be derived from appropriate instances of -iterator_adaptor. That seems like overspecification, and we ought to -look at specifying these things in terms of what the various templates -provide rather than how they're implemented. - -:Proposed resolution: - - Remove the specfication of inheritance, and add explicit - specification of all the functionality that was inherited from the - specialized iterators. - - In iterator_adaptor, inheritance is retained, sorry NAD. Also, - the Interoperable Iterators concept is added to the new iterator - concepts, and this concept is used in the specification of the - iterator adaptors. - - - In n1550, after [lib.random.access.traversal.iterators], add: - - Interoperable Iterators [lib.interoperable.iterators] - - A class or built-in type ``X`` that models Single Pass Iterator - is *interoperable with* a class or built-in type ``Y`` that - also models Single Pass Iterator if the following expressions - are valid and respect the stated semantics. In the tables - below, ``x`` is an object of type ``X``, ``y`` is an object of - type ``Y``, ``Distance`` is - ``iterator_traits::difference_type``, and ``n`` represents a - constant object of type ``Distance``. - - +-----------+-----------------------+---------------------------------------------------+ - |Expression |Return Type |Assertion/Precondition/Postcondition | - +===========+=======================+===================================================+ - |``y = x`` |``Y`` |post: ``y == x`` | - +-----------+-----------------------+---------------------------------------------------+ - |``Y(x)`` |``Y`` |post: ``Y(x) == x`` | - +-----------+-----------------------+---------------------------------------------------+ - |``x == y`` |convertible to ``bool``|``==`` is an equivalence relation over its domain. | - +-----------+-----------------------+---------------------------------------------------+ - |``y == x`` |convertible to ``bool``|``==`` is an equivalence relation over its domain. | - +-----------+-----------------------+---------------------------------------------------+ - |``x != y`` |convertible to ``bool``|``bool(a==b) != bool(a!=b)`` over its domain. | - +-----------+-----------------------+---------------------------------------------------+ - |``y != x`` |convertible to ``bool``|``bool(a==b) != bool(a!=b)`` over its domain. | - +-----------+-----------------------+---------------------------------------------------+ - - If ``X`` and ``Y`` both model Random Access Traversal Iterator then - the following additional requirements must be met. - - +-----------+-----------------------+---------------------+--------------------------------------+ - |Expression |Return Type |Operational Semantics|Assertion/ Precondition | - +===========+=======================+=====================+======================================+ - |``x < y`` |convertible to ``bool``|``y - x > 0`` |``<`` is a total ordering relation | - +-----------+-----------------------+---------------------+--------------------------------------+ - |``y < x`` |convertible to ``bool``|``x - y > 0`` |``<`` is a total ordering relation | - +-----------+-----------------------+---------------------+--------------------------------------+ - |``x > y`` |convertible to ``bool``|``y < x`` |``>`` is a total ordering relation | - +-----------+-----------------------+---------------------+--------------------------------------+ - |``y > x`` |convertible to ``bool``|``x < y`` |``>`` is a total ordering relation | - +-----------+-----------------------+---------------------+--------------------------------------+ - |``x >= y`` |convertible to ``bool``|``!(x < y)`` | | - +-----------+-----------------------+---------------------+--------------------------------------+ - |``y >= x`` |convertible to ``bool``|``!(y < x)`` | | - +-----------+-----------------------+---------------------+--------------------------------------+ - |``x <= y`` |convertible to ``bool``|``!(x > y)`` | | - +-----------+-----------------------+---------------------+--------------------------------------+ - |``y <= x`` |convertible to ``bool``|``!(y > x)`` | | - +-----------+-----------------------+---------------------+--------------------------------------+ - |``y - x`` |``Distance`` |``distance(Y(x),y)`` |pre: there exists a value ``n`` of | - | | | |``Distance`` such that ``x + n == y``.| - | | | |``y == x + (y - x)``. | - +-----------+-----------------------+---------------------+--------------------------------------+ - |``x - y`` |``Distance`` |``distance(y,Y(x))`` |pre: there exists a value ``n`` of | - | | | |``Distance`` such that ``y + n == x``.| - | | | |``x == y + (x - y)``. | - +-----------+-----------------------+---------------------+--------------------------------------+ - - - - In N1530: - - In [lib.iterator.adaptor] - - Change:: - - class iterator_adaptor - : public iterator_facade - - To:: - - class iterator_adaptor - : public iterator_facade // see details - - - Change the text from: - The ``Base`` type must implement the expressions involving - ``m_iterator`` in the specifications... - - until the end of the **iterator_adaptor requirements** section, to: - The ``Base`` argument shall be Assignable and Copy Constructible. - - - Add: - -.. topic:: ``iterator_adaptor`` base class parameters - - The *V'*, *C'*, *R'*, and *D'* parameters of the ``iterator_facade`` - used as a base class in the summary of ``iterator_adaptor`` - above are defined as follows: - - .. parsed-literal:: - - *V'* = if (Value is use_default) - return iterator_traits::value_type - else - return Value - - *C'* = if (CategoryOrTraversal is use_default) - return iterator_traversal::type - else - return CategoryOrTraversal - - *R'* = if (Reference is use_default) - if (Value is use_default) - return iterator_traits::reference - else - return Value& - else - return Reference - - *D'* = if (Difference is use_default) - return iterator_traits::difference_type - else - return Difference - - - In [lib.iterator.special.adaptors] - - Change:: - - class indirect_iterator - : public iterator_adaptor - { - friend class iterator_core_access; - - to:: - - class indirect_iterator - { - public: - typedef /* see below */ value_type; - typedef /* see below */ reference; - typedef /* see below */ pointer; - typedef /* see below */ difference_type; - typedef /* see below */ iterator_category; - - Change:: - - private: // as-if specification - typename indirect_iterator::reference dereference() const - { - return **this->base(); - } - - to:: - - Iterator const& base() const; - reference operator*() const; - indirect_iterator& operator++(); - indirect_iterator& operator--(); - private: - Iterator m_iterator; // exposition - - - After the synopsis add: - - The member types of ``indirect_iterator`` are defined - according to the following pseudo-code, where ``V`` is - ``iterator_traits::value_type`` - - .. parsed-literal:: - - if (Value is use_default) then - typedef remove_const::type>::type value_type; - else - typedef remove_const::type value_type; - - if (Reference is use_default) then - if (Value is use_default) then - typedef indirect_reference::type reference; - else - typedef Value& reference; - else - typedef Reference reference; - - if (Value is use_default) then - typedef pointee::type\* pointer; - else - typedef Value\* pointer; - - if (Difference is use_default) - typedef iterator_traits::difference_type difference_type; - else - typedef Difference difference_type; - - if (CategoryOrTraversal is use_default) - typedef |iterator-category|\ ( - iterator_traversal::type,``reference``,``value_type`` - ) iterator_category; - else - typedef |iterator-category|\ ( - CategoryOrTraversal,``reference``,``value_type`` - ) iterator_category; - - - [Note: See resolution to 9.44y for a description of ``pointee`` and - ``indirect_reference``] - - After the requirements section, add: - -.. topic:: ``indirect_iterator`` models - - - In addition to the concepts indicated by ``iterator_category`` - and by ``iterator_traversal::type``, a - specialization of ``indirect_iterator`` models the following - concepts, Where ``v`` is an object of - ``iterator_traits::value_type``: - - * Readable Iterator if ``reference(*v)`` is convertible to - ``value_type``. - - * Writable Iterator if ``reference(*v) = t`` is a valid - expression (where ``t`` is an object of type - ``indirect_iterator::value_type``) - - * Lvalue Iterator if ``reference`` is a reference type. - - ``indirect_iterator`` is interoperable with - ``indirect_iterator`` if and only if ``X`` is - interoperable with ``Y``. - - - Before ``indirect_iterator();`` add: - - In addition to the operations required by the concepts described - above, specializations of ``indirect_iterator`` provide the - following operations. - - Change: - :Returns: An instance of ``indirect_iterator`` with - the ``iterator_adaptor`` subobject copy constructed from ``x``. - - to: - :Returns: An instance of ``indirect_iterator`` with - ``m_iterator`` copy constructed from ``x``. - - - At the end of the indirect_iterator operations add: - - ``Iterator const& base() const;`` - - :Returns: ``m_iterator`` - - - ``reference operator*() const;`` - - :Returns: ``**m_iterator`` - - - ``indirect_iterator& operator++();`` - - :Effects: ``++m_iterator`` - :Returns: ``*this`` - - - ``indirect_iterator& operator--();`` - - :Effects: ``--m_iterator`` - :Returns: ``*this`` - - - - Change:: - - template - class reverse_iterator : - public iterator_adaptor< reverse_iterator, Iterator > - { - friend class iterator_core_access; - - to:: - - template - class reverse_iterator - { - public: - typedef iterator_traits::value_type value_type; - typedef iterator_traits::reference reference; - typedef iterator_traits::pointer pointer; - typedef iterator_traits::difference_type difference_type; - typedef /* see below */ iterator_category; - - Change:: - - private: // as-if specification - typename reverse_iterator::reference dereference() const { return *prior(this->base()); } - - void increment() { --this->base_reference(); } - void decrement() { ++this->base_reference(); } - - void advance(typename reverse_iterator::difference_type n) - { - this->base_reference() += -n; - } - - template - typename reverse_iterator::difference_type - distance_to(reverse_iterator const& y) const - { - return this->base_reference() - y.base(); - } - - to:: - - Iterator const& base() const; - reference operator*() const; - reverse_iterator& operator++(); - reverse_iterator& operator--(); - private: - Iterator m_iterator; // exposition - - After the synopsis for ``reverse_iterator``, add: - If ``Iterator`` models Random Access Traversal Iterator and Readable - Lvalue Iterator, then ``iterator_category`` is convertible to - ``random_access_iterator_tag``. Otherwise, if - ``Iterator`` models Bidirectional Traversal Iterator and Readable - Lvalue Iterator, then ``iterator_category`` is convertible to - ``bidirectional_iterator_tag``. Otherwise, ``iterator_category`` is - convertible to ``input_iterator_tag``. - - - Change: - **reverse_iterator requirements** - - The base ``Iterator`` must be a model of Bidirectional Traversal - Iterator. The resulting ``reverse_iterator`` will be a model of the - most refined standard traversal and access concepts that are modeled - by ``Iterator``. - - - to: - **reverse_iterator requirements** - - ``Iterator`` must be a model of Bidirectional Traversal Iterator. - - -.. topic:: ``reverse_iterator`` models - - A specialization of ``reverse_iterator`` models the same iterator - traversal and iterator access concepts modeled by its ``Iterator`` - argument. In addition, it may model old iterator concepts - specified in the following table: - - +---------------------------------------+-----------------------------------+ - | If ``I`` models |then ``reverse_iterator`` models| - +=======================================+===================================+ - | Readable Lvalue Iterator, | Bidirectional Iterator | - | Bidirectional Traversal Iterator | | - +---------------------------------------+-----------------------------------+ - | Writable Lvalue Iterator, | Mutable Bidirectional Iterator | - | Bidirectional Traversal Iterator | | - +---------------------------------------+-----------------------------------+ - | Readable Lvalue Iterator, | Random Access Iterator | - | Random Access Traversal Iterator | | - +---------------------------------------+-----------------------------------+ - | Writable Lvalue Iterator, | Mutable Random Access Iterator | - | Random Access Traversal Iterator | | - +---------------------------------------+-----------------------------------+ - - - ``reverse_iterator`` is interoperable with - ``reverse_iterator`` if and only if ``X`` is interoperable with - ``Y``. - - Change: - :Returns: An instance of ``reverse_iterator`` with a - default constructed base object. - - to: - :Effects: Constructs an instance of ``reverse_iterator`` with ``m_iterator`` - default constructed. - - Change: - :Effects: Constructs an instance of ``reverse_iterator`` with a - base object copy constructed from ``x``. - - to: - :Effects: Constructs an instance of ``reverse_iterator`` with a - ``m_iterator`` constructed from ``x``. - - - Change: - :Returns: An instance of ``reverse_iterator`` that is a copy of ``r``. - - to: - :Effects: Constructs instance of ``reverse_iterator`` whose - ``m_iterator`` subobject is constructed from ``y.base()``. - - - - At the end of the operations for ``reverse_iterator``, add: - ``Iterator const& base() const;`` - - :Returns: ``m_iterator`` - - - ``reference operator*() const;`` - - :Effects: - - :: - - Iterator tmp = m_iterator; - return *--tmp; - - - ``reverse_iterator& operator++();`` - - :Effects: ``--m_iterator`` - :Returns: ``*this`` - - - ``reverse_iterator& operator--();`` - - :Effects: ``++m_iterator`` - :Returns: ``*this`` - - - - Change:: - - class transform_iterator - : public iterator_adaptor - { - friend class iterator_core_access; - - to:: - - class transform_iterator - { - public: - typedef /* see below */ value_type; - typedef /* see below */ reference; - typedef /* see below */ pointer; - typedef iterator_traits::difference_type difference_type; - typedef /* see below */ iterator_category; - - - After ``UnaryFunction functor() const;`` add:: - - Iterator const& base() const; - reference operator*() const; - transform_iterator& operator++(); - transform_iterator& operator--(); - - Change:: - - private: - typename transform_iterator::value_type dereference() const; - UnaryFunction m_f; - }; - - to:: - - private: - Iterator m_iterator; // exposition only - UnaryFunction m_f; // exposition only - }; - - - After the synopsis, add: - If ``Iterator`` models Readable Lvalue Iterator and if ``Iterator`` - models Random Access Traversal Iterator, then ``iterator_category`` is - convertible to ``random_access_iterator_tag``. Otherwise, if - ``Iterator`` models Bidirectional Traversal Iterator, then - ``iterator_category`` is convertible to - ``bidirectional_iterator_tag``. Otherwise ``iterator_category`` is - convertible to ``forward_iterator_tag``. If ``Iterator`` does not - model Readable Lvalue Iterator then ``iterator_category`` is - convertible to ``input_iterator_tag``. - - - In the requirements section, change: - The type ``Iterator`` must at least model Readable Iterator. The - resulting ``transform_iterator`` models the most refined of the - following that is also modeled by ``Iterator``. - - * Writable Lvalue Iterator if - ``result_of::reference)>::type`` - is a non-const reference. - - * Readable Lvalue Iterator if - ``result_of::reference)>::type`` - is a const reference. - - * Readable Iterator otherwise. - - - The ``transform_iterator`` models the most refined standard traversal - concept that is modeled by ``Iterator``. - - The ``reference`` type of ``transform_iterator`` is - ``result_of::reference)>::type``. - The ``value_type`` is ``remove_cv >::type``. - - to: - The argument ``Iterator`` shall model Readable Iterator. - - - After the requirements section, add: - -.. topic:: ``transform_iterator`` models - - The resulting ``transform_iterator`` models the most refined of the - following options that is also modeled by ``Iterator``. - - * Writable Lvalue Iterator if - ``transform_iterator::reference`` is a non-const - reference. - - * Readable Lvalue Iterator if - ``transform_iterator::reference`` is a const reference. - - * Readable Iterator otherwise. - - The ``transform_iterator`` models the most refined standard traversal - concept that is modeled by the ``Iterator`` argument. - - If ``transform_iterator`` is a model of Readable Lvalue Iterator then - it models the following original iterator concepts depending on what - the ``Iterator`` argument models. - - +-----------------------------------+-----------------------------------+ - | If ``Iterator`` models |then ``transform_iterator`` models | - +===================================+===================================+ - | Single Pass Iterator | Input Iterator | - +-----------------------------------+-----------------------------------+ - | Forward Traversal Iterator | Forward Iterator | - +-----------------------------------+-----------------------------------+ - | Bidirectional Traversal Iterator | Bidirectional Iterator | - +-----------------------------------+-----------------------------------+ - | Random Access Traversal Iterator | Random Access Iterator | - +-----------------------------------+-----------------------------------+ - - If ``transform_iterator`` models Writable Lvalue Iterator then it is a - mutable iterator (as defined in the old iterator requirements). - - ``transform_iterator`` is interoperable with - ``transform_iterator`` if and only if ``X`` is - interoperable with ``Y``. - - - Remove the private operations section heading and remove:: - - ``typename transform_iterator::value_type dereference() const;`` - - :Returns: ``m_f(transform_iterator::dereference());`` - - After the entry for ``functor()``, add:: - - ``Iterator const& base() const;`` - - :Returns: ``m_iterator`` - - - ``reference operator*() const;`` - - :Returns: ``m_f(*m_iterator)`` - - - ``transform_iterator& operator++();`` - - :Effects: ``++m_iterator`` - :Returns: ``*this`` - - - ``transform_iterator& operator--();`` - - :Effects: ``--m_iterator`` - :Returns: ``*this`` - - - Change:: - - template - class filter_iterator - : public iterator_adaptor< - filter_iterator, Iterator - , use_default - , /* see details */ - > - { - public: - - to:: - - template - class filter_iterator - { - public: - typedef iterator_traits::value_type value_type; - typedef iterator_traits::reference reference; - typedef iterator_traits::pointer pointer; - typedef iterator_traits::difference_type difference_type; - typedef /* see below */ iterator_category; - - Change:: - - private: // as-if specification - void increment() - { - ++(this->base_reference()); - satisfy_predicate(); - } - - void satisfy_predicate() - { - while (this->base() != this->m_end && !this->m_predicate(*this->base())) - ++(this->base_reference()); - } - - Predicate m_predicate; - Iterator m_end; - - to:: - - Iterator const& base() const; - reference operator*() const; - filter_iterator& operator++(); - private: - Predicate m_pred; // exposition only - Iterator m_iter; // exposition only - Iterator m_end; // exposition only - - - - Change: - The base ``Iterator`` parameter must be a model of Readable - Iterator and Single Pass Iterator. The resulting - ``filter_iterator`` will be a model of Forward Traversal Iterator - if ``Iterator`` is, otherwise the ``filter_iterator`` will be a - model of Single Pass Iterator. The access category of the - ``filter_iterator`` will be the same as the access category of - ``Iterator``. - - to: - The ``Iterator`` argument shall meet the requirements of Readable - Iterator and Single Pass Iterator or it shall meet the requirements of - Input Iterator. - - After the requirements section, add: - -.. topic:: ``filter_iterator`` models - - The concepts that ``filter_iterator`` models are dependent on which - concepts the ``Iterator`` argument models, as specified in the - following tables. - - +-----------------------------+----------------------------------------------------------+ - | If ``Iterator`` models | then ``filter_iterator`` models | - +=============================+==========================================================+ - | Single Pass Iterator | Single Pass Iterator | - +-----------------------------+----------------------------------------------------------+ - | Forward Traversal Iterator | Forward Traversal Iterator | - +-----------------------------+----------------------------------------------------------+ - - +--------------------------------+----------------------------------------------+ - | If ``Iterator`` models | then ``filter_iterator`` models | - +================================+==============================================+ - | Readable Iterator | Readable Iterator | - +--------------------------------+----------------------------------------------+ - | Writable Iterator | Writable Iterator | - +--------------------------------+----------------------------------------------+ - | Lvalue Iterator | Lvalue Iterator | - +--------------------------------+----------------------------------------------+ - - +-------------------------------------------------------+---------------------------------+ - | If ``Iterator`` models | then ``filter_iterator`` models | - +=======================================================+=================================+ - | Readable Iterator, Single Pass Iterator | Input Iterator | - +-------------------------------------------------------+---------------------------------+ - | Readable Lvalue Iterator, Forward Traversal Iterator | Forward Iterator | - +-------------------------------------------------------+---------------------------------+ - | Writable Lvalue Iterator, Forward Traversal Iterator | Mutable Forward Iterator | - +-------------------------------------------------------+---------------------------------+ - - - ``filter_iterator`` is interoperable with ``filter_iterator`` - if and only if ``X`` is interoperable with ``Y``. - - - Change: - :Returns: a ``filter_iterator`` whose - predicate is a default constructed ``Predicate`` and - whose ``end`` is a default constructed ``Iterator``. - - to: - :Effects: Constructs a ``filter_iterator`` whose``m_pred``, ``m_iter``, and ``m_end`` - members are a default constructed. - - Change: - :Returns: A ``filter_iterator`` at position ``x`` that filters according - to predicate ``f`` and that will not increment past ``end``. - - to: - :Effects: Constructs a ``filter_iterator`` where ``m_iter`` is either - the first position in the range ``[x,end)`` such that ``f(*m_iter) == true`` - or else``m_iter == end``. The member ``m_pred`` is constructed from - ``f`` and ``m_end`` from ``end``. - - Change: - :Returns: A ``filter_iterator`` at position ``x`` that filters - according to a default constructed ``Predicate`` - and that will not increment past ``end``. - - to: - :Effects: Constructs a ``filter_iterator`` where ``m_iter`` is either - the first position in the range ``[x,end)`` such that ``m_pred(*m_iter) == true`` - or else``m_iter == end``. The member ``m_pred`` is default constructed. - - - Change: - :Returns: A copy of iterator ``t``. - - to: - :Effects: Constructs a filter iterator whose members are copied from ``t``. - - Change: - :Returns: A copy of the predicate object used to construct ``*this``. - - to: - :Returns: ``m_pred`` - - Change: - :Returns: The object ``end`` used to construct ``*this``. - - to: - :Returns: ``m_end`` - - At the end of the operations section, add: - - ``reference operator*() const;`` - - :Returns: ``*m_iter`` - - - ``filter_iterator& operator++();`` - - :Effects: Increments ``m_iter`` and then continues to - increment ``m_iter`` until either ``m_iter == m_end`` - or ``m_pred(*m_iter) == true``. - :Returns: ``*this`` - - - Change:: - - class counting_iterator - : public iterator_adaptor< - counting_iterator - , Incrementable - , Incrementable - , Access - , /* see details for traversal category */ - , Incrementable const& - , Incrementable const* - , /* distance = Difference or a signed integral type */> - { - friend class iterator_core_access; - public: - - to:: - - class counting_iterator - { - public: - typedef Incrementable value_type; - typedef const Incrementable& reference; - typedef const Incrementable* pointer; - typedef /* see below */ difference_type; - typedef /* see below */ iterator_category; - - - - Change:: - - private: - typename counting_iterator::reference dereference() const - { - return this->base_reference(); - } - - to:: - - Incrementable const& base() const; - reference operator*() const; - counting_iterator& operator++(); - counting_iterator& operator--(); - private: - Incrementable m_inc; // exposition - - After the synopsis, add: - - If the ``Difference`` argument is ``use_default`` then - ``difference_type`` is an unspecified signed integral - type. Otherwise ``difference_type`` is ``Difference``. - - ``iterator_category`` is determined according to the following - algorithm: - - .. parsed-literal:: - - if (CategoryOrTraversal is not use_default) - return CategoryOrTraversal - else if (numeric_limits::is_specialized) - return |iterator-category|\ ( - random_access_traversal_tag, Incrementable, const Incrementable&) - else - return |iterator-category|\ ( - iterator_traversal::type, - Incrementable, const Incrementable&) - - - - Change: - [*Note:* implementers are encouraged to provide an implementation of - ``distance_to`` and a ``difference_type`` that avoids overflows in - the cases when the ``Incrementable`` type is a numeric type.] - - to: - [*Note:* implementers are encouraged to provide an implementation of - ``operator-`` and a ``difference_type`` that avoid overflows in - the cases where ``std::numeric_limits::is_specialized`` - is true.] - - Change: - The ``Incrementable`` type must be Default Constructible, Copy - Constructible, and Assignable. The default distance is - an implementation defined signed integegral type. - - The resulting ``counting_iterator`` models Readable Lvalue Iterator. - - to: - The ``Incrementable`` argument shall be Copy Constructible and Assignable. - - Change: - Furthermore, if you wish to create a counting iterator that is a Forward - Traversal Iterator, then the following expressions must be valid: - - to: - If ``iterator_category`` is convertible to ``forward_iterator_tag`` - or ``forward_traversal_tag``, the following must be well-formed: - - Change: - If you wish to create a counting iterator that is a - Bidirectional Traversal Iterator, then pre-decrement is also required: - - to: - If ``iterator_category`` is convertible to - ``bidirectional_iterator_tag`` or ``bidirectional_traversal_tag``, - the following expression must also be well-formed: - - Change: - If you wish to create a counting iterator that is a Random Access - Traversal Iterator, then these additional expressions are also - required: - - to: - If ``iterator_category`` is convertible to - ``random_access_iterator_tag`` or ``random_access_traversal_tag``, - the following must must also be valid: - - After the requirements section, add: - -.. topic:: ``counting_iterator`` models - - Specializations of ``counting_iterator`` model Readable Lvalue - Iterator. In addition, they model the concepts corresponding to the - iterator tags to which their ``iterator_category`` is convertible. - Also, if ``CategoryOrTraversal`` is not ``use_default`` then - ``counting_iterator`` models the concept corresponding to the iterator - tag ``CategoryOrTraversal``. Otherwise, if - ``numeric_limits::is_specialized``, then - ``counting_iterator`` models Random Access Traversal Iterator. - Otherwise, ``counting_iterator`` models the same iterator traversal - concepts modeled by ``Incrementable``. - - ``counting_iterator`` is interoperable with - ``counting_iterator`` if and only if ``X`` is - interoperable with ``Y``. - - At the begining of the operations section, add: - - In addition to the operations required by the concepts modeled by - ``counting_iterator``, ``counting_iterator`` provides the following - operations. - - Change: - :Returns: A default constructed instance of ``counting_iterator``. - - to: - :Requires: ``Incrementable`` is Default Constructible. - :Effects: Default construct the member ``m_inc``. - - Change: - :Returns: An instance of ``counting_iterator`` that is a copy of ``rhs``. - - to: - :Effects: Construct member ``m_inc`` from ``rhs.m_inc``. - - Change: - :Returns: An instance of ``counting_iterator`` with its base - object copy constructed from ``x``. - - to: - :Effects: Construct member ``m_inc`` from ``x``. - - At the end of the operations section, add: - - ``reference operator*() const;`` - - :Returns: ``m_inc`` - - - ``counting_iterator& operator++();`` - - :Effects: ``++m_inc`` - :Returns: ``*this`` - - - ``counting_iterator& operator--();`` - - :Effects: ``--m_inc`` - :Returns: ``*this`` - - - ``Incrementable const& base() const;`` - - :Returns: ``m_inc`` - - -9.38x Problem with specification of a->m in Readable Iterator -============================================================= - -:Submitter: Howard Hinnant -:Status: New - -c++std-lib-12585: - -Readable Iterator Requirements says: - - +----------+--------+-----------------------------------------------------------+ - | ``a->m`` | ``U&`` | pre: ``(*a).m`` is well-defined. Equivalent to ``(*a).m`` | - +----------+--------+-----------------------------------------------------------+ - -Do we mean to outlaw iterators with proxy references from meeting -the readable requirements? - -Would it be better for the requirements to read ``static_cast(*a).m`` -instead of ``(*a).m`` ? - -:Proposed resolution: NAD. - -:Rationale: We think you're misreading "pre:". - If ``(*a).m`` is not well defined, then the iterator is not - required to provide ``a->m``. So a proxy iterator is not - required to provide ``a->m``. - - As an aside, it is possible for proxy iterators to - support ``->``, so changing the requirements to - read ``static_cast(*a).m`` is interesting. - However, such a change to Readable Iterator would - mean that it no longer corresponds to the - input iterator requirements. So old iterators would not - necessarily conform to new iterator requirements. - - -9.39x counting_iterator Traversal argument unspecified -====================================================== - -:Submitter: Pete Becker - -c++std-lib-12635: - -counting_iterator takes an argument for its Traversal type, with a -default value of use_default. It is derived from an instance of -iterator_adaptor, where the argument passed for the Traversal type -is described as "\ ``/* see details for traversal category -*/``". The details for counting_iterator describe constraints on -the Incrementable type imposed by various traversal -categories. There is no description of what the argument to -iterator_adaptor should be. - - -:Proposed resolution: - We no longer inherit from iterator_adaptor. So instead, - we specify the iterator_category in terms of the Traversal type - (which is now called CategoryOrTraversal). Also the - requirements and models section was reorganized to - match these changes and to make more sense. - - - -9.40x indirect_iterator requirements muddled -============================================ - -:Submitter: Pete Becker - -c++std-lib-12640: - - The value_type of the Iterator template parameter should itself - be dereferenceable. The return type of the ``operator*`` for - the value_type must be the same type as the Reference template - parameter. - - I'd say this a bit differently, to emphasize what's required: - iterator_traits::value_type must be dereferenceable. - The Reference template parameter must be the same type as - ``*iterator_traits::value_type()``. - - The Value template parameter will be the value_type for the - indirect_iterator, unless Value is const. If Value is const X, then - value_type will be non- const X. - - Also non-volatile, right? In other words, if Value isn't use_default, it - just gets passed as the Value argument for iterator_adaptor. - - The default for Value is:: - - iterator_traits< iterator_traits::value_type >::value_type - - If the default is used for Value, then there must be a valid - specialization of iterator_traits for the value type of the - base iterator. - - The earlier requirement is that - ``iterator_traits::value_type`` must be - dereferenceable. Now it's being treated as an iterator. Is this - just a pun, or is ``iterator_traits::value_type`` - required to be some form of iterator? If it's the former we need - to find a different way to say it. If it's the latter we need to - say so. - -:Proposed resolution: - Change: - - The ``value_type`` of the ``Iterator`` template parameter - should itself be dereferenceable. The return type of the - ``operator*`` for the ``value_type`` must be the same type as - the ``Reference`` template parameter. The ``Value`` template - parameter will be the ``value_type`` for the - ``indirect_iterator``, unless ``Value`` is const. If ``Value`` - is ``const X``, then ``value_type`` will be *non-* ``const X``. - The default for ``Value`` is:: - - iterator_traits< iterator_traits::value_type >::value_type - - If the default is used for ``Value``, then there must be a - valid specialization of ``iterator_traits`` for the value type - of the base iterator. - - The ``Reference`` parameter will be the ``reference`` type of the - ``indirect_iterator``. The default is ``Value&``. - - The ``Access`` and ``Traversal`` parameters are passed - unchanged to the corresponding parameters of the - ``iterator_adaptor`` base class, and the ``Iterator`` parameter - is passed unchanged as the ``Base`` parameter to the - ``iterator_adaptor`` base class. - - to: - - The expression ``*v``, where ``v`` is an object of - ``iterator_traits::value_type``, shall be valid - expression and convertible to ``reference``. ``Iterator`` - shall model the traversal concept indicated by - ``iterator_category``. ``Value``, ``Reference``, and - ``Difference`` shall be chosen so that ``value_type``, - ``reference``, and ``difference_type`` meet the requirements - indicated by ``iterator_category``. - - [Note: there are further requirements on the - ``iterator_traits::value_type`` if the ``Value`` - parameter is not ``use_default``, as implied by the algorithm - for deducing the default for the ``value_type`` member.] - - -:Rationale: Not included above is the specification of the - ``value_type``, ``reference``, etc., members, which is handled by - the changes in 9.37x. - - -9.41x Problem with transform_iterator requirements -================================================== - -:Submitter: Pete Becker - -c++std-lib-12641: - - The reference type of transform_iterator is ``result_of< - UnaryFunction(iterator_traits::reference) - >::type``. The ``value_type`` is - ``remove_cv >::type``. - -These are the defaults, right? If the user supplies their own types -that's what gets passed to iterator_adaptor. And again, the -specification should be in terms of the specialization of -iterator_adaptor, and not in terms of the result: - -Reference argument to iterator_adaptor:: - - if (Reference != use_default) - Reference - else - result_of< - UnaryFunction(iterator_traits::reference) - >::type - -Value argument to iterator_adaptor:: - - if (Value != use_default) - Value - else if (Reference != use_default) - remove_reference::type - else - remove_reference< - result_of< - UnaryFunction(iterator_traits::reference) - >::type - >::type - -There's probably a better way to specify that last alternative, but -I've been at this too long, and it's all turning into a maze of -twisty passages, all alike. - -:Proposed resolution: - Replace: - - The reference type of transform_iterator is ``result_of< - UnaryFunction(iterator_traits::reference) - >::type``. The ``value_type`` is - ``remove_cv >::type``. - - with: - - If ``Reference`` is ``use_default`` then the ``reference`` - member of ``transform_iterator`` is ``result_of< - UnaryFunction(iterator_traits::reference) - >::type``. Otherwise, ``reference`` is ``Reference``. - - If ``Value`` is ``use_default`` then the ``value_type`` - member is ``remove_cv >::type``. - Otherwise, ``value_type`` is ``Value``. - - -9.42x filter_iterator details unspecified -========================================= - -:Submitter: Pete Becker - -c++std-lib-12642: - -The paper says:: - - template - class filter_iterator - : public iterator_adaptor< - filter_iterator, - Iterator, - use_default, - /* see details */ > - -That comment covers the Access, Traversal, Reference, and Difference -arguments. The only specification for any of these in the details is: - - The access category of the filter_iterator will be the same as - the access category of Iterator. - -Needs more. - -:Proposed resolution: - Add to the synopsis:: - - typedef iterator_traits::value_type value_type; - typedef iterator_traits::reference reference; - typedef iterator_traits::pointer pointer; - typedef iterator_traits::difference_type difference_type; - typedef /* see below */ iterator_category; - - and add just after the synopsis: - - If ``Iterator`` models Readable Lvalue Iterator and Forward - Traversal Iterator then ``iterator_category`` is convertible - to ``std::forward_iterator_tag``. Otherwise - ``iterator_category`` is convertible to - ``std::input_iterator_tag``. - - -9.43x transform_iterator interoperability too restrictive -========================================================= - -:Submitter: Jeremy Siek - -We do not need to require that the function objects have the same -type, just that they be convertible. - -:Proposed resolution: - - Change:: - - template - transform_iterator( - transform_iterator const& t - , typename enable_if_convertible::type* = 0 // exposition - ); - - to:: - - template - transform_iterator( - transform_iterator const& t - , typename enable_if_convertible::type* = 0 // exposition only - , typename enable_if_convertible::type* = 0 // exposition only - ); - - -9.44y ``indirect_iterator`` and smart pointers -============================================== - -:Submitter: Dave Abrahams - -``indirect_iterator`` should be able to iterate over containers of -smart pointers, but the mechanism that allows it was left out of -the specification, even though it's present in the Boost -specification - -:Proposed resolution: Add ``pointee`` and ``indirect_reference`` - to deal with this capability. - - In [lib.iterator.helper.synopsis], add:: - - template - struct pointee; - - template - struct indirect_reference; - - After ``indirect_iterator``\ 's abstract, add: - -.. topic:: Class template ``pointee`` - - .. include:: pointee_ref.rst - -.. topic:: Class template ``indirect_reference`` - - .. include:: indirect_reference_ref.rst - -See proposed resolution to Issue 9.37x for more changes related to -this issue. - -9.45y N1530: Typos and editorial changes in proposal text (not standardese) -=========================================================================== - -:Submitter: Dave Abrahams - -1. "because specification helps to highlight that the ``Reference`` - template parameter may not always be identical to the iterator's - ``reference`` type, and will keep users making mistakes based on - that assumption." - - :Proposed resolution: add "from" before "making" - -9.46y N1530: ``base()`` return-by-value is costly -================================================= - -:Submitter: Dave Abrahams - -We've had some real-life reports that iterators that use -``iterator_adaptor``\ 's ``base()`` function can be inefficient -when the ``Base`` iterator is expensive to copy. Iterators, of -all things, should be efficient. - -:Proposed resolution: - - In [lib.iterator.adaptor] - - Change:: - - Base base() const; - - to:: - - Base const& base() const; - - twice (once in the synopsis and once in the **public - operations** section). - - -9.47x Forgot default constructible in Forward Traversal Iterator -================================================================ - -:Submitter: Jeremy Siek - -We want Forward Traversal Iterator plus Readable Lvalue Iterator to -match the old Foward Iterator requirements, so we need Forward -Traversal Iterator to include Default Constructible. - -:Proposed resolution: - - Change: - - A class or built-in type ``X`` models the *Forward Traversal Iterator* - concept if the following expressions are valid and respect the stated - semantics. - - +-------------------------------------------------------------------------------------------+ - |Forward Traversal Iterator Requirements (in addition to Single Pass Iterator) | - +---------------------------------------+-----------------------------------+---------------+ - - to: - - A class or built-in type ``X`` models the *Forward Traversal Iterator* - concept if, in addition to ``X`` meeting the requirements of - Default Constructible and Single Pass Iterator, the following - expressions are valid and respect the - stated semantics. - - +--------------------------------------------------------------------------------------------------------+ - |Forward Traversal Iterator Requirements (in addition to Default Constructible and Single Pass Iterator) | - +---------------------------------------+-----------------------------------+----------------------------+ - -9.48x Editorial changes (non-normative text) -============================================ - -Change: - Iterator facade uses the Curiously Recurring Template Pattern (CRTP) - [Cop95] so that the user can specify the behavior of - ``iterator_facade`` in a derived class. Former designs used policy - objects to specify the behavior. ``iterator_facade`` does not use policy - objects for several reasons: - -to: - Iterator facade uses the Curiously Recurring Template - Pattern (CRTP) [Cop95] so that the user can specify the behavior - of ``iterator_facade`` in a derived class. Former designs used - policy objects to specify the behavior, but that approach was - discarded for several reasons: - - -Change: - iterator's ``operator++`` returns the iterator type itself means - that all iterators generated by ``iterator_facade`` would be - instantiations of ``iterator_facade``. Cumbersome type generator - -to: - iterator's ``operator++`` returns the iterator type itself - would mean that all iterators built with the library would - have to be specializations of ``iterator_facade<...>``, rather - than something more descriptive like - ``indirect_iterator``. Cumbersome type generator - - -Change: - The return type for ``operator->`` and ``operator[]`` is not - explicitly specified. Instead it requires each ``iterator_facade`` - instantiation to meet the requirements of its ``iterator_category``. - -To: - The return types for ``iterator_facade``\ 's ``operator->`` and - ``operator[]`` are not explicitly specified. Instead, those types - are described in terms of a set of requirements, which must be - satisfied by the ``iterator_facade`` implementation. - - -9.49x Clarification of iterator_facade requirements and type members -==================================================================== - -A general cleanup and simplification of the requirements and -description of type members for ``iterator_facade``. - - -The user is only allowed to add ``const`` as a qualifier. - -Change: - ``typedef remove_cv::type value_type;`` - -to: - ``typedef remove_const::type value_type;`` - - -We use to have an unspecified type for ``pointer``, to match the -return type of ``operator->``, but there's no real reason to make them -match, so we just use the simpler ``Value*`` for ``pointer``. - -Change: - - ``typedef /* see description of operator-> */ pointer;`` - -To: - ``typedef Value* pointer;`` - - -Remove: - Some of the constraints on template parameters to - ``iterator_facade`` are expressed in terms of resulting nested - types and should be viewed in the context of their impact on - ``iterator_traits``. - -Change: - The ``Derived`` template parameter must be a class derived from - ``iterator_facade``. - -and: - The following table describes the other requirements on the - ``Derived`` parameter. Depending on the resulting iterator's - ``iterator_category``, a subset of the expressions listed in the table - are required to be valid. The operations in the first column must be - accessible to member functions of class ``iterator_core_access``. - -to: - The following table describes the typical valid expressions on - ``iterator_facade``\ 's ``Derived`` parameter, depending on the - iterator concept(s) it will model. The operations in the first - column must be made accessible to member functions of class - ``iterator_core_access``. In addition, - ``static_cast(iterator_facade*)`` shall be well-formed. - - -Remove: - The nested ``::value_type`` type will be the same as - ``remove_cv::type``, so the ``Value`` parameter must be - an (optionally ``const``\ -qualified) non-reference type. - - The nested ``::reference`` will be the same as the ``Reference`` - parameter; it must be a suitable reference type for the resulting - iterator. The default for the ``Reference`` parameter is - ``Value&``. - - -Change: - - In the table below, ``X`` is the derived iterator type, ``a`` is an - object of type ``X``, ``b`` and ``c`` are objects of type ``const X``, - ``n`` is an object of ``X::difference_type``, ``y`` is a constant - object of a single pass iterator type interoperable with X, and ``z`` - is a constant object of a random access traversal iterator type - interoperable with ``X``. - - +--------------------+-------------------+-------------------------------------+---------------------------+ - |Expression |Return Type |Assertion/Note |Required to implement | - | | | |Iterator Concept(s) | - +====================+===================+=====================================+===========================+ - |``c.dereference()`` |``X::reference`` | |Readable Iterator, Writable| - | | | |Iterator | - +--------------------+-------------------+-------------------------------------+---------------------------+ - |``c.equal(b)`` |convertible to bool|true iff ``b`` and ``c`` are |Single Pass Iterator | - | | |equivalent. | | - +--------------------+-------------------+-------------------------------------+---------------------------+ - |``c.equal(y)`` |convertible to bool|true iff ``c`` and ``y`` refer to the|Single Pass Iterator | - | | |same position. Implements ``c == y``| | - | | |and ``c != y``. | | - +--------------------+-------------------+-------------------------------------+---------------------------+ - |``a.advance(n)`` |unused | |Random Access Traversal | - | | | |Iterator | - +--------------------+-------------------+-------------------------------------+---------------------------+ - |``a.increment()`` |unused | |Incrementable Iterator | - +--------------------+-------------------+-------------------------------------+---------------------------+ - |``a.decrement()`` |unused | |Bidirectional Traversal | - | | | |Iterator | - +--------------------+-------------------+-------------------------------------+---------------------------+ - |``c.distance_to(b)``|convertible to |equivalent to ``distance(c, b)`` |Random Access Traversal | - | |X::difference_type | |Iterator | - +--------------------+-------------------+-------------------------------------+---------------------------+ - |``c.distance_to(z)``|convertible to |equivalent to ``distance(c, z)``. |Random Access Traversal | - | |X::difference_type |Implements ``c - z``, ``c < z``, ``c |Iterator | - | | |<= z``, ``c > z``, and ``c >= c``. | | - +--------------------+-------------------+-------------------------------------+---------------------------+ - -to: - - In the table below, ``F`` is ``iterator_facade``, ``a`` is an - object of type ``X``, ``b`` and ``c`` are objects of type ``const X``, - ``n`` is an object of ``F::difference_type``, ``y`` is a constant - object of a single pass iterator type interoperable with ``X``, and ``z`` - is a constant object of a random access traversal iterator type - interoperable with ``X``. - - **iterator_facade Core Operations** - - +--------------------+----------------------+-------------------------+---------------------------+ - |Expression |Return Type |Assertion/Note |Used to implement Iterator | - | | | |Concept(s) | - +====================+======================+=========================+===========================+ - |``c.dereference()`` |``F::reference`` | |Readable Iterator, Writable| - | | | |Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - |``c.equal(y)`` |convertible to bool |true iff ``c`` and ``y`` |Single Pass Iterator | - | | |refer to the same | | - | | |position. | | - +--------------------+----------------------+-------------------------+---------------------------+ - |``a.increment()`` |unused | |Incrementable Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - |``a.decrement()`` |unused | |Bidirectional Traversal | - | | | |Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - |``a.advance(n)`` |unused | |Random Access Traversal | - | | | |Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - |``c.distance_to(z)``|convertible to |equivalent to |Random Access Traversal | - | |``F::difference_type``|``distance(c, X(z))``. |Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ diff --git a/doc/iterator_adaptor.html b/doc/iterator_adaptor.html deleted file mode 100644 index b105c79..0000000 --- a/doc/iterator_adaptor.html +++ /dev/null @@ -1,440 +0,0 @@ - - - - - - -Iterator Adaptor - - - - - - - -
-

Iterator Adaptor

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-01-12
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved
- --- - - - -
abstract:
- - -

Each specialization of the iterator_adaptor class template is derived from -a specialization of iterator_facade. The core interface functions -expected by iterator_facade are implemented in terms of the -iterator_adaptor's Base template parameter. A class derived -from iterator_adaptor typically redefines some of the core -interface functions to adapt the behavior of the Base type. -Whether the derived class models any of the standard iterator concepts -depends on the operations supported by the Base type and which -core interface functions of iterator_facade are redefined in the -Derived class.

- -
-

Overview

- - -

The iterator_adaptor class template adapts some Base 1 -type to create a new iterator. Instantiations of iterator_adaptor -are derived from a corresponding instantiation of iterator_facade -and implement the core behaviors in terms of the Base type. In -essence, iterator_adaptor merely forwards all operations to an -instance of the Base type, which it stores as a member.

- - - - - -
[1](1, 2) The term "Base" here does not refer to a base class and is -not meant to imply the use of derivation. We have followed the lead -of the standard library, which provides a base() function to access -the underlying iterator object of a reverse_iterator adaptor.
-

The user of iterator_adaptor creates a class derived from an -instantiation of iterator_adaptor and then selectively -redefines some of the core member functions described in the table -above. The Base type need not meet the full requirements for an -iterator. It need only support the operations used by the core -interface functions of iterator_adaptor that have not been -redefined in the user's derived class.

-

Several of the template parameters of iterator_adaptor default -to use_default. This allows the -user to make use of a default parameter even when she wants to -specify a parameter later in the parameter list. Also, the -defaults for the corresponding associated types are somewhat -complicated, so metaprogramming is required to compute them, and -use_default can help to simplify the implementation. Finally, -the identity of the use_default type is not left unspecified -because specification helps to highlight that the Reference -template parameter may not always be identical to the iterator's -reference type, and will keep users from making mistakes based on -that assumption.

-
-
-

Reference

- - -
-template <
-    class Derived
-  , class Base
-  , class Value               = use_default
-  , class CategoryOrTraversal = use_default
-  , class Reference           = use_default
-  , class Difference = use_default
->
-class iterator_adaptor 
-  : public iterator_facade<Derived, V', C', R', D'> // see details
-{
-    friend class iterator_core_access;
- public:
-    iterator_adaptor();
-    explicit iterator_adaptor(Base iter);
-    Base const& base() const;
- protected:
-    Base const& base_reference() const;
-    Base& base_reference();
- private: // Core iterator interface for iterator_facade.  
-    typename iterator_adaptor::reference dereference() const;
-
-    template <
-    class OtherDerived, class OtherIterator, class V, class C, class R, class D
-    >   
-    bool equal(iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& x) const;
-
-    void advance(typename iterator_adaptor::difference_type n);
-    void increment();
-    void decrement();
-
-    template <
-        class OtherDerived, class OtherIterator, class V, class C, class R, class D
-    >   
-    typename iterator_adaptor::difference_type distance_to(
-        iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& y) const;
-
- private:
-    Base m_iterator; // exposition only
-};
-
-
-

iterator_adaptor requirements

-

static_cast<Derived*>(iterator_adaptor*) shall be well-formed. -The Base argument shall be Assignable and Copy Constructible.

-
-
-

iterator_adaptor base class parameters

-

The V', C', R', and D' parameters of the iterator_facade -used as a base class in the summary of iterator_adaptor -above are defined as follows:

-
-V' = if (Value is use_default)
-          return iterator_traits<Base>::value_type
-      else
-          return Value
-
-C' = if (CategoryOrTraversal is use_default)
-          return iterator_traversal<Base>::type
-      else
-          return CategoryOrTraversal
-
-R' = if (Reference is use_default)
-          if (Value is use_default)
-              return iterator_traits<Base>::reference
-          else
-              return Value&
-      else
-          return Reference
-
-D' = if (Difference is use_default)
-          return iterator_traits<Base>::difference_type
-      else
-          return Difference
-
- - - -
-
-

iterator_adaptor public operations

-

iterator_adaptor();

- --- - - - - - -
Requires:The Base type must be Default Constructible.
Returns:An instance of iterator_adaptor with -m_iterator default constructed.
-

explicit iterator_adaptor(Base iter);

- --- - - - -
Returns:An instance of iterator_adaptor with -m_iterator copy constructed from iter.
-

Base const& base() const;

- --- - - - -
Returns:m_iterator
-
-
-

iterator_adaptor protected member functions

-

Base const& base_reference() const;

- --- - - - -
Returns:A const reference to m_iterator.
-

Base& base_reference();

- --- - - - -
Returns:A non-const reference to m_iterator.
-
-
-

iterator_adaptor private member functions

-

typename iterator_adaptor::reference dereference() const;

- --- - - - -
Returns:*m_iterator
-
-template <
-class OtherDerived, class OtherIterator, class V, class C, class R, class D
->   
-bool equal(iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& x) const;
-
- --- - - - -
Returns:m_iterator == x.base()
-

void advance(typename iterator_adaptor::difference_type n);

- --- - - - -
Effects:m_iterator += n;
-

void increment();

- --- - - - -
Effects:++m_iterator;
-

void decrement();

- --- - - - -
Effects:--m_iterator;
-
-template <
-    class OtherDerived, class OtherIterator, class V, class C, class R, class D
->   
-typename iterator_adaptor::difference_type distance_to(
-    iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& y) const;
-
- --- - - - -
Returns:y.base() - m_iterator
-
-
-
-

Tutorial Example

- - - -

In this section we'll further refine the node_iter class -template we developed in the iterator_facade tutorial. If you haven't already -read that material, you should go back now and check it out because -we're going to pick up right where it left off.

- -

You probably didn't think of it this way, but the node_base* -object which underlies node_iterator is itself an iterator, -just like all other pointers. If we examine that pointer closely -from an iterator perspective, we can see that it has much in common -with the node_iterator we're building. First, they share most -of the same associated types (value_type, reference, -pointer, and difference_type). Second, even some of the -core functionality is the same: operator* and operator== on -the node_iterator return the result of invoking the same -operations on the underlying pointer, via the node_iterator's -dereference and equal member functions). However, the operator++ for -node_iterator behaves differently than for node_base* -since it follows the m_next pointer.

-

It turns out that the pattern of building an iterator on another -iterator-like type (the Base 1 type) while modifying -just a few aspects of the underlying type's behavior is an -extremely common one, and it's the pattern addressed by -iterator_adaptor. Using iterator_adaptor is very much like -using iterator_facade, but because iterator_adaptor tries to -mimic as much of the Base type's behavior as possible, we -neither have to supply a Value argument, nor implement any core -behaviors other than increment. The implementation of -node_iter is thus reduced to:

-
-template <class Value>
-class node_iter
-  : public boost::iterator_adaptor<
-        node_iter<Value>                // Derived
-      , Value*                          // Base
-      , boost::use_default              // Value
-      , boost::forward_traversal_tag    // CategoryOrTraversal
-    >
-{
- private:
-    struct enabler {};  // a private type avoids misuse
-
-    typedef boost::iterator_adaptor<
-        node_iter<Value>, Value*, boost::use_default, boost::forward_traversal_tag
-    > super_t;
-
- public:
-    node_iter()
-      : super_t(0) {}
-
-    explicit node_iter(Value* p)
-      : super_t(p) {}
-
-    template <class OtherValue>
-    node_iter(
-        node_iter<OtherValue> const& other
-      , typename boost::enable_if<
-            boost::is_convertible<OtherValue*,Value*>
-          , enabler
-        >::type = enabler()
-    )
-      : super_t(other.base()) {}
-
- private:
-    friend class boost::iterator_core_access;
-    void increment() { this->base_reference() = this->base()->next(); }
-};
-
-

You can see an example program which exercises this version of the -node iterators here.

-

In the case of node_iter, it's not very compelling to pass -boost::use_default as iterator_adaptor's Value -argument; we could have just passed node_iter's Value -along to iterator_adaptor, and that'd even be shorter! Most -iterator class templates built with iterator_adaptor are -parameterized on another iterator type, rather than on its -value_type. For example, boost::reverse_iterator takes an -iterator type argument and reverses its direction of traversal, -since the original iterator and the reversed one have all the same -associated types, iterator_adaptor's delegation of default -types to its Base saves the implementor of -boost::reverse_iterator from writing

-
-std::iterator_traits<Iterator>::some-associated-type
-
-

at least four times.

-

We urge you to review the documentation and implementations of -reverse_iterator and the other Boost specialized iterator -adaptors to get an idea of the sorts of things you can do with -iterator_adaptor. In particular, have a look at -transform_iterator, which is perhaps the most straightforward -adaptor, and also counting_iterator, which demonstrates that -iterator_adaptor's Base type needn't be an iterator.

-
-
- - diff --git a/doc/iterator_adaptor.rst b/doc/iterator_adaptor.rst deleted file mode 100644 index 42e25e3..0000000 --- a/doc/iterator_adaptor.rst +++ /dev/null @@ -1,37 +0,0 @@ -+++++++++++++++++ - Iterator Adaptor -+++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: - -.. include:: iterator_adaptor_abstract.rst - -.. contents:: Table of Contents - -Overview -======== - -.. include:: iterator_adaptor_body.rst - - -Reference -========= - -.. include:: iterator_adaptor_ref.rst - -Tutorial Example -================ - -.. include:: iterator_adaptor_tutorial.rst diff --git a/doc/iterator_adaptor_abstract.diff b/doc/iterator_adaptor_abstract.diff deleted file mode 100755 index 6cebd77..0000000 --- a/doc/iterator_adaptor_abstract.diff +++ /dev/null @@ -1,22 +0,0 @@ -Index: iterator_adaptor_abstract.rst -=================================================================== -RCS file: /cvsroot/boost/boost/libs/iterator/doc/iterator_adaptor_abstract.rst,v -retrieving revision 1.1 -retrieving revision 1.2 -diff -b -d -u -r1.1 -r1.2 ---- iterator_adaptor_abstract.rst 5 Aug 2003 18:19:55 -0000 1.1 -+++ iterator_adaptor_abstract.rst 24 Nov 2003 05:02:46 -0000 1.2 -@@ -1,5 +1,11 @@ Issue 9.21 --The ``iterator_adaptor`` is a base class template derived from an --instantiation of ``iterator_facade``. The core interface functions -+.. Version 1.1 of this ReStructuredText document corresponds to -+ n1530_, the paper accepted by the LWG. -+ -+.. Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All -+ rights reserved -+ -+Each specialization of the ``iterator_adaptor`` class template is derived from -+a specialization of ``iterator_facade``. The core interface functions - expected by ``iterator_facade`` are implemented in terms of the - ``iterator_adaptor``\ 's ``Base`` template parameter. A class derived - from ``iterator_adaptor`` typically redefines some of the core diff --git a/doc/iterator_adaptor_abstract.rst b/doc/iterator_adaptor_abstract.rst deleted file mode 100644 index c20ac7b..0000000 --- a/doc/iterator_adaptor_abstract.rst +++ /dev/null @@ -1,16 +0,0 @@ -.. Version 1.1 of this ReStructuredText document corresponds to - n1530_, the paper accepted by the LWG. - -.. Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All - rights reserved - -Each specialization of the ``iterator_adaptor`` class template is derived from -a specialization of ``iterator_facade``. The core interface functions -expected by ``iterator_facade`` are implemented in terms of the -``iterator_adaptor``\ 's ``Base`` template parameter. A class derived -from ``iterator_adaptor`` typically redefines some of the core -interface functions to adapt the behavior of the ``Base`` type. -Whether the derived class models any of the standard iterator concepts -depends on the operations supported by the ``Base`` type and which -core interface functions of ``iterator_facade`` are redefined in the -``Derived`` class. diff --git a/doc/iterator_adaptor_body.diff b/doc/iterator_adaptor_body.diff deleted file mode 100755 index a170244..0000000 --- a/doc/iterator_adaptor_body.diff +++ /dev/null @@ -1,35 +0,0 @@ -Index: iterator_adaptor_body.rst -=================================================================== -RCS file: /cvsroot/boost/boost/libs/iterator/doc/iterator_adaptor_body.rst,v -retrieving revision 1.2 -retrieving revision 1.3 -diff -b -d -u -r1.2 -r1.3 ---- iterator_adaptor_body.rst 22 Sep 2003 19:55:00 -0000 1.2 -+++ iterator_adaptor_body.rst 24 Nov 2003 05:02:46 -0000 1.3 -@@ -1,3 +1,9 @@ -+.. Version 1.2 of this ReStructuredText document corresponds to -+ n1530_, the paper accepted by the LWG for TR1. -+ -+.. Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All -+ rights reserved -+ - The ``iterator_adaptor`` class template adapts some ``Base`` [#base]_ - type to create a new iterator. Instantiations of ``iterator_adaptor`` - are derived from a corresponding instantiation of ``iterator_facade`` -@@ -19,7 +25,7 @@ Issue 9.1 et al - redefined in the user's derived class. - - Several of the template parameters of ``iterator_adaptor`` default --to ``use_default`` (or ``use_default_access``). This allows the -+to ``use_default``. This allows the - user to make use of a default parameter even when she wants to - specify a parameter later in the parameter list. Also, the - defaults for the corresponding associated types are somewhat -@@ -28,6 +34,6 @@ Issue 9.45y - the identity of the ``use_default`` type is not left unspecified - because specification helps to highlight that the ``Reference`` - template parameter may not always be identical to the iterator's --``reference`` type, and will keep users making mistakes based on -+``reference`` type, and will keep users from making mistakes based on - that assumption. - diff --git a/doc/iterator_adaptor_body.rst b/doc/iterator_adaptor_body.rst deleted file mode 100644 index 59b8cef..0000000 --- a/doc/iterator_adaptor_body.rst +++ /dev/null @@ -1,39 +0,0 @@ -.. Version 1.2 of this ReStructuredText document corresponds to - n1530_, the paper accepted by the LWG for TR1. - -.. Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All - rights reserved - -The ``iterator_adaptor`` class template adapts some ``Base`` [#base]_ -type to create a new iterator. Instantiations of ``iterator_adaptor`` -are derived from a corresponding instantiation of ``iterator_facade`` -and implement the core behaviors in terms of the ``Base`` type. In -essence, ``iterator_adaptor`` merely forwards all operations to an -instance of the ``Base`` type, which it stores as a member. - -.. [#base] The term "Base" here does not refer to a base class and is - not meant to imply the use of derivation. We have followed the lead - of the standard library, which provides a base() function to access - the underlying iterator object of a ``reverse_iterator`` adaptor. - -The user of ``iterator_adaptor`` creates a class derived from an -instantiation of ``iterator_adaptor`` and then selectively -redefines some of the core member functions described in the table -above. The ``Base`` type need not meet the full requirements for an -iterator. It need only support the operations used by the core -interface functions of ``iterator_adaptor`` that have not been -redefined in the user's derived class. - -Several of the template parameters of ``iterator_adaptor`` default -to ``use_default``. This allows the -user to make use of a default parameter even when she wants to -specify a parameter later in the parameter list. Also, the -defaults for the corresponding associated types are somewhat -complicated, so metaprogramming is required to compute them, and -``use_default`` can help to simplify the implementation. Finally, -the identity of the ``use_default`` type is not left unspecified -because specification helps to highlight that the ``Reference`` -template parameter may not always be identical to the iterator's -``reference`` type, and will keep users from making mistakes based on -that assumption. - diff --git a/doc/iterator_adaptor_ref.rst b/doc/iterator_adaptor_ref.rst deleted file mode 100644 index fb6a88c..0000000 --- a/doc/iterator_adaptor_ref.rst +++ /dev/null @@ -1,177 +0,0 @@ -.. Version 1.4 of this ReStructuredText document corresponds to - n1530_, the paper accepted by the LWG for TR1. - -.. Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All - rights reserved. - -.. parsed-literal:: - - template < - class Derived - , class Base - , class Value = use_default - , class CategoryOrTraversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class iterator_adaptor - : public iterator_facade // see details__ - { - friend class iterator_core_access; - public: - iterator_adaptor(); - explicit iterator_adaptor(Base iter); - Base const& base() const; - protected: - Base const& base_reference() const; - Base& base_reference(); - private: // Core iterator interface for iterator_facade. - typename iterator_adaptor::reference dereference() const; - - template < - class OtherDerived, class OtherIterator, class V, class C, class R, class D - > - bool equal(iterator_adaptor const& x) const; - - void advance(typename iterator_adaptor::difference_type n); - void increment(); - void decrement(); - - template < - class OtherDerived, class OtherIterator, class V, class C, class R, class D - > - typename iterator_adaptor::difference_type distance_to( - iterator_adaptor const& y) const; - - private: - Base m_iterator; // exposition only - }; - -__ base_parameters_ - -.. _requirements: - -``iterator_adaptor`` requirements ---------------------------------- - -``static_cast(iterator_adaptor*)`` shall be well-formed. -The ``Base`` argument shall be Assignable and Copy Constructible. - - -.. _base_parameters: - -``iterator_adaptor`` base class parameters ------------------------------------------- - -The *V'*, *C'*, *R'*, and *D'* parameters of the ``iterator_facade`` -used as a base class in the summary of ``iterator_adaptor`` -above are defined as follows: - -.. parsed-literal:: - - *V'* = if (Value is use_default) - return iterator_traits::value_type - else - return Value - - *C'* = if (CategoryOrTraversal is use_default) - return iterator_traversal::type - else - return CategoryOrTraversal - - *R'* = if (Reference is use_default) - if (Value is use_default) - return iterator_traits::reference - else - return Value& - else - return Reference - - *D'* = if (Difference is use_default) - return iterator_traits::difference_type - else - return Difference - -.. ``iterator_adaptor`` models - --------------------------- - - In order for ``Derived`` to model the iterator concepts corresponding - to ``iterator_traits::iterator_category``, the expressions - involving ``m_iterator`` in the specifications of those private member - functions of ``iterator_adaptor`` that may be called by - ``iterator_facade`` in evaluating any valid - expression involving ``Derived`` in those concepts' requirements. - -.. The above is confusing and needs a rewrite. -JGS -.. That's why it's removed. We're embracing inheritance, remember? - -``iterator_adaptor`` public operations --------------------------------------- - -``iterator_adaptor();`` - -:Requires: The ``Base`` type must be Default Constructible. -:Returns: An instance of ``iterator_adaptor`` with - ``m_iterator`` default constructed. - - -``explicit iterator_adaptor(Base iter);`` - -:Returns: An instance of ``iterator_adaptor`` with - ``m_iterator`` copy constructed from ``iter``. - -``Base const& base() const;`` - -:Returns: ``m_iterator`` - -``iterator_adaptor`` protected member functions ------------------------------------------------ - -``Base const& base_reference() const;`` - -:Returns: A const reference to ``m_iterator``. - - -``Base& base_reference();`` - -:Returns: A non-const reference to ``m_iterator``. - - -``iterator_adaptor`` private member functions ---------------------------------------------- - -``typename iterator_adaptor::reference dereference() const;`` - -:Returns: ``*m_iterator`` - -:: - - template < - class OtherDerived, class OtherIterator, class V, class C, class R, class D - > - bool equal(iterator_adaptor const& x) const; - -:Returns: ``m_iterator == x.base()`` - - -``void advance(typename iterator_adaptor::difference_type n);`` - -:Effects: ``m_iterator += n;`` - -``void increment();`` - -:Effects: ``++m_iterator;`` - -``void decrement();`` - -:Effects: ``--m_iterator;`` - -:: - - template < - class OtherDerived, class OtherIterator, class V, class C, class R, class D - > - typename iterator_adaptor::difference_type distance_to( - iterator_adaptor const& y) const; - -:Returns: ``y.base() - m_iterator`` diff --git a/doc/iterator_adaptor_tutorial.rst b/doc/iterator_adaptor_tutorial.rst deleted file mode 100755 index ed1aa7e..0000000 --- a/doc/iterator_adaptor_tutorial.rst +++ /dev/null @@ -1,131 +0,0 @@ -.. 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) - -In this section we'll further refine the ``node_iter`` class -template we developed in the |fac_tut|_. If you haven't already -read that material, you should go back now and check it out because -we're going to pick up right where it left off. - -.. |fac_tut| replace:: ``iterator_facade`` tutorial -.. _fac_tut: iterator_facade.html#tutorial-example - -.. sidebar:: ``node_base*`` really *is* an iterator - - It's not really a very interesting iterator, since ``node_base`` - is an abstract class: a pointer to a ``node_base`` just points - at some base subobject of an instance of some other class, and - incrementing a ``node_base*`` moves it past this base subobject - to who-knows-where? The most we can do with that incremented - position is to compare another ``node_base*`` to it. In other - words, the original iterator traverses a one-element array. - -You probably didn't think of it this way, but the ``node_base*`` -object which underlies ``node_iterator`` is itself an iterator, -just like all other pointers. If we examine that pointer closely -from an iterator perspective, we can see that it has much in common -with the ``node_iterator`` we're building. First, they share most -of the same associated types (``value_type``, ``reference``, -``pointer``, and ``difference_type``). Second, even some of the -core functionality is the same: ``operator*`` and ``operator==`` on -the ``node_iterator`` return the result of invoking the same -operations on the underlying pointer, via the ``node_iterator``\ 's -|dereference_and_equal|_). However, the ``operator++`` for -``node_iterator`` behaves differently than for ``node_base*`` -since it follows the ``m_next`` pointer. - -.. |dereference_and_equal| replace:: ``dereference`` and ``equal`` member functions -.. _dereference_and_equal: iterator_facade.html#implementing-the-core-operations - -It turns out that the pattern of building an iterator on another -iterator-like type (the ``Base`` [#base]_ type) while modifying -just a few aspects of the underlying type's behavior is an -extremely common one, and it's the pattern addressed by -``iterator_adaptor``. Using ``iterator_adaptor`` is very much like -using ``iterator_facade``, but because iterator_adaptor tries to -mimic as much of the ``Base`` type's behavior as possible, we -neither have to supply a ``Value`` argument, nor implement any core -behaviors other than ``increment``. The implementation of -``node_iter`` is thus reduced to:: - - template - class node_iter - : public boost::iterator_adaptor< - node_iter // Derived - , Value* // Base - , boost::use_default // Value - , boost::forward_traversal_tag // CategoryOrTraversal - > - { - private: - struct enabler {}; // a private type avoids misuse - - typedef boost::iterator_adaptor< - node_iter, Value*, boost::use_default, boost::forward_traversal_tag - > super_t; - - public: - node_iter() - : super_t(0) {} - - explicit node_iter(Value* p) - : super_t(p) {} - - template - node_iter( - node_iter const& other - , typename boost::enable_if< - boost::is_convertible - , enabler - >::type = enabler() - ) - : super_t(other.base()) {} - - private: - friend class boost::iterator_core_access; - void increment() { this->base_reference() = this->base()->next(); } - }; - -You can see an example program which exercises this version of the -node iterators `here`__. - -__ ../example/node_iterator3.cpp - -In the case of ``node_iter``, it's not very compelling to pass -``boost::use_default`` as ``iterator_adaptor``\ 's ``Value`` -argument; we could have just passed ``node_iter``\ 's ``Value`` -along to ``iterator_adaptor``, and that'd even be shorter! Most -iterator class templates built with ``iterator_adaptor`` are -parameterized on another iterator type, rather than on its -``value_type``. For example, ``boost::reverse_iterator`` takes an -iterator type argument and reverses its direction of traversal, -since the original iterator and the reversed one have all the same -associated types, ``iterator_adaptor``\ 's delegation of default -types to its ``Base`` saves the implementor of -``boost::reverse_iterator`` from writing - -.. parsed-literal:: - - std::iterator_traits::*some-associated-type* - -at least four times. - -We urge you to review the documentation and implementations of -|reverse_iterator|_ and the other Boost `specialized iterator -adaptors`__ to get an idea of the sorts of things you can do with -``iterator_adaptor``. In particular, have a look at -|transform_iterator|_, which is perhaps the most straightforward -adaptor, and also |counting_iterator|_, which demonstrates that -``iterator_adaptor``\ 's ``Base`` type needn't be an iterator. - -.. |reverse_iterator| replace:: ``reverse_iterator`` -.. _reverse_iterator: reverse_iterator.html - -.. |counting_iterator| replace:: ``counting_iterator`` -.. _counting_iterator: counting_iterator.html - -.. |transform_iterator| replace:: ``transform_iterator`` -.. _transform_iterator: transform_iterator.html - -__ index.html#specialized-adaptors - diff --git a/doc/iterator_archetypes.html b/doc/iterator_archetypes.html deleted file mode 100755 index 8e3b75c..0000000 --- a/doc/iterator_archetypes.html +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - -Iterator Archetype - - - - - - - -
-

Iterator Archetype

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com
Organization:Boost Consulting, Indiana University Open Systems -Lab, Zephyr Associates, Inc.
Date:2004-01-13
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2004. All rights reserved
- --- - - - -
abstract:iterator archetypes provide a means to check the compile time requirements of a generic component on its iterator arguments.
- -
-

Reference

-
-

iterator_archetype Synopsis

-
-namespace iterator_archetypes
-{
-    // Access categories
-
-    typedef /implementation  defined/ readable_iterator_t;
-    typedef /implementation  defined/ writable_iterator_t;
-    typedef /implementation  defined/ readable_writable_iterator_t;
-    typedef /implementation  defined/ readable_lvalue_iterator_t;
-    typedef /implementation  defined/ writable_lvalue_iterator_t;
-
-}
-
-template <
-    class Value
-  , class AccessCategory
-  , class TraversalCategory
->
-class iterator_archetype
-{
-    typedef /* see below / value_type;
-    typedef / see below / reference;
-    typedef / see below / pointer;
-    typedef / see below / difference_type;
-    typedef / see below */ iterator_category;
-};
-
-
-

System Message: WARNING/2 (iterator_archetypes.rst, line 26); backlink

-Inline emphasis start-string without end-string.
-
-
-

Access Category Tags

-

The access category types provided correspond to the following -standard iterator access concept combinations:

-
-readable_iterator_t :=
-
-  Readable Iterator
-
-writable_iterator_t :=
-
-  Writeable Iterator
-
-readable_writable_iterator_t :=
-
-  Readable Iterator & Writeable Iterator & Swappable Iterator
-
-readable_lvalue_iterator_t :=
-
-  Readable Iterator & Lvalue Iterator
-
-writeable_lvalue_iterator_t :=
-
-  Readable Iterator & Writeable Iterator & Swappable Iterator & Lvalue Iterator
-
-
-
-

iterator_archetype Requirements

-

The AccessCategory argument must be one of the predefined access -category tags. The TraversalCategory must be one of the standard -traversal tags. The Value type must satisfy the requirements of -the iterator concept specified by AccessCategory and -TraversalCategory as implied by the nested traits types.

-
-
-

iterator_archetype Models

-

iterator_archetype models the iterator concepts specified by the -AccessCategory and TraversalCategory -arguments. iterator_archetype does not model any other access -concepts or any more derived traversal concepts.

-
-
-

Traits

-

The nested trait types are defined as follows:

-
-if (AccessCategory == readable_iterator_t)
-  
-  value_type = Value
-  reference  = Value
-  pointer    = Value*
-
-else if (AccessCategory == writable_iterator_t)
-
-  value_type = void
-  reference  = void
-  pointer    = void
-
-else if (AccessCategory == readable_writable_iterator_t)
-
-  value_type = Value
-
-  reference :=
-
-    A type X that is convertible to Value for which the following
-    expression is valid. Given an object x of type X and v of type 
-    Value.
-
-    x = v
-
-  pointer    = Value*
-
-else if (AccessCategory == readable_lvalue_iterator_t)
-  
-  value_type = Value
-  reference  = Value const&
-  pointer    = Value const*
-
-else if (AccessCategory == writable_lvalue_iterator_t)
-  
-  value_type = Value
-  reference  = Value&
-  pointer    = Value*
-
-if ( TraversalCategory is convertible to forward_traversal_tag )
-
-  difference_type := ptrdiff_t
-
-else
-
-  difference_type := unspecified type
-
-
-iterator_category := 
-
-  A type X satisfying the following two constraints:
-
-     1. X is convertible to X1, and not to any more-derived
-        type, where X1 is defined by:
-
-          if (reference is a reference type
-              && TraversalCategory is convertible to forward_traversal_tag)
-          {
-              if (TraversalCategory is convertible to random_access_traversal_tag)
-                  X1 = random_access_iterator_tag
-              else if (TraversalCategory is convertible to bidirectional_traversal_tag)
-                  X1 = bidirectional_iterator_tag
-              else
-                  X1 = forward_iterator_tag
-          }
-          else
-          {
-              if (TraversalCategory is convertible to single_pass_traversal_tag
-                  && reference != void)
-                  X1 = input_iterator_tag
-              else
-                  X1 = output_iterator_tag
-          }
-
-     2. X is convertible to TraversalCategory
-
-
-
-
- - - - diff --git a/doc/iterator_archetypes.rst b/doc/iterator_archetypes.rst deleted file mode 100755 index ad711d8..0000000 --- a/doc/iterator_archetypes.rst +++ /dev/null @@ -1,181 +0,0 @@ -++++++++++++++++++++ - Iterator Archetype -++++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, `Zephyr Associates, Inc.`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2004. All rights reserved - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Zephyr Associates, Inc.`: http://www.styleadvisor.com - -:abstract: iterator archetypes provide a means to check the compile time requirements of a generic component on its iterator arguments. - -.. contents:: Table of Contents - -Reference -========= - -``iterator_archetype`` Synopsis -............................... - -.. parsed-literal:: - - namespace iterator_archetypes - { - // Access categories - - typedef /*implementation defined*/ readable_iterator_t; - typedef /*implementation defined*/ writable_iterator_t; - typedef /*implementation defined*/ readable_writable_iterator_t; - typedef /*implementation defined*/ readable_lvalue_iterator_t; - typedef /*implementation defined*/ writable_lvalue_iterator_t; - - } - - template < - class Value - , class AccessCategory - , class TraversalCategory - > - class iterator_archetype - { - typedef /* see below */ value_type; - typedef /* see below */ reference; - typedef /* see below */ pointer; - typedef /* see below */ difference_type; - typedef /* see below */ iterator_category; - }; - -``Access Category Tags`` -........................ - -The access category types provided correspond to the following -standard iterator access concept combinations: - -.. parsed-literal:: - - readable_iterator_t := - - Readable Iterator - - writable_iterator_t := - - Writeable Iterator - - readable_writable_iterator_t := - - Readable Iterator & Writeable Iterator & Swappable Iterator - - readable_lvalue_iterator_t := - - Readable Iterator & Lvalue Iterator - - writeable_lvalue_iterator_t := - - Readable Iterator & Writeable Iterator & Swappable Iterator & Lvalue Iterator - -``iterator_archetype`` Requirements -................................... - -The ``AccessCategory`` argument must be one of the predefined access -category tags. The ``TraversalCategory`` must be one of the standard -traversal tags. The ``Value`` type must satisfy the requirements of -the iterator concept specified by ``AccessCategory`` and -``TraversalCategory`` as implied by the nested traits types. - -``iterator_archetype`` Models -............................. - -``iterator_archetype`` models the iterator concepts specified by the -``AccessCategory`` and ``TraversalCategory`` -arguments. ``iterator_archetype`` does not model any other access -concepts or any more derived traversal concepts. - -``Traits`` -.......... - -The nested trait types are defined as follows: - -.. parsed-literal:: - - if (AccessCategory == readable_iterator_t) - - value_type = Value - reference = Value - pointer = Value* - - else if (AccessCategory == writable_iterator_t) - - value_type = void - reference = void - pointer = void - - else if (AccessCategory == readable_writable_iterator_t) - - value_type = Value - - reference := - - A type X that is convertible to Value for which the following - expression is valid. Given an object x of type X and v of type - Value. - - x = v - - pointer = Value* - - else if (AccessCategory == readable_lvalue_iterator_t) - - value_type = Value - reference = Value const& - pointer = Value const* - - else if (AccessCategory == writable_lvalue_iterator_t) - - value_type = Value - reference = Value& - pointer = Value* - - if ( TraversalCategory is convertible to forward_traversal_tag ) - - difference_type := ptrdiff_t - - else - - difference_type := unspecified type - - - iterator_category := - - A type X satisfying the following two constraints: - - 1. X is convertible to X1, and not to any more-derived - type, where X1 is defined by: - - if (reference is a reference type - && TraversalCategory is convertible to forward_traversal_tag) - { - if (TraversalCategory is convertible to random_access_traversal_tag) - X1 = random_access_iterator_tag - else if (TraversalCategory is convertible to bidirectional_traversal_tag) - X1 = bidirectional_iterator_tag - else - X1 = forward_iterator_tag - } - else - { - if (TraversalCategory is convertible to single_pass_traversal_tag - && reference != void) - X1 = input_iterator_tag - else - X1 = output_iterator_tag - } - - 2. X is convertible to TraversalCategory - - \ No newline at end of file diff --git a/doc/iterator_facade.html b/doc/iterator_facade.html deleted file mode 100644 index a3d100e..0000000 --- a/doc/iterator_facade.html +++ /dev/null @@ -1,1272 +0,0 @@ - - - - - - -Iterator Facade - - - - - - - -
-

Iterator Facade

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-01-12
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved
- --- - - - -
abstract:iterator_facade is a base class template that implements the -interface of standard iterators in terms of a few core functions -and associated types, to be supplied by a derived iterator class.
- -
-

Overview

- - -

While the iterator interface is rich, there is a core subset of the -interface that is necessary for all the functionality. We have -identified the following core behaviors for iterators:

-
    -
  • dereferencing
  • -
  • incrementing
  • -
  • decrementing
  • -
  • equality comparison
  • -
  • random-access motion
  • -
  • distance measurement
  • -
-

In addition to the behaviors listed above, the core interface elements -include the associated types exposed through iterator traits: -value_type, reference, difference_type, and -iterator_category.

-

Iterator facade uses the Curiously Recurring Template -Pattern (CRTP) [Cop95] so that the user can specify the behavior -of iterator_facade in a derived class. Former designs used -policy objects to specify the behavior, but that approach was -discarded for several reasons:

-
-
    -
  1. the creation and eventual copying of the policy object may create -overhead that can be avoided with the current approach.
  2. -
  3. The policy object approach does not allow for custom constructors -on the created iterator types, an essential feature if -iterator_facade should be used in other library -implementations.
  4. -
  5. Without the use of CRTP, the standard requirement that an -iterator's operator++ returns the iterator type itself -would mean that all iterators built with the library would -have to be specializations of iterator_facade<...>, rather -than something more descriptive like -indirect_iterator<T*>. Cumbersome type generator -metafunctions would be needed to build new parameterized -iterators, and a separate iterator_adaptor layer would be -impossible.
  6. -
-
-
-

Usage

-

The user of iterator_facade derives his iterator class from a -specialization of iterator_facade and passes the derived -iterator class as iterator_facade's first template parameter. -The order of the other template parameters have been carefully -chosen to take advantage of useful defaults. For example, when -defining a constant lvalue iterator, the user can pass a -const-qualified version of the iterator's value_type as -iterator_facade's Value parameter and omit the -Reference parameter which follows.

-

The derived iterator class must define member functions implementing -the iterator's core behaviors. The following table describes -expressions which are required to be valid depending on the category -of the derived iterator type. These member functions are described -briefly below and in more detail in the iterator facade -requirements.

-
- ---- - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionEffects
i.dereference()Access the value referred to
i.equal(j)Compare for equality with j
i.increment()Advance by one position
i.decrement()Retreat by one position
i.advance(n)Advance by n positions
i.distance_to(j)Measure the distance to j
-
- -

In addition to implementing the core interface functions, an iterator -derived from iterator_facade typically defines several -constructors. To model any of the standard iterator concepts, the -iterator must at least have a copy constructor. Also, if the iterator -type X is meant to be automatically interoperate with another -iterator type Y (as with constant and mutable iterators) then -there must be an implicit conversion from X to Y or from Y -to X (but not both), typically implemented as a conversion -constructor. Finally, if the iterator is to model Forward Traversal -Iterator or a more-refined iterator concept, a default constructor is -required.

-
-
-

Iterator Core Access

-

iterator_facade and the operator implementations need to be able -to access the core member functions in the derived class. Making the -core member functions public would expose an implementation detail to -the user. The design used here ensures that implementation details do -not appear in the public interface of the derived iterator type.

-

Preventing direct access to the core member functions has two -advantages. First, there is no possibility for the user to accidently -use a member function of the iterator when a member of the value_type -was intended. This has been an issue with smart pointer -implementations in the past. The second and main advantage is that -library implementers can freely exchange a hand-rolled iterator -implementation for one based on iterator_facade without fear of -breaking code that was accessing the public core member functions -directly.

-

In a naive implementation, keeping the derived class' core member -functions private would require it to grant friendship to -iterator_facade and each of the seven operators. In order to -reduce the burden of limiting access, iterator_core_access is -provided, a class that acts as a gateway to the core member functions -in the derived iterator class. The author of the derived class only -needs to grant friendship to iterator_core_access to make his core -member functions available to the library.

- - -

iterator_core_access will be typically implemented as an empty -class containing only private static member functions which invoke the -iterator core member functions. There is, however, no need to -standardize the gateway protocol. Note that even if -iterator_core_access used public member functions it would not -open a safety loophole, as every core member function preserves the -invariants of the iterator.

-
-
-

operator[]

-

The indexing operator for a generalized iterator presents special -challenges. A random access iterator's operator[] is only -required to return something convertible to its value_type. -Requiring that it return an lvalue would rule out currently-legal -random-access iterators which hold the referenced value in a data -member (e.g. counting_iterator), because *(p+n) is a reference -into the temporary iterator p+n, which is destroyed when -operator[] returns.

-

Writable iterators built with iterator_facade implement the -semantics required by the preferred resolution to issue 299 and -adopted by proposal n1550: the result of p[n] is an object -convertible to the iterator's value_type, and p[n] = x is -equivalent to *(p + n) = x (Note: This result object may be -implemented as a proxy containing a copy of p+n). This approach -will work properly for any random-access iterator regardless of the -other details of its implementation. A user who knows more about -the implementation of her iterator is free to implement an -operator[] that returns an lvalue in the derived iterator -class; it will hide the one supplied by iterator_facade from -clients of her iterator.

-
-
-

operator->

-

The reference type of a readable iterator (and today's input -iterator) need not in fact be a reference, so long as it is -convertible to the iterator's value_type. When the value_type -is a class, however, it must still be possible to access members -through operator->. Therefore, an iterator whose reference -type is not in fact a reference must return a proxy containing a copy -of the referenced value from its operator->.

-

The return types for iterator_facade's operator-> and -operator[] are not explicitly specified. Instead, those types -are described in terms of a set of requirements, which must be -satisfied by the iterator_facade implementation.

- - -- - - -
[Cop95](1, 2) [Coplien, 1995] Coplien, J., Curiously Recurring Template -Patterns, C++ Report, February 1995, pp. 24-27.
-
-
-
-

Reference

- - -
-template <
-    class Derived
-  , class Value
-  , class CategoryOrTraversal
-  , class Reference  = Value&
-  , class Difference = ptrdiff_t
->
-class iterator_facade {
-public:
-    typedef remove_const<Value>::type value_type;
-    typedef Reference reference;
-    typedef Value* pointer;
-    typedef Difference difference_type;
-    typedef /* see below */ iterator_category;
-
-    reference operator*() const;
-    /* see below */ operator->() const;
-    /* see below */ operator[](difference_type n) const;
-    Derived& operator++();
-    Derived operator++(int);
-    Derived& operator--();
-    Derived operator--(int);
-    Derived& operator+=(difference_type n);
-    Derived& operator-=(difference_type n);
-    Derived operator-(difference_type n) const;
-};
-
-// Comparison operators
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type // exposition
-operator ==(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator !=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-// Iterator difference
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-/* see below */
-operator-(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-          iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
-// Iterator addition
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (iterator_facade<Dr,V,TC,R,D> const&,
-                   typename Derived::difference_type n);
-
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (typename Derived::difference_type n,
-                   iterator_facade<Dr,V,TC,R,D> const&);
-
-

The iterator_category member of iterator_facade is

-
-iterator-category(CategoryOrTraversal, value_type, reference)
-
-

where iterator-category is defined as follows:

-
-iterator-category(C,R,V) :=
-   if (C is convertible to std::input_iterator_tag
-       || C is convertible to std::output_iterator_tag
-   )
-       return C
-
-   else if (C is not convertible to incrementable_traversal_tag)
-       the program is ill-formed
-
-   else return a type X satisfying the following two constraints:
-
-      1. X is convertible to X1, and not to any more-derived
-         type, where X1 is defined by:
-
-           if (R is a reference type
-               && C is convertible to forward_traversal_tag)
-           {
-               if (C is convertible to random_access_traversal_tag)
-                   X1 = random_access_iterator_tag
-               else if (C is convertible to bidirectional_traversal_tag)
-                   X1 = bidirectional_iterator_tag
-               else
-                   X1 = forward_iterator_tag
-           }
-           else
-           {
-               if (C is convertible to single_pass_traversal_tag
-                   && R is convertible to V)
-                   X1 = input_iterator_tag
-               else
-                   X1 = C
-           }
-
-      2. category-to-traversal(X) is convertible to the most
-         derived traversal tag type to which X is also
-         convertible, and not to any more-derived traversal tag
-         type.
-
-

[Note: the intention is to allow iterator_category to be one of -the five original category tags when convertibility to one of the -traversal tags would add no information]

- - - -

The enable_if_interoperable template used above is for exposition -purposes. The member operators should only be in an overload set -provided the derived types Dr1 and Dr2 are interoperable, -meaning that at least one of the types is convertible to the other. The -enable_if_interoperable approach uses SFINAE to take the operators -out of the overload set when the types are not interoperable. -The operators should behave as-if enable_if_interoperable -were defined to be:

-
-template <bool, typename> enable_if_interoperable_impl
-{};
-
-template <typename T> enable_if_interoperable_impl<true,T>
-{ typedef T type; };
-
-template<typename Dr1, typename Dr2, typename T>
-struct enable_if_interoperable
-  : enable_if_interoperable_impl<
-        is_convertible<Dr1,Dr2>::value || is_convertible<Dr2,Dr1>::value
-      , T
-    >
-{};
-
-
-

iterator_facade Requirements

-

The following table describes the typical valid expressions on -iterator_facade's Derived parameter, depending on the -iterator concept(s) it will model. The operations in the first -column must be made accessible to member functions of class -iterator_core_access. In addition, -static_cast<Derived*>(iterator_facade*) shall be well-formed.

-

In the table below, F is iterator_facade<X,V,C,R,D>, a is an -object of type X, b and c are objects of type const X, -n is an object of F::difference_type, y is a constant -object of a single pass iterator type interoperable with X, and z -is a constant object of a random access traversal iterator type -interoperable with X.

-
-

iterator_facade Core Operations

- ------ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionReturn TypeAssertion/NoteUsed to implement Iterator -Concept(s)
c.dereference()F::reference Readable Iterator, Writable -Iterator
c.equal(y)convertible to booltrue iff c and y -refer to the same -position.Single Pass Iterator
a.increment()unused Incrementable Iterator
a.decrement()unused Bidirectional Traversal -Iterator
a.advance(n)unused Random Access Traversal -Iterator
c.distance_to(z)convertible to -F::difference_typeequivalent to -distance(c, X(z)).Random Access Traversal -Iterator
-
-
-
-

iterator_facade operations

-

The operations in this section are described in terms of operations on -the core interface of Derived which may be inaccessible -(i.e. private). The implementation should access these operations -through member functions of class iterator_core_access.

-

reference operator*() const;

- --- - - - -
Returns:static_cast<Derived const*>(this)->dereference()
-

operator->() const; (see below)

- --- - - - -
Returns:

If reference is a reference type, an object -of type pointer equal to:

-
-&static_cast<Derived const*>(this)->dereference()
-
-

Otherwise returns an object of unspecified type such that, -(*static_cast<Derived const*>(this))->m is equivalent to (w = **static_cast<Derived const*>(this), -w.m) for some temporary object w of type value_type.

-
-

unspecified operator[](difference_type n) const;

- --- - - - -
Returns:an object convertible to value_type. For constant -objects v of type value_type, and n of type -difference_type, (*this)[n] = v is equivalent to -*(*this + n) = v, and static_cast<value_type -const&>((*this)[n]) is equivalent to -static_cast<value_type const&>(*(*this + n))
-

Derived& operator++();

- --- - - - -
Effects:
-static_cast<Derived*>(this)->increment();
-return *static_cast<Derived*>(this);
-
-
-

Derived operator++(int);

- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
-++*this;
-return tmp;
-
-
-

Derived& operator--();

- --- - - - -
Effects:
-static_cast<Derived*>(this)->decrement();
-return *static_cast<Derived*>(this);
-
-
-

Derived operator--(int);

- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
---*this;
-return tmp;
-
-
-

Derived& operator+=(difference_type n);

- --- - - - -
Effects:
-static_cast<Derived*>(this)->advance(n);
-return *static_cast<Derived*>(this);
-
-
-

Derived& operator-=(difference_type n);

- --- - - - -
Effects:
-static_cast<Derived*>(this)->advance(-n);
-return *static_cast<Derived*>(this);
-
-
-

Derived operator-(difference_type n) const;

- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
-return tmp -= n;
-
-
-
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (iterator_facade<Dr,V,TC,R,D> const&,
-                   typename Derived::difference_type n);
-
-template <class Dr, class V, class TC, class R, class D>
-Derived operator+ (typename Derived::difference_type n,
-                   iterator_facade<Dr,V,TC,R,D> const&);
-
- --- - - - -
Effects:
-Derived tmp(static_cast<Derived const*>(this));
-return tmp += n;
-
-
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator ==(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:if is_convertible<Dr2,Dr1>::value, then -lhs.equal(rhs). Otherwise, rhs.equal(lhs).
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator !=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:if is_convertible<Dr2,Dr1>::value, then -!lhs.equal(rhs). Otherwise, !rhs.equal(lhs).
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:if is_convertible<Dr2,Dr1>::value, then -lhs.distance_to(rhs) < 0. Otherwise, rhs.distance_to(lhs) > -0.
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator <=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:if is_convertible<Dr2,Dr1>::value, then -lhs.distance_to(rhs) <= 0. Otherwise, rhs.distance_to(lhs) ->= 0.
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:if is_convertible<Dr2,Dr1>::value, then -lhs.distance_to(rhs) > 0. Otherwise, -rhs.distance_to(lhs) < 0.
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,bool>::type
-operator >=(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-            iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - -
Returns:if is_convertible<Dr2,Dr1>::value, then -lhs.distance_to(rhs) >= 0. Otherwise, -rhs.distance_to(lhs) <= 0.
-
-template <class Dr1, class V1, class TC1, class R1, class D1,
-          class Dr2, class V2, class TC2, class R2, class D2>
-typename enable_if_interoperable<Dr1,Dr2,difference_type>::type
-operator -(iterator_facade<Dr1,V1,TC1,R1,D1> const& lhs,
-           iterator_facade<Dr2,V2,TC2,R2,D2> const& rhs);
-
- --- - - - - - -
Return Type:if is_convertible<Dr2,Dr1>::value, then difference_type shall be -iterator_traits<Dr1>::difference_type. Otherwise, -difference_type shall be -iterator_traits<Dr2>::difference_type.
Returns:if is_convertible<Dr2,Dr1>::value, then --lhs.distance_to(rhs). Otherwise, -rhs.distance_to(lhs).
-
-
-
-

Tutorial Example

- - - -

In this section we'll walk through the implementation of a few -iterators using iterator_facade, based around the simple -example of a linked list of polymorphic objects. This example was -inspired by a posting by Keith Macdonald on the Boost-Users -mailing list.

-
-

The Problem

-

Say we've written a polymorphic linked list node base class:

-
-# include <iostream>
-
-struct node_base
-{
-    node_base() : m_next(0) {}
-
-    // Each node manages all of its tail nodes
-    virtual ~node_base() { delete m_next; }
-
-    // Access the rest of the list
-    node_base* next() const { return m_next; }
-
-    // print to the stream
-    virtual void print(std::ostream& s) const = 0;
-    
-    // double the value
-    virtual void double_me() = 0;
-
-    void append(node_base* p)
-    {
-        if (m_next) 
-            m_next->append(p); 
-        else
-            m_next = p; 
-    }
-
- private:
-    node_base* m_next;
-};
-
-

Lists can hold objects of different types by linking together -specializations of the following template:

-
-template <class T>
-struct node : node_base
-{
-    node(T x)
-      : m_value(x)
-    {}
-
-    void print(std::ostream& s) const { s << this->m_value; }
-    void double_me() { m_value += m_value; }
-
- private:
-    T m_value;
-};
-
-

And we can print any node using the following streaming operator:

-
-inline std::ostream& operator<<(std::ostream& s, node_base const& n)
-{
-    n.print(s);
-    return s;
-}
-
-

Our first challenge is to build an appropriate iterator over these -lists.

-
-
-

A Basic Iterator Using iterator_facade

-

We will construct a node_iterator class using inheritance from -iterator_facade to implement most of the iterator's operations.

-
-# include "node.hpp"
-# include <boost/iterator/iterator_facade.hpp>
-
-class node_iterator
-  : public boost::iterator_facade<...>
-{
-   ...
-};
-
-
-

Template Arguments for iterator_facade

-

iterator_facade has several template parameters, so we must decide -what types to use for the arguments. The parameters are Derived, -Value, CategoryOrTraversal, Reference, and Difference.

-
-

Derived

-

Because iterator_facade is meant to be used with the CRTP -[Cop95] the first parameter is the iterator class name itself, -node_iterator.

-
-
-

Value

-

The Value parameter determines the node_iterator's -value_type. In this case, we are iterating over node_base -objects, so Value will be node_base.

-
-
-

CategoryOrTraversal

-

Now we have to determine which iterator traversal concept our -node_iterator is going to model. Singly-linked lists only have -forward links, so our iterator can't can't be a bidirectional -traversal iterator. Our iterator should be able to make multiple -passes over the same linked list (unlike, say, an -istream_iterator which consumes the stream it traverses), so it -must be a forward traversal iterator. Therefore, we'll pass -boost::forward_traversal_tag in this position 1.

- - - - - -
[1]iterator_facade also supports old-style category -tags, so we could have passed std::forward_iterator_tag here; -either way, the resulting iterator's iterator_category will -end up being std::forward_iterator_tag.
-
-
-

Reference

-

The Reference argument becomes the type returned by -node_iterator's dereference operation, and will also be the -same as std::iterator_traits<node_iterator>::reference. The -library's default for this parameter is Value&; since -node_base& is a good choice for the iterator's reference -type, we can omit this argument, or pass use_default.

-
-
-

Difference

-

The Difference argument determines how the distance between -two node_iterators will be measured and will also be the -same as std::iterator_traits<node_iterator>::difference_type. -The library's default for Difference is std::ptrdiff_t, an -appropriate type for measuring the distance between any two -addresses in memory, and one that works for almost any iterator, -so we can omit this argument, too.

-

The declaration of node_iterator will therefore look something -like:

-
-# include "node.hpp"
-# include <boost/iterator/iterator_facade.hpp>
-
-class node_iterator
-  : public boost::iterator_facade<
-        node_iterator
-      , node_base
-      , boost::forward_traversal_tag
-    >
-{
-   ...
-};
-
-
-
-
-

Constructors and Data Members

-

Next we need to decide how to represent the iterator's position. -This representation will take the form of data members, so we'll -also need to write constructors to initialize them. The -node_iterator's position is quite naturally represented using -a pointer to a node_base. We'll need a constructor to build an -iterator from a node_base*, and a default constructor to -satisfy the forward traversal iterator requirements 2. -Our node_iterator then becomes:

-
-# include "node.hpp"
-# include <boost/iterator/iterator_facade.hpp>
-
-class node_iterator
-  : public boost::iterator_facade<
-        node_iterator
-      , node_base
-      , boost::forward_traversal_tag
-    >
-{
- public:
-    node_iterator()
-      : m_node(0)
-    {}
-
-    explicit node_iterator(node_base* p)
-      : m_node(p)
-    {}
-
- private:
-    ...
-    node_base* m_node;
-};
-
- - - - - -
[2]Technically, the C++ standard places almost no -requirements on a default-constructed iterator, so if we were -really concerned with efficiency, we could've written the -default constructor to leave m_node uninitialized.
-
-
-

Implementing the Core Operations

-

The last step is to implement the core operations required by -the concepts we want our iterator to model. Referring to the -table, we can see that the first three rows are applicable -because node_iterator needs to satisfy the requirements for -readable iterator, single pass iterator, and incrementable -iterator.

-

We therefore need to supply dereference, -equal, and increment members. We don't want these members -to become part of node_iterator's public interface, so we can -make them private and grant friendship to -boost::iterator_core_access, a "back-door" that -iterator_facade uses to get access to the core operations:

-
-# include "node.hpp"
-# include <boost/iterator/iterator_facade.hpp>
-
-class node_iterator
-  : public boost::iterator_facade<
-        node_iterator
-      , node_base
-      , boost::forward_traversal_tag
-    >
-{
- public:
-    node_iterator()
-      : m_node(0) {}
-
-    explicit node_iterator(node_base* p)
-      : m_node(p) {}
-
- private:
-    friend class boost::iterator_core_access;
-
-    void increment() { m_node = m_node->next(); }
-
-    bool equal(node_iterator const& other) const
-    {
-        return this->m_node == other.m_node;
-    }
-
-    node_base& dereference() const { return *m_node; }
-
-    node_base* m_node;
-};
-
-

Voilà; a complete and conforming readable, forward-traversal -iterator! For a working example of its use, see this program.

-
-
-
-

A constant node_iterator

- -

Now, our node_iterator gives clients access to both node's print(std::ostream&) const member function, but also its -mutating double_me() member. If we wanted to build a -constant node_iterator, we'd only have to make three -changes:

-
-class const_node_iterator
-  : public boost::iterator_facade<
-        node_iterator
-      , node_base const
-      , boost::forward_traversal_tag
-    >
-{
- public:
-    const_node_iterator()
-      : m_node(0) {}
-
-    explicit const_node_iterator(node_base* p)
-      : m_node(p) {}
-
- private:
-    friend class boost::iterator_core_access;
-
-    void increment() { m_node = m_node->next(); }
-
-    bool equal(const_node_iterator const& other) const
-    {
-        return this->m_node == other.m_node;
-    }
-
-    node_base const& dereference() const { return *m_node; }
-
-    node_base const* m_node;
-};
-
- -

As a matter of fact, node_iterator and const_node_iterator -are so similar that it makes sense to factor the common code out -into a template as follows:

-
-template <class Value>
-class node_iter
-  : public boost::iterator_facade<
-        node_iter<Value>
-      , Value
-      , boost::forward_traversal_tag
-    >
-{
- public:
-    node_iter()
-      : m_node(0) {}
-
-    explicit node_iter(Value* p)
-      : m_node(p) {}
-
- private:
-    friend class boost::iterator_core_access;
-
-    bool equal(node_iter<Value> const& other) const
-    {
-        return this->m_node == other.m_node;
-    }
-
-    void increment()
-    { m_node = m_node->next(); }
-
-    Value& dereference() const
-    { return *m_node; }
-
-    Value* m_node;
-};
-typedef node_iter<node_base> node_iterator;
-typedef node_iter<node_base const> node_const_iterator;
-
-
-
-

Interoperability

-

Our const_node_iterator works perfectly well on its own, but -taken together with node_iterator it doesn't quite meet -expectations. For example, we'd like to be able to pass a -node_iterator where a node_const_iterator was expected, -just as you can with std::list<int>'s iterator and -const_iterator. Furthermore, given a node_iterator and a -node_const_iterator into the same list, we should be able to -compare them for equality.

-

This expected ability to use two different iterator types together -is known as interoperability. Achieving interoperability in -our case is as simple as templatizing the equal function and -adding a templatized converting constructor 3 4:

-
-template <class Value>
-class node_iter
-  : public boost::iterator_facade<
-        node_iter<Value>
-      , Value
-      , boost::forward_traversal_tag
-    >
-{
- public:
-    node_iter()
-      : m_node(0) {}
-
-    explicit node_iter(Value* p)
-      : m_node(p) {}
-
-    template <class OtherValue>
-    node_iter(node_iter<OtherValue> const& other)
-      : m_node(other.m_node) {}
-
- private:
-    friend class boost::iterator_core_access;
-    template <class> friend class node_iter;
-
-    template <class OtherValue>
-    bool equal(node_iter<OtherValue> const& other) const
-    { 
-        return this->m_node == other.m_node;
-    }
-
-    void increment()
-    { m_node = m_node->next(); }
-
-    Value& dereference() const
-    { return *m_node; }
-
-    Value* m_node;
-};
-typedef impl::node_iterator<node_base> node_iterator;
-typedef impl::node_iterator<node_base const> node_const_iterator;
-
- - - - - -
[3]If you're using an older compiler and it can't handle -this example, see the example code for workarounds.
- - - - - -
[4]If node_iterator had been a random access -traversal iterator, we'd have had to templatize its -distance_to function as well.
-

You can see an example program which exercises our interoperable -iterators here.

-
-
-

Telling the Truth

-

Now node_iterator and node_const_iterator behave exactly as -you'd expect... almost. We can compare them and we can convert in -one direction: from node_iterator to node_const_iterator. -If we try to convert from node_const_iterator to -node_iterator, we'll get an error when the converting -constructor tries to initialize node_iterator's m_node, a -node* with a node const*. So what's the problem?

-

The problem is that -boost::is_convertible<node_const_iterator,node_iterator>::value -will be true, but it should be false. is_convertible -lies because it can only see as far as the declaration of -node_iter's converting constructor, but can't look inside at -the definition to make sure it will compile. A perfect solution -would make node_iter's converting constructor disappear when -the m_node conversion would fail.

-

In fact, that sort of magic is possible using -boost::enable_if. By rewriting the converting constructor as -follows, we can remove it from the overload set when it's not -appropriate:

-
-#include <boost/type_traits/is_convertible.hpp>
-#include <boost/utility/enable_if.hpp>
-
-  ...
-
-  template <class OtherValue>
-  node_iter(
-      node_iter<OtherValue> const& other
-    , typename boost::enable_if<
-          boost::is_convertible<OtherValue*,Value*>
-        , enabler
-      >::type = enabler()
-  )
-    : m_node(other.m_node) {}
-
-
-
-

Wrap Up

-

This concludes our iterator_facade tutorial, but before you -stop reading we urge you to take a look at iterator_adaptor. -There's another way to approach writing these iterators which might -even be superior.

-
-
-
- - - - diff --git a/doc/iterator_facade.rst b/doc/iterator_facade.rst deleted file mode 100644 index 41a775f..0000000 --- a/doc/iterator_facade.rst +++ /dev/null @@ -1,40 +0,0 @@ -++++++++++++++++ - Iterator Facade -++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: - - .. include:: iterator_facade_abstract.rst - -.. contents:: Table of Contents - -Overview -======== - -.. include:: iterator_facade_body.rst - - -Reference -========= - -.. include:: iterator_facade_ref.rst - -.. _counting: counting_iterator.html - -Tutorial Example -================ - -.. include:: iterator_facade_tutorial.rst - diff --git a/doc/iterator_facade_abstract.rst b/doc/iterator_facade_abstract.rst deleted file mode 100644 index f024b9b..0000000 --- a/doc/iterator_facade_abstract.rst +++ /dev/null @@ -1,4 +0,0 @@ -``iterator_facade`` is a base class template that implements the -interface of standard iterators in terms of a few core functions -and associated types, to be supplied by a derived iterator class. - diff --git a/doc/iterator_facade_body.rst b/doc/iterator_facade_body.rst deleted file mode 100644 index 82f57a1..0000000 --- a/doc/iterator_facade_body.rst +++ /dev/null @@ -1,192 +0,0 @@ -.. Version 1.1 of this ReStructuredText document corresponds to - n1530_, the paper accepted by the LWG for TR1. - -.. Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All - rights reserved - - -While the iterator interface is rich, there is a core subset of the -interface that is necessary for all the functionality. We have -identified the following core behaviors for iterators: - -* dereferencing -* incrementing -* decrementing -* equality comparison -* random-access motion -* distance measurement - -In addition to the behaviors listed above, the core interface elements -include the associated types exposed through iterator traits: -``value_type``, ``reference``, ``difference_type``, and -``iterator_category``. - -Iterator facade uses the Curiously Recurring Template -Pattern (CRTP) [Cop95]_ so that the user can specify the behavior -of ``iterator_facade`` in a derived class. Former designs used -policy objects to specify the behavior, but that approach was -discarded for several reasons: - - 1. the creation and eventual copying of the policy object may create - overhead that can be avoided with the current approach. - - 2. The policy object approach does not allow for custom constructors - on the created iterator types, an essential feature if - ``iterator_facade`` should be used in other library - implementations. - - 3. Without the use of CRTP, the standard requirement that an - iterator's ``operator++`` returns the iterator type itself - would mean that all iterators built with the library would - have to be specializations of ``iterator_facade<...>``, rather - than something more descriptive like - ``indirect_iterator``. Cumbersome type generator - metafunctions would be needed to build new parameterized - iterators, and a separate ``iterator_adaptor`` layer would be - impossible. - -Usage ------ - -The user of ``iterator_facade`` derives his iterator class from a -specialization of ``iterator_facade`` and passes the derived -iterator class as ``iterator_facade``\ 's first template parameter. -The order of the other template parameters have been carefully -chosen to take advantage of useful defaults. For example, when -defining a constant lvalue iterator, the user can pass a -const-qualified version of the iterator's ``value_type`` as -``iterator_facade``\ 's ``Value`` parameter and omit the -``Reference`` parameter which follows. - -The derived iterator class must define member functions implementing -the iterator's core behaviors. The following table describes -expressions which are required to be valid depending on the category -of the derived iterator type. These member functions are described -briefly below and in more detail in the iterator facade -requirements. - - +------------------------+-------------------------------+ - |Expression |Effects | - +========================+===============================+ - |``i.dereference()`` |Access the value referred to | - +------------------------+-------------------------------+ - |``i.equal(j)`` |Compare for equality with ``j``| - +------------------------+-------------------------------+ - |``i.increment()`` |Advance by one position | - +------------------------+-------------------------------+ - |``i.decrement()`` |Retreat by one position | - +------------------------+-------------------------------+ - |``i.advance(n)`` |Advance by ``n`` positions | - +------------------------+-------------------------------+ - |``i.distance_to(j)`` |Measure the distance to ``j`` | - +------------------------+-------------------------------+ - -.. Should we add a comment that a zero overhead implementation of iterator_facade - is possible with proper inlining? - -In addition to implementing the core interface functions, an iterator -derived from ``iterator_facade`` typically defines several -constructors. To model any of the standard iterator concepts, the -iterator must at least have a copy constructor. Also, if the iterator -type ``X`` is meant to be automatically interoperate with another -iterator type ``Y`` (as with constant and mutable iterators) then -there must be an implicit conversion from ``X`` to ``Y`` or from ``Y`` -to ``X`` (but not both), typically implemented as a conversion -constructor. Finally, if the iterator is to model Forward Traversal -Iterator or a more-refined iterator concept, a default constructor is -required. - - - -Iterator Core Access --------------------- - -``iterator_facade`` and the operator implementations need to be able -to access the core member functions in the derived class. Making the -core member functions public would expose an implementation detail to -the user. The design used here ensures that implementation details do -not appear in the public interface of the derived iterator type. - -Preventing direct access to the core member functions has two -advantages. First, there is no possibility for the user to accidently -use a member function of the iterator when a member of the value_type -was intended. This has been an issue with smart pointer -implementations in the past. The second and main advantage is that -library implementers can freely exchange a hand-rolled iterator -implementation for one based on ``iterator_facade`` without fear of -breaking code that was accessing the public core member functions -directly. - -In a naive implementation, keeping the derived class' core member -functions private would require it to grant friendship to -``iterator_facade`` and each of the seven operators. In order to -reduce the burden of limiting access, ``iterator_core_access`` is -provided, a class that acts as a gateway to the core member functions -in the derived iterator class. The author of the derived class only -needs to grant friendship to ``iterator_core_access`` to make his core -member functions available to the library. - -.. This is no long uptodate -thw -.. Yes it is; I made sure of it! -DWA - -``iterator_core_access`` will be typically implemented as an empty -class containing only private static member functions which invoke the -iterator core member functions. There is, however, no need to -standardize the gateway protocol. Note that even if -``iterator_core_access`` used public member functions it would not -open a safety loophole, as every core member function preserves the -invariants of the iterator. - -``operator[]`` --------------- - -The indexing operator for a generalized iterator presents special -challenges. A random access iterator's ``operator[]`` is only -required to return something convertible to its ``value_type``. -Requiring that it return an lvalue would rule out currently-legal -random-access iterators which hold the referenced value in a data -member (e.g. |counting|_), because ``*(p+n)`` is a reference -into the temporary iterator ``p+n``, which is destroyed when -``operator[]`` returns. - -.. |counting| replace:: ``counting_iterator`` - -Writable iterators built with ``iterator_facade`` implement the -semantics required by the preferred resolution to `issue 299`_ and -adopted by proposal n1550_: the result of ``p[n]`` is an object -convertible to the iterator's ``value_type``, and ``p[n] = x`` is -equivalent to ``*(p + n) = x`` (Note: This result object may be -implemented as a proxy containing a copy of ``p+n``). This approach -will work properly for any random-access iterator regardless of the -other details of its implementation. A user who knows more about -the implementation of her iterator is free to implement an -``operator[]`` that returns an lvalue in the derived iterator -class; it will hide the one supplied by ``iterator_facade`` from -clients of her iterator. - -.. _n1550: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/papers/2003/n1550.html - -.. _`issue 299`: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#299 - -.. _`operator arrow`: - - -``operator->`` --------------- - -The ``reference`` type of a readable iterator (and today's input -iterator) need not in fact be a reference, so long as it is -convertible to the iterator's ``value_type``. When the ``value_type`` -is a class, however, it must still be possible to access members -through ``operator->``. Therefore, an iterator whose ``reference`` -type is not in fact a reference must return a proxy containing a copy -of the referenced value from its ``operator->``. - -The return types for ``iterator_facade``\ 's ``operator->`` and -``operator[]`` are not explicitly specified. Instead, those types -are described in terms of a set of requirements, which must be -satisfied by the ``iterator_facade`` implementation. - -.. [Cop95] [Coplien, 1995] Coplien, J., Curiously Recurring Template - Patterns, C++ Report, February 1995, pp. 24-27. - diff --git a/doc/iterator_facade_ref.rst b/doc/iterator_facade_ref.rst deleted file mode 100644 index 4ec61b5..0000000 --- a/doc/iterator_facade_ref.rst +++ /dev/null @@ -1,394 +0,0 @@ -.. Version 1.3 of this ReStructuredText document corresponds to - n1530_, the paper accepted by the LWG for TR1. - -.. Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All - rights reserved - - -.. parsed-literal:: - - template < - class Derived - , class Value - , class CategoryOrTraversal - , class Reference = Value& - , class Difference = ptrdiff_t - > - class iterator_facade { - public: - typedef remove_const::type value_type; - typedef Reference reference; - typedef Value\* pointer; - typedef Difference difference_type; - typedef /* see below__ \*/ iterator_category; - - reference operator\*() const; - /* see below__ \*/ operator->() const; - /* see below__ \*/ operator[](difference_type n) const; - Derived& operator++(); - Derived operator++(int); - Derived& operator--(); - Derived operator--(int); - Derived& operator+=(difference_type n); - Derived& operator-=(difference_type n); - Derived operator-(difference_type n) const; - }; - - // Comparison operators - template - typename enable_if_interoperable::type // exposition - operator ==(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator !=(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator <(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator <=(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator >(iterator_facade const& lhs, - iterator_facade const& rhs); - - template - typename enable_if_interoperable::type - operator >=(iterator_facade const& lhs, - iterator_facade const& rhs); - - // Iterator difference - template - /* see below__ \*/ - operator-(iterator_facade const& lhs, - iterator_facade const& rhs); - - // Iterator addition - template - Derived operator+ (iterator_facade const&, - typename Derived::difference_type n); - - template - Derived operator+ (typename Derived::difference_type n, - iterator_facade const&); - -__ `iterator category`_ - -__ `operator arrow`_ - -__ brackets_ - -__ minus_ - -.. _`iterator category`: - -The ``iterator_category`` member of ``iterator_facade`` is - -.. parsed-literal:: - - *iterator-category*\ (CategoryOrTraversal, value_type, reference) - -where *iterator-category* is defined as follows: - -.. include:: facade_iterator_category.rst - -The ``enable_if_interoperable`` template used above is for exposition -purposes. The member operators should only be in an overload set -provided the derived types ``Dr1`` and ``Dr2`` are interoperable, -meaning that at least one of the types is convertible to the other. The -``enable_if_interoperable`` approach uses SFINAE to take the operators -out of the overload set when the types are not interoperable. -The operators should behave *as-if* ``enable_if_interoperable`` -were defined to be:: - - template enable_if_interoperable_impl - {}; - - template enable_if_interoperable_impl - { typedef T type; }; - - template - struct enable_if_interoperable - : enable_if_interoperable_impl< - is_convertible::value || is_convertible::value - , T - > - {}; - - -``iterator_facade`` Requirements --------------------------------- - -The following table describes the typical valid expressions on -``iterator_facade``\ 's ``Derived`` parameter, depending on the -iterator concept(s) it will model. The operations in the first -column must be made accessible to member functions of class -``iterator_core_access``. In addition, -``static_cast(iterator_facade*)`` shall be well-formed. - -In the table below, ``F`` is ``iterator_facade``, ``a`` is an -object of type ``X``, ``b`` and ``c`` are objects of type ``const X``, -``n`` is an object of ``F::difference_type``, ``y`` is a constant -object of a single pass iterator type interoperable with ``X``, and ``z`` -is a constant object of a random access traversal iterator type -interoperable with ``X``. - -.. _`core operations`: - -.. topic:: ``iterator_facade`` Core Operations - - +--------------------+----------------------+-------------------------+---------------------------+ - |Expression |Return Type |Assertion/Note |Used to implement Iterator | - | | | |Concept(s) | - +====================+======================+=========================+===========================+ - |``c.dereference()`` |``F::reference`` | |Readable Iterator, Writable| - | | | |Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - |``c.equal(y)`` |convertible to bool |true iff ``c`` and ``y`` |Single Pass Iterator | - | | |refer to the same | | - | | |position. | | - +--------------------+----------------------+-------------------------+---------------------------+ - |``a.increment()`` |unused | |Incrementable Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - |``a.decrement()`` |unused | |Bidirectional Traversal | - | | | |Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - |``a.advance(n)`` |unused | |Random Access Traversal | - | | | |Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - |``c.distance_to(z)``|convertible to |equivalent to |Random Access Traversal | - | |``F::difference_type``|``distance(c, X(z))``. |Iterator | - +--------------------+----------------------+-------------------------+---------------------------+ - - - -``iterator_facade`` operations ------------------------------- - -The operations in this section are described in terms of operations on -the core interface of ``Derived`` which may be inaccessible -(i.e. private). The implementation should access these operations -through member functions of class ``iterator_core_access``. - -``reference operator*() const;`` - -:Returns: ``static_cast(this)->dereference()`` - -``operator->() const;`` (see below__) - -__ `operator arrow`_ - -:Returns: If ``reference`` is a reference type, an object - of type ``pointer`` equal to:: - - &static_cast(this)->dereference() - - Otherwise returns an object of unspecified type such that, - ``(*static_cast(this))->m`` is equivalent to ``(w = **static_cast(this), - w.m)`` for some temporary object ``w`` of type ``value_type``. - -.. _brackets: - -*unspecified* ``operator[](difference_type n) const;`` - -:Returns: an object convertible to ``value_type``. For constant - objects ``v`` of type ``value_type``, and ``n`` of type - ``difference_type``, ``(*this)[n] = v`` is equivalent to - ``*(*this + n) = v``, and ``static_cast((*this)[n])`` is equivalent to - ``static_cast(*(*this + n))`` - - - -``Derived& operator++();`` - -:Effects: - - :: - - static_cast(this)->increment(); - return *static_cast(this); - -``Derived operator++(int);`` - -:Effects: - - :: - - Derived tmp(static_cast(this)); - ++*this; - return tmp; - - -``Derived& operator--();`` - -:Effects: - - :: - - static_cast(this)->decrement(); - return *static_cast(this); - - -``Derived operator--(int);`` - -:Effects: - - :: - - Derived tmp(static_cast(this)); - --*this; - return tmp; - - -``Derived& operator+=(difference_type n);`` - -:Effects: - - :: - - static_cast(this)->advance(n); - return *static_cast(this); - - -``Derived& operator-=(difference_type n);`` - -:Effects: - - :: - - static_cast(this)->advance(-n); - return *static_cast(this); - - -``Derived operator-(difference_type n) const;`` - -:Effects: - - :: - - Derived tmp(static_cast(this)); - return tmp -= n; - -:: - - template - Derived operator+ (iterator_facade const&, - typename Derived::difference_type n); - - template - Derived operator+ (typename Derived::difference_type n, - iterator_facade const&); - -:Effects: - - :: - - Derived tmp(static_cast(this)); - return tmp += n; - - -:: - - template - typename enable_if_interoperable::type - operator ==(iterator_facade const& lhs, - iterator_facade const& rhs); - -:Returns: if ``is_convertible::value``, then - ``lhs.equal(rhs)``. Otherwise, ``rhs.equal(lhs)``. - -:: - - template - typename enable_if_interoperable::type - operator !=(iterator_facade const& lhs, - iterator_facade const& rhs); - -:Returns: if ``is_convertible::value``, then - ``!lhs.equal(rhs)``. Otherwise, ``!rhs.equal(lhs)``. - -:: - - template - typename enable_if_interoperable::type - operator <(iterator_facade const& lhs, - iterator_facade const& rhs); - -:Returns: if ``is_convertible::value``, then - ``lhs.distance_to(rhs) < 0``. Otherwise, ``rhs.distance_to(lhs) > - 0``. - -:: - - template - typename enable_if_interoperable::type - operator <=(iterator_facade const& lhs, - iterator_facade const& rhs); - -:Returns: if ``is_convertible::value``, then - ``lhs.distance_to(rhs) <= 0``. Otherwise, ``rhs.distance_to(lhs) - >= 0``. - -:: - - template - typename enable_if_interoperable::type - operator >(iterator_facade const& lhs, - iterator_facade const& rhs); - -:Returns: if ``is_convertible::value``, then - ``lhs.distance_to(rhs) > 0``. Otherwise, - ``rhs.distance_to(lhs) < 0``. - - -:: - - template - typename enable_if_interoperable::type - operator >=(iterator_facade const& lhs, - iterator_facade const& rhs); - -:Returns: if ``is_convertible::value``, then - ``lhs.distance_to(rhs) >= 0``. Otherwise, - ``rhs.distance_to(lhs) <= 0``. - -.. _minus: - -:: - - template - typename enable_if_interoperable::type - operator -(iterator_facade const& lhs, - iterator_facade const& rhs); - -:Return Type: if ``is_convertible::value``, then ``difference_type`` shall be - ``iterator_traits::difference_type``. Otherwise, - ``difference_type`` shall be - ``iterator_traits::difference_type``. - -:Returns: if ``is_convertible::value``, then - ``-lhs.distance_to(rhs)``. Otherwise, - ``rhs.distance_to(lhs)``. diff --git a/doc/iterator_facade_tutorial.rst b/doc/iterator_facade_tutorial.rst deleted file mode 100755 index 10980ed..0000000 --- a/doc/iterator_facade_tutorial.rst +++ /dev/null @@ -1,519 +0,0 @@ -.. 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) - -In this section we'll walk through the implementation of a few -iterators using ``iterator_facade``, based around the simple -example of a linked list of polymorphic objects. This example was -inspired by a `posting`__ by Keith Macdonald on the `Boost-Users`_ -mailing list. - -.. _`Boost-Users`: ../../../more/mailing_lists.htm#users - -__ http://thread.gmane.org/gmane.comp.lib.boost.user/5100 - -The Problem ------------ - -Say we've written a polymorphic linked list node base class:: - - # include - - struct node_base - { - node_base() : m_next(0) {} - - // Each node manages all of its tail nodes - virtual ~node_base() { delete m_next; } - - // Access the rest of the list - node_base* next() const { return m_next; } - - // print to the stream - virtual void print(std::ostream& s) const = 0; - - // double the value - virtual void double_me() = 0; - - void append(node_base* p) - { - if (m_next) - m_next->append(p); - else - m_next = p; - } - - private: - node_base* m_next; - }; - -Lists can hold objects of different types by linking together -specializations of the following template:: - - template - struct node : node_base - { - node(T x) - : m_value(x) - {} - - void print(std::ostream& s) const { s << this->m_value; } - void double_me() { m_value += m_value; } - - private: - T m_value; - }; - -And we can print any node using the following streaming operator:: - - inline std::ostream& operator<<(std::ostream& s, node_base const& n) - { - n.print(s); - return s; - } - -Our first challenge is to build an appropriate iterator over these -lists. - -A Basic Iterator Using ``iterator_facade`` ------------------------------------------- - -We will construct a ``node_iterator`` class using inheritance from -``iterator_facade`` to implement most of the iterator's operations. - -:: - - # include "node.hpp" - # include - - class node_iterator - : public boost::iterator_facade<...> - { - ... - }; - - - -Template Arguments for ``iterator_facade`` -.......................................... - -``iterator_facade`` has several template parameters, so we must decide -what types to use for the arguments. The parameters are ``Derived``, -``Value``, ``CategoryOrTraversal``, ``Reference``, and ``Difference``. - - -``Derived`` -''''''''''' - -Because ``iterator_facade`` is meant to be used with the CRTP -[Cop95]_ the first parameter is the iterator class name itself, -``node_iterator``. - -``Value`` -''''''''' - -The ``Value`` parameter determines the ``node_iterator``\ 's -``value_type``. In this case, we are iterating over ``node_base`` -objects, so ``Value`` will be ``node_base``. - - -``CategoryOrTraversal`` -''''''''''''''''''''''' - -Now we have to determine which `iterator traversal concept`_ our -``node_iterator`` is going to model. Singly-linked lists only have -forward links, so our iterator can't can't be a `bidirectional -traversal iterator`_. Our iterator should be able to make multiple -passes over the same linked list (unlike, say, an -``istream_iterator`` which consumes the stream it traverses), so it -must be a `forward traversal iterator`_. Therefore, we'll pass -``boost::forward_traversal_tag`` in this position [#category]_. - -.. [#category] ``iterator_facade`` also supports old-style category - tags, so we could have passed ``std::forward_iterator_tag`` here; - either way, the resulting iterator's ``iterator_category`` will - end up being ``std::forward_iterator_tag``. - -``Reference`` -''''''''''''' - -The ``Reference`` argument becomes the type returned by -``node_iterator``\ 's dereference operation, and will also be the -same as ``std::iterator_traits::reference``. The -library's default for this parameter is ``Value&``; since -``node_base&`` is a good choice for the iterator's ``reference`` -type, we can omit this argument, or pass ``use_default``. - -``Difference`` -'''''''''''''' - -The ``Difference`` argument determines how the distance between -two ``node_iterator``\ s will be measured and will also be the -same as ``std::iterator_traits::difference_type``. -The library's default for ``Difference`` is ``std::ptrdiff_t``, an -appropriate type for measuring the distance between any two -addresses in memory, and one that works for almost any iterator, -so we can omit this argument, too. - -The declaration of ``node_iterator`` will therefore look something -like:: - - # include "node.hpp" - # include - - class node_iterator - : public boost::iterator_facade< - node_iterator - , node_base - , boost::forward_traversal_tag - > - { - ... - }; - -Constructors and Data Members -............................. - -Next we need to decide how to represent the iterator's position. -This representation will take the form of data members, so we'll -also need to write constructors to initialize them. The -``node_iterator``\ 's position is quite naturally represented using -a pointer to a ``node_base``. We'll need a constructor to build an -iterator from a ``node_base*``, and a default constructor to -satisfy the `forward traversal iterator`_ requirements [#default]_. -Our ``node_iterator`` then becomes:: - - # include "node.hpp" - # include - - class node_iterator - : public boost::iterator_facade< - node_iterator - , node_base - , boost::forward_traversal_tag - > - { - public: - node_iterator() - : m_node(0) - {} - - explicit node_iterator(node_base* p) - : m_node(p) - {} - - private: - ... - node_base* m_node; - }; - -.. [#default] Technically, the C++ standard places almost no - requirements on a default-constructed iterator, so if we were - really concerned with efficiency, we could've written the - default constructor to leave ``m_node`` uninitialized. - -Implementing the Core Operations -................................ - -The last step is to implement the `core operations`_ required by -the concepts we want our iterator to model. Referring to the -table__, we can see that the first three rows are applicable -because ``node_iterator`` needs to satisfy the requirements for -`readable iterator`_, `single pass iterator`_, and `incrementable -iterator`_. - -__ `core operations`_ - -We therefore need to supply ``dereference``, -``equal``, and ``increment`` members. We don't want these members -to become part of ``node_iterator``\ 's public interface, so we can -make them private and grant friendship to -``boost::iterator_core_access``, a "back-door" that -``iterator_facade`` uses to get access to the core operations:: - - # include "node.hpp" - # include - - class node_iterator - : public boost::iterator_facade< - node_iterator - , node_base - , boost::forward_traversal_tag - > - { - public: - node_iterator() - : m_node(0) {} - - explicit node_iterator(node_base* p) - : m_node(p) {} - - private: - friend class boost::iterator_core_access; - - void increment() { m_node = m_node->next(); } - - bool equal(node_iterator const& other) const - { - return this->m_node == other.m_node; - } - - node_base& dereference() const { return *m_node; } - - node_base* m_node; - }; - -Voilà; a complete and conforming readable, forward-traversal -iterator! For a working example of its use, see `this program`__. - -__ ../example/node_iterator1.cpp - -A constant ``node_iterator`` ----------------------------- - -.. Sidebar:: Constant and Mutable iterators - - The term **mutable iterator** means an iterator through which - the object it references (its "referent") can be modified. A - **constant iterator** is one which doesn't allow modification of - its referent. - - The words *constant* and *mutable* don't refer to the ability to - modify the iterator itself. For example, an ``int const*`` is a - non-\ ``const`` *constant iterator*, which can be incremented - but doesn't allow modification of its referent, and ``int* - const`` is a ``const`` *mutable iterator*, which cannot be - modified but which allows modification of its referent. - - Confusing? We agree, but those are the standard terms. It - probably doesn't help much that a container's constant iterator - is called ``const_iterator``. - -Now, our ``node_iterator`` gives clients access to both ``node``\ -'s ``print(std::ostream&) const`` member function, but also its -mutating ``double_me()`` member. If we wanted to build a -*constant* ``node_iterator``, we'd only have to make three -changes: - -.. parsed-literal:: - - class const_node_iterator - : public boost::iterator_facade< - node_iterator - , node_base **const** - , boost::forward_traversal_tag - > - { - public: - const_node_iterator() - : m_node(0) {} - - explicit const_node_iterator(node_base* p) - : m_node(p) {} - - private: - friend class boost::iterator_core_access; - - void increment() { m_node = m_node->next(); } - - bool equal(const_node_iterator const& other) const - { - return this->m_node == other.m_node; - } - - node_base **const**\ & dereference() const { return \*m_node; } - - node_base **const**\ * m_node; - }; - -.. Sidebar:: ``const`` and an iterator's ``value_type`` - - The C++ standard requires an iterator's ``value_type`` *not* be - ``const``\ -qualified, so ``iterator_facade`` strips the - ``const`` from its ``Value`` parameter in order to produce the - iterator's ``value_type``. Making the ``Value`` argument - ``const`` provides a useful hint to ``iterator_facade`` that the - iterator is a *constant iterator*, and the default ``Reference`` - argument will be correct for all lvalue iterators. - -As a matter of fact, ``node_iterator`` and ``const_node_iterator`` -are so similar that it makes sense to factor the common code out -into a template as follows:: - - template - class node_iter - : public boost::iterator_facade< - node_iter - , Value - , boost::forward_traversal_tag - > - { - public: - node_iter() - : m_node(0) {} - - explicit node_iter(Value* p) - : m_node(p) {} - - private: - friend class boost::iterator_core_access; - - bool equal(node_iter const& other) const - { - return this->m_node == other.m_node; - } - - void increment() - { m_node = m_node->next(); } - - Value& dereference() const - { return *m_node; } - - Value* m_node; - }; - typedef node_iter node_iterator; - typedef node_iter node_const_iterator; - - -Interoperability ----------------- - -Our ``const_node_iterator`` works perfectly well on its own, but -taken together with ``node_iterator`` it doesn't quite meet -expectations. For example, we'd like to be able to pass a -``node_iterator`` where a ``node_const_iterator`` was expected, -just as you can with ``std::list``\ 's ``iterator`` and -``const_iterator``. Furthermore, given a ``node_iterator`` and a -``node_const_iterator`` into the same list, we should be able to -compare them for equality. - -This expected ability to use two different iterator types together -is known as |interoperability|_. Achieving interoperability in -our case is as simple as templatizing the ``equal`` function and -adding a templatized converting constructor [#broken]_ [#random]_:: - - template - class node_iter - : public boost::iterator_facade< - node_iter - , Value - , boost::forward_traversal_tag - > - { - public: - node_iter() - : m_node(0) {} - - explicit node_iter(Value* p) - : m_node(p) {} - - template - node_iter(node_iter const& other) - : m_node(other.m_node) {} - - private: - friend class boost::iterator_core_access; - template friend class node_iter; - - template - bool equal(node_iter const& other) const - { - return this->m_node == other.m_node; - } - - void increment() - { m_node = m_node->next(); } - - Value& dereference() const - { return *m_node; } - - Value* m_node; - }; - typedef impl::node_iterator node_iterator; - typedef impl::node_iterator node_const_iterator; - -.. |interoperability| replace:: **interoperability** -.. _interoperability: new-iter-concepts.html#interoperable-iterators-lib-interoperable-iterators - -.. [#broken] If you're using an older compiler and it can't handle - this example, see the `example code`__ for workarounds. - -.. [#random] If ``node_iterator`` had been a `random access - traversal iterator`_, we'd have had to templatize its - ``distance_to`` function as well. - - -__ ../example/node_iterator2.hpp - -You can see an example program which exercises our interoperable -iterators `here`__. - -__ ../example/node_iterator2.cpp - -Telling the Truth ------------------ - -Now ``node_iterator`` and ``node_const_iterator`` behave exactly as -you'd expect... almost. We can compare them and we can convert in -one direction: from ``node_iterator`` to ``node_const_iterator``. -If we try to convert from ``node_const_iterator`` to -``node_iterator``, we'll get an error when the converting -constructor tries to initialize ``node_iterator``\ 's ``m_node``, a -``node*`` with a ``node const*``. So what's the problem? - -The problem is that -``boost::``\ |is_convertible|_\ ``::value`` -will be ``true``, but it should be ``false``. |is_convertible|_ -lies because it can only see as far as the *declaration* of -``node_iter``\ 's converting constructor, but can't look inside at -the *definition* to make sure it will compile. A perfect solution -would make ``node_iter``\ 's converting constructor disappear when -the ``m_node`` conversion would fail. - -.. |is_convertible| replace:: ``is_convertible`` -.. _is_convertible: ../../type_traits/index.html#relationships - -In fact, that sort of magic is possible using -|enable_if|__. By rewriting the converting constructor as -follows, we can remove it from the overload set when it's not -appropriate:: - - #include - #include - - ... - - template - node_iter( - node_iter const& other - , typename boost::enable_if< - boost::is_convertible - , enabler - >::type = enabler() - ) - : m_node(other.m_node) {} - -.. |enable_if| replace:: ``boost::enable_if`` -__ ../../utility/enable_if.html - - -Wrap Up -------- - -This concludes our ``iterator_facade`` tutorial, but before you -stop reading we urge you to take a look at |iterator_adaptor|__. -There's another way to approach writing these iterators which might -even be superior. - -.. |iterator_adaptor| replace:: ``iterator_adaptor`` -__ iterator_adaptor.html - -.. _`iterator traversal concept`: new-iter-concepts.html#iterator-traversal-concepts-lib-iterator-traversal -.. _`readable iterator`: new-iter-concepts.html#readable-iterators-lib-readable-iterators -.. _`lvalue iterator`: new-iter-concepts.html#lvalue-iterators-lib-lvalue-iterators -.. _`single pass iterator`: new-iter-concepts.html#single-pass-iterators-lib-single-pass-iterators -.. _`incrementable iterator`: new-iter-concepts.html#incrementable-iterators-lib-incrementable-iterators -.. _`forward traversal iterator`: new-iter-concepts.html#forward-traversal-iterators-lib-forward-traversal-iterators -.. _`bidirectional traversal iterator`: new-iter-concepts.html#bidirectional-traversal-iterators-lib-bidirectional-traversal-iterators -.. _`random access traversal iterator`: new-iter-concepts.html#random-access-traversal-iterators-lib-random-access-traversal-iterators - diff --git a/doc/make_counting_iterator.rst b/doc/make_counting_iterator.rst deleted file mode 100755 index f1c9ae9..0000000 --- a/doc/make_counting_iterator.rst +++ /dev/null @@ -1,9 +0,0 @@ - -:: - - template - counting_iterator make_counting_iterator(Incrementable x); - -:Returns: An instance of ``counting_iterator`` - with ``current`` constructed from ``x``. - diff --git a/doc/make_filter_iterator.rst b/doc/make_filter_iterator.rst deleted file mode 100755 index e4cd877..0000000 --- a/doc/make_filter_iterator.rst +++ /dev/null @@ -1,16 +0,0 @@ - -:: - - template - filter_iterator - make_filter_iterator(Predicate f, Iterator x, Iterator end = Iterator()); - -:Returns: filter_iterator(f, x, end) - -:: - - template - filter_iterator - make_filter_iterator(Iterator x, Iterator end = Iterator()); - -:Returns: filter_iterator(x, end) diff --git a/doc/make_reverse_iterator.rst b/doc/make_reverse_iterator.rst deleted file mode 100644 index c3e20ed..0000000 --- a/doc/make_reverse_iterator.rst +++ /dev/null @@ -1,9 +0,0 @@ -:: - - template - reverse_iteratorn - make_reverse_iterator(BidirectionalIterator x); - -:Returns: An instance of ``reverse_iterator`` - with a ``current`` constructed from ``x``. - diff --git a/doc/make_transform_iterator.rst b/doc/make_transform_iterator.rst deleted file mode 100755 index 5d5f1b2..0000000 --- a/doc/make_transform_iterator.rst +++ /dev/null @@ -1,19 +0,0 @@ -:: - - template - transform_iterator - make_transform_iterator(Iterator it, UnaryFunction fun); - -:Returns: An instance of ``transform_iterator`` with ``m_f`` - initialized to ``f`` and ``m_iterator`` initialized to ``x``. - - - -:: - - template - transform_iterator - make_transform_iterator(Iterator it); - -:Returns: An instance of ``transform_iterator`` with ``m_f`` - default constructed and ``m_iterator`` initialized to ``x``. diff --git a/doc/new-iter-concepts.html b/doc/new-iter-concepts.html deleted file mode 100755 index c735532..0000000 --- a/doc/new-iter-concepts.html +++ /dev/null @@ -1,1008 +0,0 @@ - - - - - - -New Iterator Concepts - - - - - - - -
-

New Iterator Concepts

- --- - - - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com
Organization:Boost Consulting, Indiana University Open Systems -Lab, Zephyr Associates, Inc.
Date:2004-01-19
Number:This is a revised version of n1550=03-0133, which was -accepted for Technical Report 1 by the C++ standard -committee's library working group. This proposal is a -revision of paper n1297, n1477, and n1531.
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt -2003. All rights reserved
- - --- - - - -
Abstract:We propose a new system of iterator concepts that treat -access and positioning independently. This allows the -concepts to more closely match the requirements -of algorithms and provides better categorizations -of iterators that are used in practice.
- -
-

Motivation

-

The standard iterator categories and requirements are flawed because -they use a single hierarchy of concepts to address two orthogonal -issues: iterator traversal and value access. As a result, many -algorithms with requirements expressed in terms of the iterator -categories are too strict. Also, many real-world iterators can not be -accurately categorized. A proxy-based iterator with random-access -traversal, for example, may only legally have a category of "input -iterator", so generic algorithms are unable to take advantage of its -random-access capabilities. The current iterator concept hierarchy is -geared towards iterator traversal (hence the category names), while -requirements that address value access sneak in at various places. The -following table gives a summary of the current value access -requirements in the iterator categories.

- ---- - - - - - - - - - - - - - - - - - - -
Value Access Requirements in Existing Iterator Categories
Output Iterator*i = a
Input Iterator*i is convertible to T
Forward Iterator*i is T& (or const T& once issue 200 -is resolved)
Random Access Iteratori[n] is convertible to T (also i[n] = t -is required for mutable iterators once issue 299 -is resolved)
-

Because iterator traversal and value access are mixed together in a -single hierarchy, many useful iterators can not be appropriately -categorized. For example, vector<bool>::iterator is almost a -random access iterator, but the return type is not bool& (see -issue 96 and Herb Sutter's paper J16/99-0008 = WG21 -N1185). Therefore, the iterators of vector<bool> only meet the -requirements of input iterator and output iterator. This is so -nonintuitive that the C++ standard contradicts itself on this point. -In paragraph 23.2.4/1 it says that a vector is a sequence that -supports random access iterators.

-

Another difficult-to-categorize iterator is the transform iterator, an -adaptor which applies a unary function object to the dereferenced -value of the some underlying iterator (see transform_iterator). -For unary functions such as times, the return type of -operator* clearly needs to be the result_type of the function -object, which is typically not a reference. Because random access -iterators are required to return lvalues from operator*, if you -wrap int* with a transform iterator, you do not get a random -access iterator as might be expected, but an input iterator.

-

A third example is found in the vertex and edge iterators of the -Boost Graph Library. These iterators return vertex and edge -descriptors, which are lightweight handles created on-the-fly. They -must be returned by-value. As a result, their current standard -iterator category is input_iterator_tag, which means that, -strictly speaking, you could not use these iterators with algorithms -like min_element(). As a temporary solution, the concept -Multi-Pass Input Iterator was introduced to describe the vertex and -edge descriptors, but as the design notes for the concept suggest, a -better solution is needed.

-

In short, there are many useful iterators that do not fit into the -current standard iterator categories. As a result, the following bad -things happen:

-
    -
  • Iterators are often mis-categorized.
  • -
  • Algorithm requirements are more strict than necessary, because they -cannot separate the need for random access or bidirectional -traversal from the need for a true reference return type.
  • -
-
-
-

Impact on the Standard

-

This proposal for TR1 is a pure extension. Further, the new iterator -concepts are backward-compatible with the old iterator requirements, -and old iterators are forward-compatible with the new iterator -concepts. That is to say, iterators that satisfy the old requirements -also satisfy appropriate concepts in the new system, and iterators -modeling the new concepts will automatically satisfy the appropriate -old requirements.

- - -
-

Possible (but not proposed) Changes to the Working Paper

-

The extensions in this paper suggest several changes we might make -to the working paper for the next standard. These changes are not -a formal part of this proposal for TR1.

-
-

Changes to Algorithm Requirements

-

The algorithms in the standard library could benefit from the new -iterator concepts because the new concepts provide a more accurate way -to express their type requirements. The result is algorithms that are -usable in more situations and have fewer type requirements.

-

For the next working paper (but not for TR1), the committee should -consider the following changes to the type requirements of -algorithms. These changes are phrased as phrased as textual -substitutions, listing the algorithms to which each textual -substitution applies.

-

Forward Iterator -> Forward Traversal Iterator and Readable Iterator

-
-find_end, adjacent_find, search, search_n, rotate_copy, -lower_bound, upper_bound, equal_range, binary_search, -min_element, max_element
-

Forward Iterator (1) -> Single Pass Iterator and Readable Iterator, -Forward Iterator (2) -> Forward Traversal Iterator and Readable Iterator

-
-find_first_of
-

Forward Iterator -> Readable Iterator and Writable Iterator

-
-iter_swap
-

Forward Iterator -> Single Pass Iterator and Writable Iterator

-
-fill, generate
-

Forward Iterator -> Forward Traversal Iterator and Swappable Iterator

-
-rotate
-

Forward Iterator (1) -> Swappable Iterator and Single Pass Iterator, -Forward Iterator (2) -> Swappable Iterator and Incrementable Iterator

-
-swap_ranges
-
-
Forward Iterator -> Forward Traversal Iterator and Readable Iterator and Writable Iterator
-
remove, remove_if, unique
-
-

Forward Iterator -> Single Pass Iterator and Readable Iterator and Writable Iterator

-
-replace, replace_if
-
-
Bidirectional Iterator -> Bidirectional Traversal Iterator and Swappable Iterator
-
reverse
-
Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable and Swappable Iterator
-
partition
-
-

Bidirectional Iterator (1) -> Bidirectional Traversal Iterator and Readable Iterator, -Bidirectional Iterator (2) -> Bidirectional Traversal Iterator and Writable Iterator

-
-copy_backwards
-
-
Bidirectional Iterator -> Bidirectional Traversal Iterator and Swappable Iterator and Readable Iterator
-
next_permutation, prev_permutation
-
Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable Iterator and Writable Iterator
-
stable_partition, inplace_merge
-
Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable Iterator
-
reverse_copy
-
Random Access Iterator -> Random Access Traversal Iterator and Readable and Writable Iterator
-
random_shuffle, sort, stable_sort, partial_sort, nth_element, push_heap, pop_heap -make_heap, sort_heap
-
Input Iterator (2) -> Incrementable Iterator and Readable Iterator
-
equal, mismatch
-
Input Iterator (2) -> Incrementable Iterator and Readable Iterator
-
transform
-
-
-
-

Deprecations

-

For the next working paper (but not for TR1), the committee should -consider deprecating the old iterator tags, and -std::iterator_traits, since it will be superceded by individual -traits metafunctions.

-
-
-

vector<bool>

-

For the next working paper (but not for TR1), the committee should -consider reclassifying vector<bool>::iterator as a Random -Access Traversal Iterator and Readable Iterator and Writable -Iterator.

-
-
-
-
-

Design

-

The iterator requirements are to be separated into two groups. One set -of concepts handles the syntax and semantics of value access:

-
    -
  • Readable Iterator
  • -
  • Writable Iterator
  • -
  • Swappable Iterator
  • -
  • Lvalue Iterator
  • -
-

The access concepts describe requirements related to operator* and -operator->, including the value_type, reference, and -pointer associated types.

-

The other set of concepts handles traversal:

-
    -
  • Incrementable Iterator
  • -
  • Single Pass Iterator
  • -
  • Forward Traversal Iterator
  • -
  • Bidirectional Traversal Iterator
  • -
  • Random Access Traversal Iterator
  • -
-

The refinement relationships for the traversal concepts are in the -following diagram.

-

traversal.png

-

In addition to the iterator movement operators, such as -operator++, the traversal concepts also include requirements on -position comparison such as operator== and operator<. The -reason for the fine grain slicing of the concepts into the -Incrementable and Single Pass is to provide concepts that are exact -matches with the original input and output iterator requirements.

-

This proposal also includes a concept for specifying when an iterator -is interoperable with another iterator, in the sense that int* is -interoperable with int const*.

-
    -
  • Interoperable Iterators
  • -
-

The relationship between the new iterator concepts and the old are -given in the following diagram.

-

oldeqnew.png

-

Like the old iterator requirements, we provide tags for purposes of -dispatching based on the traversal concepts. The tags are related via -inheritance so that a tag is convertible to another tag if the concept -associated with the first tag is a refinement of the second tag.

-

Our design reuses iterator_traits<Iter>::iterator_category to -indicate an iterator's traversal capability. To specify -capabilities not captured by any old-style iterator category, an -iterator designer can use an iterator_category type that is -convertible to both the the most-derived old iterator category tag -which fits, and the appropriate new iterator traversal tag.

- -

We do not provide tags for the purposes of dispatching based on the -access concepts, in part because we could not find a way to -automatically infer the right access tags for old-style iterators. -An iterator's writability may be dependent on the assignability of -its value_type and there's no known way to detect whether an -arbitrary type is assignable. Fortunately, the need for -dispatching based on access capability is not as great as the need -for dispatching based on traversal capability.

-

A difficult design decision concerned the operator[]. The direct -approach for specifying operator[] would have a return type of -reference; the same as operator*. However, going in this -direction would mean that an iterator satisfying the old Random Access -Iterator requirements would not necessarily be a model of Readable or -Writable Lvalue Iterator. Instead we have chosen a design that -matches the preferred resolution of issue 299: operator[] is -only required to return something convertible to the value_type -(for a Readable Iterator), and is required to support assignment -i[n] = t (for a Writable Iterator).

-
-
-

Proposed Text

-
-

Addition to [lib.iterator.requirements]

-
-

Iterator Value Access Concepts [lib.iterator.value.access]

-

In the tables below, X is an iterator type, a is a constant -object of type X, R is -std::iterator_traits<X>::reference, T is -std::iterator_traits<X>::value_type, and v is a constant -object of type T.

-
-

Readable Iterators [lib.readable.iterators]

-

A class or built-in type X models the Readable Iterator concept -for value type T if, in addition to X being Assignable and -Copy Constructible, the following expressions are valid and respect -the stated semantics. U is the type of any specified member of -type T.

- ----- - - - - - - - - - - - - - - - - - - - - - - -
Readable Iterator Requirements (in addition to Assignable and Copy Constructible)
ExpressionReturn TypeNote/Precondition
iterator_traits<X>::value_typeTAny non-reference, -non-cv-qualified type
*aConvertible to T
-
pre: a is dereferenceable. If a == b then *a
-
is equivalent to *b.
-
-
a->mU&pre: pre: (*a).m is well-defined. Equivalent to (*a).m.
- -
-
-

Writable Iterators [lib.writable.iterators]

-

A class or built-in type X models the Writable Iterator concept -if, in addition to X being Copy Constructible, the following -expressions are valid and respect the stated semantics. Writable -Iterators have an associated set of value types.

- ----- - - - - - - - - - - - - - - -
Writable Iterator Requirements (in addition to Copy Constructible)
ExpressionReturn TypePrecondition
*a = o pre: The type of o -is in the set of -value types of X
-
-
-

Swappable Iterators [lib.swappable.iterators]

-

A class or built-in type X models the Swappable Iterator concept -if, in addition to X being Copy Constructible, the following -expressions are valid and respect the stated semantics.

- ----- - - - - - - - - - - - - - - -
Swappable Iterator Requirements (in addition to Copy Constructible)
ExpressionReturn TypePostcondition
iter_swap(a, b)voidthe pointed to values are -exchanged
-
-
[Note: An iterator that is a model of the Readable and Writable Iterator concepts
-
is also a model of Swappable Iterator. --end note]
-
-
-
-

Lvalue Iterators [lib.lvalue.iterators]

-

The Lvalue Iterator concept adds the requirement that the return -type of operator* type be a reference to the value type of the -iterator.

- ----- - - - - - - - - - - - - - - -
Lvalue Iterator Requirements
ExpressionReturn TypeNote/Assertion
*aT&T is cv -iterator_traits<X>::value_type -where cv is an optional -cv-qualification. -pre: a is -dereferenceable. If a -== b then *a is -equivalent to *b.
-
-
-
-

Iterator Traversal Concepts [lib.iterator.traversal]

-

In the tables below, X is an iterator type, a and b are -constant objects of type X, r and s are mutable objects of -type X, T is std::iterator_traits<X>::value_type, and -v is a constant object of type T.

-
-

Incrementable Iterators [lib.incrementable.iterators]

-

A class or built-in type X models the Incrementable Iterator -concept if, in addition to X being Assignable and Copy -Constructible, the following expressions are valid and respect the -stated semantics.

- ----- - - - - - - - - - - - - - - - - - - - - - - -
Incrementable Iterator Requirements (in addition to Assignable, Copy Constructible)
ExpressionReturn TypeAssertion/Semantics
++rX&&r == &++r
r++X
-{
-   X tmp = r;
-   ++r;
-   return tmp;
-}
-
-
iterator_traversal<X>::typeConvertible to -incrementable_traversal_tag 
- -
-
-

Single Pass Iterators [lib.single.pass.iterators]

-

A class or built-in type X models the Single Pass Iterator -concept if the following expressions are valid and respect the stated -semantics.

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Single Pass Iterator Requirements (in addition to Incrementable Iterator and Equality -Comparable)
ExpressionReturn TypeAssertion/Semantics / -Pre-/Post-condition
++rX&pre: r is -dereferenceable; post: -r is dereferenceable or -r is past-the-end
a == bconvertible to bool== is an equivalence -relation over its domain
a != bconvertible to bool!(a == b)
iterator_traversal<X>::typeConvertible to -single_pass_traversal_tag 
- -
-
-

Forward Traversal Iterators [lib.forward.traversal.iterators]

-

A class or built-in type X models the Forward Traversal Iterator -concept if, in addition to X meeting the requirements of Default -Constructible and Single Pass Iterator, the following expressions are -valid and respect the stated semantics.

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Forward Traversal Iterator Requirements (in addition to Default Constructible and Single Pass Iterator)
ExpressionReturn TypeAssertion/Note
X u;X&note: u may have a -singular value.
++rX&r == s and r is -dereferenceable implies -++r == ++s.
iterator_traits<X>::difference_typeA signed integral type representing -the distance between iterators 
iterator_traversal<X>::typeConvertible to -forward_traversal_tag 
- -
-
-

Bidirectional Traversal Iterators [lib.bidirectional.traversal.iterators]

-

A class or built-in type X models the Bidirectional Traversal -Iterator concept if, in addition to X meeting the requirements of -Forward Traversal Iterator, the following expressions are valid and -respect the stated semantics.

- ----- - - - - - - - - - - - - - - - - - - - - - - -
Bidirectional Traversal Iterator Requirements (in addition to Forward Traversal -Iterator)
ExpressionReturn TypeAssertion/Semantics / -Pre-/Post-condition
--rX&pre: there exists -s such that r -== ++s. post: -s is -dereferenceable. ---(++r) == r. ---r == --s -implies r == -s. &r == &--r.
r--convertible to const X&
-{
-  X tmp = r;
-  --r;
-  return tmp;
-}
-
-
iterator_traversal<X>::typeConvertible to -bidirectional_traversal_tag 
- -
-
-

Random Access Traversal Iterators [lib.random.access.traversal.iterators]

-

A class or built-in type X models the Random Access Traversal -Iterator concept if the following expressions are valid and respect -the stated semantics. In the table below, Distance is -iterator_traits<X>::difference_type and n represents a -constant object of type Distance.

- ------ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Random Access Traversal Iterator Requirements (in addition to Bidirectional Traversal Iterator)
ExpressionReturn TypeOperational SemanticsAssertion/ -Precondition
r += nX&
-{
-  Distance m = n;
-  if (m >= 0)
-    while (m--)
-      ++r;
-  else
-    while (m++)
-      --r;
-  return r;
-}
-
-
 
a + n, n + aX{ X tmp = a; return tmp -+= n; } 
r -= nX&return r += -n 
a - nX{ X tmp = a; return tmp --= n; } 
b - aDistancea < b ?  distance(a,b) -: -distance(b,a)pre: there exists a -value n of -Distance such that -a + n == b. b -== a + (b - a).
a[n]convertible to T*(a + n)pre: a is a readable -iterator
a[n] = vconvertible to T*(a + n) = vpre: a is a writable -iterator
a < bconvertible to boolb - a > 0< is a total -ordering relation
a > bconvertible to boolb < a> is a total -ordering relation
a >= bconvertible to bool!(a < b) 
a <= bconvertible to bool!(a > b) 
iterator_traversal<X>::typeConvertible to -random_access_traversal_tag  
- -
-
-

Interoperable Iterators [lib.interoperable.iterators]

-

A class or built-in type X that models Single Pass Iterator is -interoperable with a class or built-in type Y that also models -Single Pass Iterator if the following expressions are valid and -respect the stated semantics. In the tables below, x is an object -of type X, y is an object of type Y, Distance is -iterator_traits<Y>::difference_type, and n represents a -constant object of type Distance.

- ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionReturn TypeAssertion/Precondition/Postcondition
y = xYpost: y == x
Y(x)Ypost: Y(x) == x
x == yconvertible to bool== is an equivalence relation over its domain.
y == xconvertible to bool== is an equivalence relation over its domain.
x != yconvertible to boolbool(a==b) != bool(a!=b) over its domain.
y != xconvertible to boolbool(a==b) != bool(a!=b) over its domain.
-

If X and Y both model Random Access Traversal Iterator then -the following additional requirements must be met.

- ------ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ExpressionReturn TypeOperational SemanticsAssertion/ Precondition
x < yconvertible to booly - x > 0< is a total ordering relation
y < xconvertible to boolx - y > 0< is a total ordering relation
x > yconvertible to booly < x> is a total ordering relation
y > xconvertible to boolx < y> is a total ordering relation
x >= yconvertible to bool!(x < y) 
y >= xconvertible to bool!(y < x) 
x <= yconvertible to bool!(x > y) 
y <= xconvertible to bool!(y > x) 
y - xDistancedistance(Y(x),y)pre: there exists a value n of -Distance such that x + n == y. -y == x + (y - x).
x - yDistancedistance(y,Y(x))pre: there exists a value n of -Distance such that y + n == x. -x == y + (x - y).
-
-
-
-
-

Addition to [lib.iterator.synopsis]

-
-// lib.iterator.traits, traits and tags
-template <class Iterator> struct is_readable_iterator;
-template <class Iterator> struct iterator_traversal;
-
-struct incrementable_traversal_tag { };
-struct single_pass_traversal_tag : incrementable_traversal_tag { };
-struct forward_traversal_tag : single_pass_traversal_tag { };
-struct bidirectional_traversal_tag : forward_traversal_tag { };
-struct random_access_traversal_tag : bidirectional_traversal_tag { };
-
-
-
-

Addition to [lib.iterator.traits]

-

The is_readable_iterator class -template satisfies the UnaryTypeTrait requirements.

-

Given an iterator type X, is_readable_iterator<X>::value -yields true if, for an object a of type X, *a is -convertible to iterator_traits<X>::value_type, and false -otherwise.

-

iterator_traversal<X>::type is

-
-category-to-traversal(iterator_traits<X>::iterator_category) 
-
-

where category-to-traversal is defined as follows

-
-category-to-traversal(C) =
-    if (C is convertible to incrementable_traversal_tag)
-        return C;
-    else if (C is convertible to random_access_iterator_tag)
-        return random_access_traversal_tag;
-    else if (C is convertible to bidirectional_iterator_tag)
-        return bidirectional_traversal_tag;
-    else if (C is convertible to forward_iterator_tag)
-        return forward_traversal_tag;
-    else if (C is convertible to input_iterator_tag)
-        return single_pass_traversal_tag;
-    else if (C is convertible to output_iterator_tag)
-        return incrementable_traversal_tag;
-    else
-        the program is ill-formed
-
-
-
-
-

Footnotes

-

The UnaryTypeTrait concept is defined in n1519; the LWG is -considering adding the requirement that specializations are derived -from their nested ::type.

- -
-
- - - - diff --git a/doc/new-iter-concepts.rst b/doc/new-iter-concepts.rst deleted file mode 100644 index c442ed0..0000000 --- a/doc/new-iter-concepts.rst +++ /dev/null @@ -1,794 +0,0 @@ -++++++++++++++++++++++ - New Iterator Concepts -++++++++++++++++++++++ - -.. Version 1.25 of this ReStructuredText document is the same as - n1550_, the paper accepted by the LWG. - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, `Zephyr Associates, Inc.`_ -:date: $Date$ - -:Number: This is a revised version of n1550_\ =03-0133, which was - accepted for Technical Report 1 by the C++ standard - committee's library working group. This proposal is a - revision of paper n1297_, n1477_, and n1531_. - -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt - 2003. All rights reserved - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Zephyr Associates, Inc.`: http://www.styleadvisor.com - -.. _`Institute for Transport Railway Operation and Construction`: - http://www.ive.uni-hannover.de - -:Abstract: We propose a new system of iterator concepts that treat - access and positioning independently. This allows the - concepts to more closely match the requirements - of algorithms and provides better categorizations - of iterators that are used in practice. - -.. contents:: Table of Contents - -.. _n1297: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2001/n1297.html -.. _n1477: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1477.html -.. _n1531: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1531.html -.. _n1550: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1550.html - -============ - Motivation -============ - -The standard iterator categories and requirements are flawed because -they use a single hierarchy of concepts to address two orthogonal -issues: *iterator traversal* and *value access*. As a result, many -algorithms with requirements expressed in terms of the iterator -categories are too strict. Also, many real-world iterators can not be -accurately categorized. A proxy-based iterator with random-access -traversal, for example, may only legally have a category of "input -iterator", so generic algorithms are unable to take advantage of its -random-access capabilities. The current iterator concept hierarchy is -geared towards iterator traversal (hence the category names), while -requirements that address value access sneak in at various places. The -following table gives a summary of the current value access -requirements in the iterator categories. - -+------------------------------------------------------------------------------+ -|Value Access Requirements in Existing Iterator Categories | -+========================+=====================================================+ -|Output Iterator |``*i = a`` | -+------------------------+-----------------------------------------------------+ -|Input Iterator |``*i`` is convertible to ``T`` | -+------------------------+-----------------------------------------------------+ -|Forward Iterator |``*i`` is ``T&`` (or ``const T&`` once `issue 200`_ | -| |is resolved) | -+------------------------+-----------------------------------------------------+ -|Random Access Iterator |``i[n]`` is convertible to ``T`` (also ``i[n] = t`` | -| |is required for mutable iterators once `issue 299`_ | -| |is resolved) | -+------------------------+-----------------------------------------------------+ - -.. _issue 200: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/lwg-active.html#200 -.. _issue 299: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/lwg-active.html#299 - - -Because iterator traversal and value access are mixed together in a -single hierarchy, many useful iterators can not be appropriately -categorized. For example, ``vector::iterator`` is almost a -random access iterator, but the return type is not ``bool&`` (see -`issue 96`_ and Herb Sutter's paper J16/99-0008 = WG21 -N1185). Therefore, the iterators of ``vector`` only meet the -requirements of input iterator and output iterator. This is so -nonintuitive that the C++ standard contradicts itself on this point. -In paragraph 23.2.4/1 it says that a ``vector`` is a sequence that -supports random access iterators. - -.. _issue 96: http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/lwg-active.html#96 - -Another difficult-to-categorize iterator is the transform iterator, an -adaptor which applies a unary function object to the dereferenced -value of the some underlying iterator (see `transform_iterator`_). -For unary functions such as ``times``, the return type of -``operator*`` clearly needs to be the ``result_type`` of the function -object, which is typically not a reference. Because random access -iterators are required to return lvalues from ``operator*``, if you -wrap ``int*`` with a transform iterator, you do not get a random -access iterator as might be expected, but an input iterator. - -.. _`transform_iterator`: http://www.boost.org/libs/utility/transform_iterator.htm - -A third example is found in the vertex and edge iterators of the -`Boost Graph Library`_. These iterators return vertex and edge -descriptors, which are lightweight handles created on-the-fly. They -must be returned by-value. As a result, their current standard -iterator category is ``input_iterator_tag``, which means that, -strictly speaking, you could not use these iterators with algorithms -like ``min_element()``. As a temporary solution, the concept -`Multi-Pass Input Iterator`_ was introduced to describe the vertex and -edge descriptors, but as the design notes for the concept suggest, a -better solution is needed. - -.. _Boost Graph Library: http://www.boost.org/libs/graph/doc/table_of_contents.html -.. _Multi-Pass Input Iterator: http://www.boost.org/libs/utility/MultiPassInputIterator.html - -In short, there are many useful iterators that do not fit into the -current standard iterator categories. As a result, the following bad -things happen: - -- Iterators are often mis-categorized. - -- Algorithm requirements are more strict than necessary, because they - cannot separate the need for random access or bidirectional - traversal from the need for a true reference return type. - - -======================== - Impact on the Standard -======================== - -This proposal for TR1 is a pure extension. Further, the new iterator -concepts are backward-compatible with the old iterator requirements, -and old iterators are forward-compatible with the new iterator -concepts. That is to say, iterators that satisfy the old requirements -also satisfy appropriate concepts in the new system, and iterators -modeling the new concepts will automatically satisfy the appropriate -old requirements. - -.. I think we need to say something about the resolution to allow - convertibility to any of the old-style tags as a TR issue (hope it - made it). -DWA - -.. Hmm, not sure I understand. Are you talking about whether a - standards conforming input iterator is allowed to have - a tag that is not input_iterator_tag but that - is convertible to input_iterator_tag? -JGS - -Possible (but not proposed) Changes to the Working Paper -======================================================== - -The extensions in this paper suggest several changes we might make -to the working paper for the next standard. These changes are not -a formal part of this proposal for TR1. - -Changes to Algorithm Requirements -+++++++++++++++++++++++++++++++++ - -The algorithms in the standard library could benefit from the new -iterator concepts because the new concepts provide a more accurate way -to express their type requirements. The result is algorithms that are -usable in more situations and have fewer type requirements. - -For the next working paper (but not for TR1), the committee should -consider the following changes to the type requirements of -algorithms. These changes are phrased as phrased as textual -substitutions, listing the algorithms to which each textual -substitution applies. - -Forward Iterator -> Forward Traversal Iterator and Readable Iterator - - ``find_end, adjacent_find, search, search_n, rotate_copy, - lower_bound, upper_bound, equal_range, binary_search, - min_element, max_element`` - -Forward Iterator (1) -> Single Pass Iterator and Readable Iterator, -Forward Iterator (2) -> Forward Traversal Iterator and Readable Iterator - - ``find_first_of`` - -Forward Iterator -> Readable Iterator and Writable Iterator - - ``iter_swap`` - -Forward Iterator -> Single Pass Iterator and Writable Iterator - - ``fill, generate`` - -Forward Iterator -> Forward Traversal Iterator and Swappable Iterator - - ``rotate`` - -Forward Iterator (1) -> Swappable Iterator and Single Pass Iterator, -Forward Iterator (2) -> Swappable Iterator and Incrementable Iterator - - ``swap_ranges`` - -Forward Iterator -> Forward Traversal Iterator and Readable Iterator and Writable Iterator - ``remove, remove_if, unique`` - -Forward Iterator -> Single Pass Iterator and Readable Iterator and Writable Iterator - - ``replace, replace_if`` - -Bidirectional Iterator -> Bidirectional Traversal Iterator and Swappable Iterator - ``reverse`` - -Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable and Swappable Iterator - ``partition`` - -Bidirectional Iterator (1) -> Bidirectional Traversal Iterator and Readable Iterator, -Bidirectional Iterator (2) -> Bidirectional Traversal Iterator and Writable Iterator - - ``copy_backwards`` - -Bidirectional Iterator -> Bidirectional Traversal Iterator and Swappable Iterator and Readable Iterator - ``next_permutation, prev_permutation`` - -Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable Iterator and Writable Iterator - ``stable_partition, inplace_merge`` - -Bidirectional Iterator -> Bidirectional Traversal Iterator and Readable Iterator - ``reverse_copy`` - -Random Access Iterator -> Random Access Traversal Iterator and Readable and Writable Iterator - ``random_shuffle, sort, stable_sort, partial_sort, nth_element, push_heap, pop_heap - make_heap, sort_heap`` - -Input Iterator (2) -> Incrementable Iterator and Readable Iterator - ``equal, mismatch`` - -Input Iterator (2) -> Incrementable Iterator and Readable Iterator - ``transform`` - -Deprecations -++++++++++++ - -For the next working paper (but not for TR1), the committee should -consider deprecating the old iterator tags, and -std::iterator_traits, since it will be superceded by individual -traits metafunctions. - -``vector`` -++++++++++++++++ - -For the next working paper (but not for TR1), the committee should -consider reclassifying ``vector::iterator`` as a Random -Access Traversal Iterator and Readable Iterator and Writable -Iterator. - -======== - Design -======== - -The iterator requirements are to be separated into two groups. One set -of concepts handles the syntax and semantics of value access: - -- Readable Iterator -- Writable Iterator -- Swappable Iterator -- Lvalue Iterator - -The access concepts describe requirements related to ``operator*`` and -``operator->``, including the ``value_type``, ``reference``, and -``pointer`` associated types. - -The other set of concepts handles traversal: - -- Incrementable Iterator -- Single Pass Iterator -- Forward Traversal Iterator -- Bidirectional Traversal Iterator -- Random Access Traversal Iterator - -The refinement relationships for the traversal concepts are in the -following diagram. - -.. image:: traversal.png - -In addition to the iterator movement operators, such as -``operator++``, the traversal concepts also include requirements on -position comparison such as ``operator==`` and ``operator<``. The -reason for the fine grain slicing of the concepts into the -Incrementable and Single Pass is to provide concepts that are exact -matches with the original input and output iterator requirements. - -This proposal also includes a concept for specifying when an iterator -is interoperable with another iterator, in the sense that ``int*`` is -interoperable with ``int const*``. - -- Interoperable Iterators - - -The relationship between the new iterator concepts and the old are -given in the following diagram. - -.. image:: oldeqnew.png - -Like the old iterator requirements, we provide tags for purposes of -dispatching based on the traversal concepts. The tags are related via -inheritance so that a tag is convertible to another tag if the concept -associated with the first tag is a refinement of the second tag. - -Our design reuses ``iterator_traits::iterator_category`` to -indicate an iterator's traversal capability. To specify -capabilities not captured by any old-style iterator category, an -iterator designer can use an ``iterator_category`` type that is -convertible to both the the most-derived old iterator category tag -which fits, and the appropriate new iterator traversal tag. - -.. dwa2003/1/2: Note that we are not *requiring* convertibility to - a new-style traversal tag in order to meet new concepts. - Old-style iterators still fit, after all. - -We do not provide tags for the purposes of dispatching based on the -access concepts, in part because we could not find a way to -automatically infer the right access tags for old-style iterators. -An iterator's writability may be dependent on the assignability of -its ``value_type`` and there's no known way to detect whether an -arbitrary type is assignable. Fortunately, the need for -dispatching based on access capability is not as great as the need -for dispatching based on traversal capability. - -A difficult design decision concerned the ``operator[]``. The direct -approach for specifying ``operator[]`` would have a return type of -``reference``; the same as ``operator*``. However, going in this -direction would mean that an iterator satisfying the old Random Access -Iterator requirements would not necessarily be a model of Readable or -Writable Lvalue Iterator. Instead we have chosen a design that -matches the preferred resolution of `issue 299`_: ``operator[]`` is -only required to return something convertible to the ``value_type`` -(for a Readable Iterator), and is required to support assignment -``i[n] = t`` (for a Writable Iterator). - - -=============== - Proposed Text -=============== - -Addition to [lib.iterator.requirements] -======================================= - -Iterator Value Access Concepts [lib.iterator.value.access] -++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -In the tables below, ``X`` is an iterator type, ``a`` is a constant -object of type ``X``, ``R`` is -``std::iterator_traits::reference``, ``T`` is -``std::iterator_traits::value_type``, and ``v`` is a constant -object of type ``T``. - -.. _Readable Iterator: - -Readable Iterators [lib.readable.iterators] -------------------------------------------- - -A class or built-in type ``X`` models the *Readable Iterator* concept -for value type ``T`` if, in addition to ``X`` being Assignable and -Copy Constructible, the following expressions are valid and respect -the stated semantics. ``U`` is the type of any specified member of -type ``T``. - -+-----------------------------------------------------------------------------------------------------------------------------+ -|Readable Iterator Requirements (in addition to Assignable and Copy Constructible) | -+-----------------------------------+------------------------+----------------------------------------------------------------+ -|Expression |Return Type |Note/Precondition | -+===================================+========================+================================================================+ -|``iterator_traits::value_type`` |``T`` |Any non-reference, | -| | |non-cv-qualified type | -+-----------------------------------+------------------------+----------------------------------------------------------------+ -|``*a`` | Convertible to ``T`` |pre: ``a`` is dereferenceable. If ``a == b`` then ``*a`` | -| | | is equivalent to ``*b``. | -+-----------------------------------+------------------------+----------------------------------------------------------------+ -|``a->m`` |``U&`` |pre: ``pre: (*a).m`` is well-defined. Equivalent to ``(*a).m``. | -+-----------------------------------+------------------------+----------------------------------------------------------------+ - -.. We won't say anything about iterator_traits::reference until the DR is resolved. -JGS - -.. _Writable Iterator: - -Writable Iterators [lib.writable.iterators] -------------------------------------------- - -A class or built-in type ``X`` models the *Writable Iterator* concept -if, in addition to ``X`` being Copy Constructible, the following -expressions are valid and respect the stated semantics. Writable -Iterators have an associated *set of value types*. - -+---------------------------------------------------------------------+ -|Writable Iterator Requirements (in addition to Copy Constructible) | -+-------------------------+--------------+----------------------------+ -|Expression |Return Type |Precondition | -+=========================+==============+============================+ -|``*a = o`` | | pre: The type of ``o`` | -| | | is in the set of | -| | | value types of ``X`` | -+-------------------------+--------------+----------------------------+ - -Swappable Iterators [lib.swappable.iterators] ---------------------------------------------- - -A class or built-in type ``X`` models the *Swappable Iterator* concept -if, in addition to ``X`` being Copy Constructible, the following -expressions are valid and respect the stated semantics. - -+---------------------------------------------------------------------+ -|Swappable Iterator Requirements (in addition to Copy Constructible) | -+-------------------------+-------------+-----------------------------+ -|Expression |Return Type |Postcondition | -+=========================+=============+=============================+ -|``iter_swap(a, b)`` |``void`` |the pointed to values are | -| | |exchanged | -+-------------------------+-------------+-----------------------------+ - -[*Note:* An iterator that is a model of the *Readable* and *Writable Iterator* concepts - is also a model of *Swappable Iterator*. *--end note*] - - -Lvalue Iterators [lib.lvalue.iterators] ---------------------------------------- - -The *Lvalue Iterator* concept adds the requirement that the return -type of ``operator*`` type be a reference to the value type of the -iterator. - -+-------------------------------------------------------------+ -| Lvalue Iterator Requirements | -+-------------+-----------+-----------------------------------+ -|Expression |Return Type|Note/Assertion | -+=============+===========+===================================+ -|``*a`` | ``T&`` |``T`` is *cv* | -| | |``iterator_traits::value_type`` | -| | |where *cv* is an optional | -| | |cv-qualification. | -| | |pre: ``a`` is | -| | |dereferenceable. If ``a | -| | |== b`` then ``*a`` is | -| | |equivalent to ``*b``. | -+-------------+-----------+-----------------------------------+ - - - -Iterator Traversal Concepts [lib.iterator.traversal] -++++++++++++++++++++++++++++++++++++++++++++++++++++ - -In the tables below, ``X`` is an iterator type, ``a`` and ``b`` are -constant objects of type ``X``, ``r`` and ``s`` are mutable objects of -type ``X``, ``T`` is ``std::iterator_traits::value_type``, and -``v`` is a constant object of type ``T``. - - -Incrementable Iterators [lib.incrementable.iterators] ------------------------------------------------------ - -A class or built-in type ``X`` models the *Incrementable Iterator* -concept if, in addition to ``X`` being Assignable and Copy -Constructible, the following expressions are valid and respect the -stated semantics. - - -+-------------------------------------------------------------------------------------+ -|Incrementable Iterator Requirements (in addition to Assignable, Copy Constructible) | -| | -+--------------------------------+-------------------------------+--------------------+ -|Expression |Return Type |Assertion/Semantics | -+================================+===============================+====================+ -|``++r`` |``X&`` |``&r == &++r`` | -+--------------------------------+-------------------------------+--------------------+ -|``r++`` |``X`` |:: | -| | | | -| | | { | -| | | X tmp = r; | -| | | ++r; | -| | | return tmp; | -| | | } | -+--------------------------------+-------------------------------+--------------------+ -|``iterator_traversal::type`` |Convertible to | | -| |``incrementable_traversal_tag``| | -+--------------------------------+-------------------------------+--------------------+ - -.. TR1: incrementable_iterator_tag changed to - incrementable_traversal_tag for consistency. - -Single Pass Iterators [lib.single.pass.iterators] -------------------------------------------------- - -A class or built-in type ``X`` models the *Single Pass Iterator* -concept if the following expressions are valid and respect the stated -semantics. - - -+------------------------------------------------------------------------------------------+ -|Single Pass Iterator Requirements (in addition to Incrementable Iterator and Equality | -|Comparable) | -+--------------------------------+-----------------------------+---------------------------+ -|Expression |Return Type |Assertion/Semantics / | -| | |Pre-/Post-condition | -+================================+=============================+===========================+ -|``++r`` |``X&`` |pre: ``r`` is | -| | |dereferenceable; post: | -| | |``r`` is dereferenceable or| -| | |``r`` is past-the-end | -+--------------------------------+-----------------------------+---------------------------+ -|``a == b`` |convertible to ``bool`` |``==`` is an equivalence | -| | |relation over its domain | -+--------------------------------+-----------------------------+---------------------------+ -|``a != b`` |convertible to ``bool`` |``!(a == b)`` | -+--------------------------------+-----------------------------+---------------------------+ -|``iterator_traversal::type`` |Convertible to | | -| |``single_pass_traversal_tag``| | -+--------------------------------+-----------------------------+---------------------------+ - -.. TR1: single_pass_iterator_tag changed to - single_pass_traversal_tag for consistency - - -Forward Traversal Iterators [lib.forward.traversal.iterators] -------------------------------------------------------------- - -A class or built-in type ``X`` models the *Forward Traversal Iterator* -concept if, in addition to ``X`` meeting the requirements of Default -Constructible and Single Pass Iterator, the following expressions are -valid and respect the stated semantics. - -+--------------------------------------------------------------------------------------------------------+ -|Forward Traversal Iterator Requirements (in addition to Default Constructible and Single Pass Iterator) | -+---------------------------------------+-----------------------------------+----------------------------+ -|Expression |Return Type |Assertion/Note | -+=======================================+===================================+============================+ -|``X u;`` |``X&`` |note: ``u`` may have a | -| | |singular value. | -+---------------------------------------+-----------------------------------+----------------------------+ -|``++r`` |``X&`` |``r == s`` and ``r`` is | -| | |dereferenceable implies | -| | |``++r == ++s.`` | -+---------------------------------------+-----------------------------------+----------------------------+ -|``iterator_traits::difference_type``|A signed integral type representing| | -| |the distance between iterators | | -| | | | -+---------------------------------------+-----------------------------------+----------------------------+ -|``iterator_traversal::type`` |Convertible to | | -| |``forward_traversal_tag`` | | -+---------------------------------------+-----------------------------------+----------------------------+ - -.. TR1: forward_traversal_iterator_tag changed to - forward_traversal_tag for consistency - - -Bidirectional Traversal Iterators [lib.bidirectional.traversal.iterators] -------------------------------------------------------------------------- - -A class or built-in type ``X`` models the *Bidirectional Traversal -Iterator* concept if, in addition to ``X`` meeting the requirements of -Forward Traversal Iterator, the following expressions are valid and -respect the stated semantics. - -+--------------------------------------------------------------------------------------+ -|Bidirectional Traversal Iterator Requirements (in addition to Forward Traversal | -|Iterator) | -+--------------------------------+-------------------------------+---------------------+ -|Expression |Return Type |Assertion/Semantics /| -| | |Pre-/Post-condition | -+================================+===============================+=====================+ -|``--r`` |``X&`` |pre: there exists | -| | |``s`` such that ``r | -| | |== ++s``. post: | -| | |``s`` is | -| | |dereferenceable. | -| | |``--(++r) == r``. | -| | |``--r == --s`` | -| | |implies ``r == | -| | |s``. ``&r == &--r``. | -+--------------------------------+-------------------------------+---------------------+ -|``r--`` |convertible to ``const X&`` |:: | -| | | | -| | | { | -| | | X tmp = r; | -| | | --r; | -| | | return tmp; | -| | | } | -+--------------------------------+-------------------------------+---------------------+ -|``iterator_traversal::type`` |Convertible to | | -| |``bidirectional_traversal_tag``| | -| | | | -+--------------------------------+-------------------------------+---------------------+ - -.. TR1: bidirectional_traversal_iterator_tag changed to - bidirectional_traversal_tag for consistency - -Random Access Traversal Iterators [lib.random.access.traversal.iterators] -------------------------------------------------------------------------- - -A class or built-in type ``X`` models the *Random Access Traversal -Iterator* concept if the following expressions are valid and respect -the stated semantics. In the table below, ``Distance`` is -``iterator_traits::difference_type`` and ``n`` represents a -constant object of type ``Distance``. - -+------------------------------------------------------------------------------------------------------------------+ -|Random Access Traversal Iterator Requirements (in addition to Bidirectional Traversal Iterator) | -+-------------------------------+---------------------------------+-------------------------+----------------------+ -|Expression |Return Type |Operational Semantics |Assertion/ | -| | | |Precondition | -+===============================+=================================+=========================+======================+ -|``r += n`` |``X&`` |:: | | -| | | | | -| | | { | | -| | | Distance m = n; | | -| | | if (m >= 0) | | -| | | while (m--) | | -| | | ++r; | | -| | | else | | -| | | while (m++) | | -| | | --r; | | -| | | return r; | | -| | | } | | -+-------------------------------+---------------------------------+-------------------------+----------------------+ -|``a + n``, ``n + a`` |``X`` |``{ X tmp = a; return tmp| | -| | |+= n; }`` | | -| | | | | -+-------------------------------+---------------------------------+-------------------------+----------------------+ -|``r -= n`` |``X&`` |``return r += -n`` | | -+-------------------------------+---------------------------------+-------------------------+----------------------+ -|``a - n`` |``X`` |``{ X tmp = a; return tmp| | -| | |-= n; }`` | | -| | | | | -+-------------------------------+---------------------------------+-------------------------+----------------------+ -|``b - a`` |``Distance`` |``a < b ? distance(a,b) |pre: there exists a | -| | |: -distance(b,a)`` |value ``n`` of | -| | | |``Distance`` such that| -| | | |``a + n == b``. ``b | -| | | |== a + (b - a)``. | -+-------------------------------+---------------------------------+-------------------------+----------------------+ -|``a[n]`` |convertible to T |``*(a + n)`` |pre: a is a `readable | -| | | |iterator`_ | -+-------------------------------+---------------------------------+-------------------------+----------------------+ -|``a[n] = v`` |convertible to T |``*(a + n) = v`` |pre: a is a `writable | -| | | |iterator`_ | -+-------------------------------+---------------------------------+-------------------------+----------------------+ -|``a < b`` |convertible to ``bool`` |``b - a > 0`` |``<`` is a total | -| | | |ordering relation | -+-------------------------------+---------------------------------+-------------------------+----------------------+ -|``a > b`` |convertible to ``bool`` |``b < a`` |``>`` is a total | -| | | |ordering relation | -+-------------------------------+---------------------------------+-------------------------+----------------------+ -|``a >= b`` |convertible to ``bool`` |``!(a < b)`` | | -+-------------------------------+---------------------------------+-------------------------+----------------------+ -|``a <= b`` |convertible to ``bool`` |``!(a > b)`` | | -+-------------------------------+---------------------------------+-------------------------+----------------------+ -|``iterator_traversal::type``|Convertible to | | | -| |``random_access_traversal_tag`` | | | -+-------------------------------+---------------------------------+-------------------------+----------------------+ - -.. TR1: random_access_traversal_iterator_tag changed to - random_access_traversal_tag for consistency - - -Interoperable Iterators [lib.interoperable.iterators] ------------------------------------------------------ - -A class or built-in type ``X`` that models Single Pass Iterator is -*interoperable with* a class or built-in type ``Y`` that also models -Single Pass Iterator if the following expressions are valid and -respect the stated semantics. In the tables below, ``x`` is an object -of type ``X``, ``y`` is an object of type ``Y``, ``Distance`` is -``iterator_traits::difference_type``, and ``n`` represents a -constant object of type ``Distance``. - -+-----------+-----------------------+---------------------------------------------------+ -|Expression |Return Type |Assertion/Precondition/Postcondition | -+===========+=======================+===================================================+ -|``y = x`` |``Y`` |post: ``y == x`` | -+-----------+-----------------------+---------------------------------------------------+ -|``Y(x)`` |``Y`` |post: ``Y(x) == x`` | -+-----------+-----------------------+---------------------------------------------------+ -|``x == y`` |convertible to ``bool``|``==`` is an equivalence relation over its domain. | -+-----------+-----------------------+---------------------------------------------------+ -|``y == x`` |convertible to ``bool``|``==`` is an equivalence relation over its domain. | -+-----------+-----------------------+---------------------------------------------------+ -|``x != y`` |convertible to ``bool``|``bool(a==b) != bool(a!=b)`` over its domain. | -+-----------+-----------------------+---------------------------------------------------+ -|``y != x`` |convertible to ``bool``|``bool(a==b) != bool(a!=b)`` over its domain. | -+-----------+-----------------------+---------------------------------------------------+ - -If ``X`` and ``Y`` both model Random Access Traversal Iterator then -the following additional requirements must be met. - -+-----------+-----------------------+---------------------+--------------------------------------+ -|Expression |Return Type |Operational Semantics|Assertion/ Precondition | -+===========+=======================+=====================+======================================+ -|``x < y`` |convertible to ``bool``|``y - x > 0`` |``<`` is a total ordering relation | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y < x`` |convertible to ``bool``|``x - y > 0`` |``<`` is a total ordering relation | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``x > y`` |convertible to ``bool``|``y < x`` |``>`` is a total ordering relation | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y > x`` |convertible to ``bool``|``x < y`` |``>`` is a total ordering relation | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``x >= y`` |convertible to ``bool``|``!(x < y)`` | | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y >= x`` |convertible to ``bool``|``!(y < x)`` | | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``x <= y`` |convertible to ``bool``|``!(x > y)`` | | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y <= x`` |convertible to ``bool``|``!(y > x)`` | | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``y - x`` |``Distance`` |``distance(Y(x),y)`` |pre: there exists a value ``n`` of | -| | | |``Distance`` such that ``x + n == y``.| -| | | |``y == x + (y - x)``. | -+-----------+-----------------------+---------------------+--------------------------------------+ -|``x - y`` |``Distance`` |``distance(y,Y(x))`` |pre: there exists a value ``n`` of | -| | | |``Distance`` such that ``y + n == x``.| -| | | |``x == y + (x - y)``. | -+-----------+-----------------------+---------------------+--------------------------------------+ - - - -Addition to [lib.iterator.synopsis] -=================================== - - -:: - - // lib.iterator.traits, traits and tags - template struct is_readable_iterator; - template struct iterator_traversal; - - struct incrementable_traversal_tag { }; - struct single_pass_traversal_tag : incrementable_traversal_tag { }; - struct forward_traversal_tag : single_pass_traversal_tag { }; - struct bidirectional_traversal_tag : forward_traversal_tag { }; - struct random_access_traversal_tag : bidirectional_traversal_tag { }; - -Addition to [lib.iterator.traits] -================================= - -The ``is_readable_iterator`` class -template satisfies the UnaryTypeTrait_ requirements. - -Given an iterator type ``X``, ``is_readable_iterator::value`` -yields ``true`` if, for an object ``a`` of type ``X``, ``*a`` is -convertible to ``iterator_traits::value_type``, and ``false`` -otherwise. - -``iterator_traversal::type`` is - -.. parsed-literal:: - - *category-to-traversal*\ (iterator_traits::iterator_category) - -where *category-to-traversal* is defined as follows - -.. _`category-to-traversal`: - -.. parsed-literal:: - - *category-to-traversal*\ (C) = - if (C is convertible to incrementable_traversal_tag) - return C; - else if (C is convertible to random_access_iterator_tag) - return random_access_traversal_tag; - else if (C is convertible to bidirectional_iterator_tag) - return bidirectional_traversal_tag; - else if (C is convertible to forward_iterator_tag) - return forward_traversal_tag; - else if (C is convertible to input_iterator_tag) - return single_pass_traversal_tag; - else if (C is convertible to output_iterator_tag) - return incrementable_traversal_tag; - else - *the program is ill-formed* - - -=========== - Footnotes -=========== - -.. _UnaryTypeTrait: n1519_ - -The UnaryTypeTrait concept is defined in n1519_; the LWG is -considering adding the requirement that specializations are derived -from their nested ``::type``. - -.. _n1519: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1519.htm - -.. - LocalWords: Abrahams Siek Witt const bool Sutter's WG int UL LI href Lvalue - LocalWords: ReadableIterator WritableIterator SwappableIterator cv pre iter - LocalWords: ConstantLvalueIterator MutableLvalueIterator CopyConstructible TR - LocalWords: ForwardTraversalIterator BidirectionalTraversalIterator lvalue - LocalWords: RandomAccessTraversalIterator dereferenceable Incrementable tmp - LocalWords: incrementable xxx min prev inplace png oldeqnew AccessTag struct - LocalWords: TraversalTag typename lvalues DWA Hmm JGS mis enum diff --git a/doc/oldeqnew.png b/doc/oldeqnew.png deleted file mode 100644 index 30cd159..0000000 Binary files a/doc/oldeqnew.png and /dev/null differ diff --git a/doc/permutation_iterator.html b/doc/permutation_iterator.html deleted file mode 100644 index 456940a..0000000 --- a/doc/permutation_iterator.html +++ /dev/null @@ -1,295 +0,0 @@ - - - - - - -Permutation Iterator - - - - - - - -
-

Permutation Iterator

- --- - - - - - - - - - - - -
Author:Toon Knapen, David Abrahams, Roland Richter, Jeremy Siek
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu
Organization:Boost Consulting, Indiana University Open Systems -Lab
Date:2004-01-13
Copyright:Copyright Toon Knapen, David Abrahams, Roland Richter, and Jeremy Siek 2003. All rights reserved
- --- - - - -
abstract:The permutation iterator adaptor provides a permuted view of a given -range. That is, the view includes every element of the given range but -in a potentially different order.
- -
-

Introduction

-

The adaptor takes two arguments:

-
-
    -
  • an iterator to the range V on which the permutation -will be applied
  • -
  • the reindexing scheme that defines how the -elements of V will be permuted.
  • -
-
-

Note that the permutation iterator is not limited to strict -permutations of the given range V. The distance between begin and end -of the reindexing iterators is allowed to be smaller compared to the -size of the range V, in which case the permutation iterator only -provides a permutation of a subrange of V. The indexes neither need -to be unique. In this same context, it must be noted that the past the -end permutation iterator is completely defined by means of the -past-the-end iterator to the indices.

-
-
-

Reference

-
-template< class ElementIterator
-        , class IndexIterator
-        , class ValueT        = use_default
-        , class CategoryT     = use_default
-        , class ReferenceT    = use_default
-        , class DifferenceT   = use_default >
-class permutation_iterator
-{
-public:
-  permutation_iterator();
-  explicit permutation_iterator(ElementIterator x, IndexIterator y);
-
-  template< class OEIter, class OIIter, class V, class C, class R, class D >
-  permutation_iterator(
-      permutation_iterator<OEIter, OIIter, V, C, R, D> const& r
-      , typename enable_if_convertible<OEIter, ElementIterator>::type* = 0
-      , typename enable_if_convertible<OIIter, IndexIterator>::type* = 0
-      );
-  reference operator*() const;
-  permutation_iterator& operator++();
-  ElementIterator const& base() const;
-private:
-  ElementIterator m_elt;      // exposition only
-  IndexIterator m_order;      // exposition only
-};
-
-template <class ElementIterator, class IndexIterator>
-permutation_iterator<ElementIterator, IndexIterator> 
-make_permutation_iterator( ElementIterator e, IndexIterator i);
-
-
-

permutation_iterator requirements

-

ElementIterator shall model Random Access Traversal Iterator. -IndexIterator shall model Readable Iterator. The value type of -the IndexIterator must be convertible to the difference type of -ElementIterator.

-
-
-

permutation_iterator models

-

permutation_iterator models the same iterator traversal concepts -as IndexIterator and the same iterator access concepts as -ElementIterator.

-

If IndexIterator models Single Pass Iterator and -ElementIterator models Readable Iterator then -permutation_iterator models Input Iterator.

-

If IndexIterator models Forward Traversal Iterator and -ElementIterator models Readable Lvalue Iterator then -permutation_iterator models Forward Iterator.

-

If IndexIterator models Bidirectional Traversal Iterator and -ElementIterator models Readable Lvalue Iterator then -permutation_iterator models Bidirectional Iterator.

-

If IndexIterator models Random Access Traversal Iterator and -ElementIterator models Readable Lvalue Iterator then -permutation_iterator models Random Access Iterator.

-

permutation_iterator<E1, X, V1, C2, R1, D1> is interoperable -with permutation_iterator<E2, Y, V2, C2, R2, D2> if and only if -X is interoperable with Y and E1 is convertible -to E2.

-
-
-

permutation_iterator operations

-

In addition to those operations required by the concepts that -permutation_iterator models, permutation_iterator provides the -following operations.

-

permutation_iterator();

- --- - - - -
Effects:Default constructs m_elt and m_order.
-

explicit permutation_iterator(ElementIterator x, IndexIterator y);

- --- - - - -
Effects:Constructs m_elt from x and m_order from y.
-
-template< class OEIter, class OIIter, class V, class C, class R, class D >
-permutation_iterator(
-    permutation_iterator<OEIter, OIIter, V, C, R, D> const& r
-    , typename enable_if_convertible<OEIter, ElementIterator>::type* = 0
-    , typename enable_if_convertible<OIIter, IndexIterator>::type* = 0
-    );
-
- --- - - - -
Effects:Constructs m_elt from r.m_elt and -m_order from y.m_order.
-

reference operator*() const;

- --- - - - -
Returns:*(m_elt + *m_order)
-

permutation_iterator& operator++();

- --- - - - - - -
Effects:++m_order
Returns:*this
-

ElementIterator const& base() const;

- --- - - - -
Returns:m_order
-
-template <class ElementIterator, class IndexIterator>
-permutation_iterator<ElementIterator, IndexIterator> 
-make_permutation_iterator(ElementIterator e, IndexIterator i);
-
- --- - - - -
Returns:permutation_iterator<ElementIterator, IndexIterator>(e, i)
-
-
-
-

Example

-
-using namespace boost;
-int i = 0;
-
-typedef std::vector< int > element_range_type;
-typedef std::list< int > index_type;
-
-static const int element_range_size = 10;
-static const int index_size = 4;
-
-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 permutation_iterator< element_range_type::iterator, index_type::iterator > permutation_type;
-permutation_type begin = make_permutation_iterator( elements.begin(), indices.begin() );
-permutation_type it = begin;
-permutation_type end = make_permutation_iterator( elements.begin(), indices.end() );
-
-std::cout << "The original range is : ";
-std::copy( elements.begin(), elements.end(), std::ostream_iterator< int >( std::cout, " " ) );
-std::cout << "\n";
-
-std::cout << "The reindexing scheme is : ";
-std::copy( indices.begin(), indices.end(), std::ostream_iterator< int >( std::cout, " " ) );
-std::cout << "\n";
-
-std::cout << "The permutated range is : ";
-std::copy( begin, end, std::ostream_iterator< int >( std::cout, " " ) );
-std::cout << "\n";
-
-std::cout << "Elements at even indices in the permutation : ";
-it = begin;
-for(i = 0; i < index_size / 2 ; ++i, it+=2 ) std::cout << *it << " ";
-std::cout << "\n";
-
-std::cout << "Permutation backwards : ";
-it = begin + (index_size);
-assert( it != begin );
-for( ; it-- != begin ; ) std::cout << *it << " ";
-std::cout << "\n";
-
-std::cout << "Iterate backward with stride 2 : ";
-it = begin + (index_size - 1);
-for(i = 0 ; i < index_size / 2 ; ++i, it-=2 ) std::cout << *it << " ";
-std::cout << "\n";
-
-

The output is:

-
-The original range is : 0 1 2 3 4 5 6 7 8 9 
-The reindexing scheme is : 9 8 7 6 
-The permutated range is : 9 8 7 6 
-Elements at even indices in the permutation : 9 7 
-Permutation backwards : 6 7 8 9 
-Iterate backward with stride 2 : 6 8 
-
-

The source code for this example can be found here.

-
-
- - - - diff --git a/doc/permutation_iterator.rst b/doc/permutation_iterator.rst deleted file mode 100644 index 11fa6e1..0000000 --- a/doc/permutation_iterator.rst +++ /dev/null @@ -1,37 +0,0 @@ -++++++++++++++++++++++ - Permutation Iterator -++++++++++++++++++++++ - -:Author: Toon Knapen, David Abrahams, Roland Richter, Jeremy Siek -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_ -:date: $Date$ -:copyright: Copyright Toon Knapen, David Abrahams, Roland Richter, and Jeremy Siek 2003. All rights reserved - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu - -:abstract: - - .. include:: permutation_iterator_abstract.rst - -.. contents:: Table of Contents - - -Introduction -============ - -.. include:: permutation_iterator_body.rst - - -Reference -========= - -.. include:: permutation_iterator_ref.rst - - -Example -======= - -.. include:: permutation_iterator_eg.rst diff --git a/doc/permutation_iterator_abstract.rst b/doc/permutation_iterator_abstract.rst deleted file mode 100644 index 578b3ed..0000000 --- a/doc/permutation_iterator_abstract.rst +++ /dev/null @@ -1,4 +0,0 @@ -The permutation iterator adaptor provides a permuted view of a given -range. That is, the view includes every element of the given range but -in a potentially different order. - diff --git a/doc/permutation_iterator_body.rst b/doc/permutation_iterator_body.rst deleted file mode 100644 index 0f838e7..0000000 --- a/doc/permutation_iterator_body.rst +++ /dev/null @@ -1,15 +0,0 @@ -The adaptor takes two arguments: - - * an iterator to the range V on which the permutation - will be applied - * the reindexing scheme that defines how the - elements of V will be permuted. - -Note that the permutation iterator is not limited to strict -permutations of the given range V. The distance between begin and end -of the reindexing iterators is allowed to be smaller compared to the -size of the range V, in which case the permutation iterator only -provides a permutation of a subrange of V. The indexes neither need -to be unique. In this same context, it must be noted that the past the -end permutation iterator is completely defined by means of the -past-the-end iterator to the indices. diff --git a/doc/permutation_iterator_eg.rst b/doc/permutation_iterator_eg.rst deleted file mode 100644 index b493c7a..0000000 --- a/doc/permutation_iterator_eg.rst +++ /dev/null @@ -1,67 +0,0 @@ -:: - - using namespace boost; - int i = 0; - - typedef std::vector< int > element_range_type; - typedef std::list< int > index_type; - - static const int element_range_size = 10; - static const int index_size = 4; - - 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 permutation_iterator< element_range_type::iterator, index_type::iterator > permutation_type; - permutation_type begin = make_permutation_iterator( elements.begin(), indices.begin() ); - permutation_type it = begin; - permutation_type end = make_permutation_iterator( elements.begin(), indices.end() ); - - std::cout << "The original range is : "; - std::copy( elements.begin(), elements.end(), std::ostream_iterator< int >( std::cout, " " ) ); - std::cout << "\n"; - - std::cout << "The reindexing scheme is : "; - std::copy( indices.begin(), indices.end(), std::ostream_iterator< int >( std::cout, " " ) ); - std::cout << "\n"; - - std::cout << "The permutated range is : "; - std::copy( begin, end, std::ostream_iterator< int >( std::cout, " " ) ); - std::cout << "\n"; - - std::cout << "Elements at even indices in the permutation : "; - it = begin; - for(i = 0; i < index_size / 2 ; ++i, it+=2 ) std::cout << *it << " "; - std::cout << "\n"; - - std::cout << "Permutation backwards : "; - it = begin + (index_size); - assert( it != begin ); - for( ; it-- != begin ; ) std::cout << *it << " "; - std::cout << "\n"; - - std::cout << "Iterate backward with stride 2 : "; - it = begin + (index_size - 1); - for(i = 0 ; i < index_size / 2 ; ++i, it-=2 ) std::cout << *it << " "; - std::cout << "\n"; - - -The output is:: - - The original range is : 0 1 2 3 4 5 6 7 8 9 - The reindexing scheme is : 9 8 7 6 - The permutated range is : 9 8 7 6 - Elements at even indices in the permutation : 9 7 - Permutation backwards : 6 7 8 9 - Iterate backward with stride 2 : 6 8 - - -The source code for this example can be found `here`__. - -__ ../example/permutation_iterator_example.cpp diff --git a/doc/permutation_iterator_ref.rst b/doc/permutation_iterator_ref.rst deleted file mode 100644 index c29f285..0000000 --- a/doc/permutation_iterator_ref.rst +++ /dev/null @@ -1,126 +0,0 @@ -.. parsed-literal:: - - template< class ElementIterator - , class IndexIterator - , class ValueT = use_default - , class CategoryT = use_default - , class ReferenceT = use_default - , class DifferenceT = use_default > - class permutation_iterator - { - public: - permutation_iterator(); - explicit permutation_iterator(ElementIterator x, IndexIterator y); - - template< class OEIter, class OIIter, class V, class C, class R, class D > - permutation_iterator( - permutation_iterator const& r - , typename enable_if_convertible::type* = 0 - , typename enable_if_convertible::type* = 0 - ); - reference operator*() const; - permutation_iterator& operator++(); - ElementIterator const& base() const; - private: - ElementIterator m_elt; // exposition only - IndexIterator m_order; // exposition only - }; - - template - permutation_iterator - make_permutation_iterator( ElementIterator e, IndexIterator i); - - - -``permutation_iterator`` requirements -------------------------------------- - -``ElementIterator`` shall model Random Access Traversal Iterator. -``IndexIterator`` shall model Readable Iterator. The value type of -the ``IndexIterator`` must be convertible to the difference type of -``ElementIterator``. - - -``permutation_iterator`` models -------------------------------- - -``permutation_iterator`` models the same iterator traversal concepts -as ``IndexIterator`` and the same iterator access concepts as -``ElementIterator``. - -If ``IndexIterator`` models Single Pass Iterator and -``ElementIterator`` models Readable Iterator then -``permutation_iterator`` models Input Iterator. - -If ``IndexIterator`` models Forward Traversal Iterator and -``ElementIterator`` models Readable Lvalue Iterator then -``permutation_iterator`` models Forward Iterator. - -If ``IndexIterator`` models Bidirectional Traversal Iterator and -``ElementIterator`` models Readable Lvalue Iterator then -``permutation_iterator`` models Bidirectional Iterator. - -If ``IndexIterator`` models Random Access Traversal Iterator and -``ElementIterator`` models Readable Lvalue Iterator then -``permutation_iterator`` models Random Access Iterator. - -``permutation_iterator`` is interoperable -with ``permutation_iterator`` if and only if -``X`` is interoperable with ``Y`` and ``E1`` is convertible -to ``E2``. - - -``permutation_iterator`` operations ------------------------------------ - -In addition to those operations required by the concepts that -``permutation_iterator`` models, ``permutation_iterator`` provides the -following operations. - -``permutation_iterator();`` - -:Effects: Default constructs ``m_elt`` and ``m_order``. - - -``explicit permutation_iterator(ElementIterator x, IndexIterator y);`` - -:Effects: Constructs ``m_elt`` from ``x`` and ``m_order`` from ``y``. - - -:: - - template< class OEIter, class OIIter, class V, class C, class R, class D > - permutation_iterator( - permutation_iterator const& r - , typename enable_if_convertible::type* = 0 - , typename enable_if_convertible::type* = 0 - ); - -:Effects: Constructs ``m_elt`` from ``r.m_elt`` and - ``m_order`` from ``y.m_order``. - - -``reference operator*() const;`` - -:Returns: ``*(m_elt + *m_order)`` - - -``permutation_iterator& operator++();`` - -:Effects: ``++m_order`` -:Returns: ``*this`` - - -``ElementIterator const& base() const;`` - -:Returns: ``m_order`` - - -:: - - template - permutation_iterator - make_permutation_iterator(ElementIterator e, IndexIterator i); - -:Returns: ``permutation_iterator(e, i)`` - diff --git a/doc/pointee.html b/doc/pointee.html deleted file mode 100755 index 4ca16d8..0000000 --- a/doc/pointee.html +++ /dev/null @@ -1,179 +0,0 @@ - - - - - - -pointee and indirect_reference - - - - - - - -
-

pointee and indirect_reference

- --- - - - - - - - - - - - -
Author:David Abrahams
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting
Date:2004-01-13
Copyright:Copyright David Abrahams 2004. All rights reserved
- --- - - - -
abstract:Provides the capability to deduce the referent types of -pointers, smart pointers and iterators in generic code.
-
-

Overview

-

Have you ever wanted to write a generic function that can operate -on any kind of dereferenceable object? If you have, you've -probably run into the problem of how to determine the type that the -object "points at":

-
-template <class Dereferenceable>
-void f(Dereferenceable p)
-{
-    what-goes-here? value = *p;
-    ...
-}
-
-
-

pointee

-

It turns out to be impossible to come up with a fully-general -algorithm to do determine what-goes-here directly, but it is -possible to require that pointee<Dereferenceable>::type is -correct. Naturally, pointee has the same difficulty: it can't -determine the appropriate ::type reliably for all -Dereferenceables, but it makes very good guesses (it works -for all pointers, standard and boost smart pointers, and -iterators), and when it guesses wrongly, it can be specialized as -neccessary:

-
-namespace boost
-{
-  template <class T>
-  struct pointee<third_party_lib::smart_pointer<T> >
-  {
-      typedef T type;
-  };
-}
-
-
-
-

indirect_reference

-

indirect_reference<T>::type is rather more specialized than -pointee, and is meant to be used to forward the result of -dereferencing an object of its argument type. Most dereferenceable -types just return a reference to their pointee, but some return -proxy references or return the pointee by value. When that -information is needed, call on indirect_reference.

-

Both of these templates are essential to the correct functioning of -indirect_iterator.

-
-
-
-

Reference

-
-

pointee

- - - -
-template <class Dereferenceable>
-struct pointee
-{
-    typedef /* see below */ type;
-};
-
- --- - - - -
Requires:For an object x of type Dereferenceable, *x -is well-formed. If ++x is ill-formed it shall neither be -ambiguous nor shall it violate access control, and -Dereferenceable::element_type shall be an accessible type. -Otherwise iterator_traits<Dereferenceable>::value_type shall -be well formed. [Note: These requirements need not apply to -explicit or partial specializations of pointee]
-

type is determined according to the following algorithm, where -x is an object of type Dereferenceable:

-
-if ( ++x is ill-formed )
-{
-    return ``Dereferenceable::element_type``
-}
-else if (``*x`` is a mutable reference to
-         std::iterator_traits<Dereferenceable>::value_type)
-{
-    return iterator_traits<Dereferenceable>::value_type
-}
-else
-{
-    return iterator_traits<Dereferenceable>::value_type const
-}
-
-
-
-

indirect_reference

- - - -
-template <class Dereferenceable>
-struct indirect_reference
-{
-    typedef /* see below */ type;
-};
-
- --- - - - -
Requires:For an object x of type Dereferenceable, *x -is well-formed. If ++x is ill-formed it shall neither be -ambiguous nor shall it violate access control, and -pointee<Dereferenceable>::type& shall be well-formed. -Otherwise iterator_traits<Dereferenceable>::reference shall -be well formed. [Note: These requirements need not apply to -explicit or partial specializations of indirect_reference]
-

type is determined according to the following algorithm, where -x is an object of type Dereferenceable:

-
-if ( ++x is ill-formed )
-    return ``pointee<Dereferenceable>::type&``
-else
-    std::iterator_traits<Dereferenceable>::reference
-
-
-
-
- - - - diff --git a/doc/pointee.rst b/doc/pointee.rst deleted file mode 100755 index 21b90a4..0000000 --- a/doc/pointee.rst +++ /dev/null @@ -1,84 +0,0 @@ -++++++++++++++++++++++++++++++++++++++++ - ``pointee`` and ``indirect_reference`` -++++++++++++++++++++++++++++++++++++++++ - -:Author: David Abrahams -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_ -:date: $Date$ -:copyright: Copyright David Abrahams 2004. All rights reserved - -.. _`Boost Consulting`: http://www.boost-consulting.com - -:abstract: Provides the capability to deduce the referent types of - pointers, smart pointers and iterators in generic code. - -Overview -======== - -Have you ever wanted to write a generic function that can operate -on any kind of dereferenceable object? If you have, you've -probably run into the problem of how to determine the type that the -object "points at": - -.. parsed-literal:: - - template - void f(Dereferenceable p) - { - *what-goes-here?* value = \*p; - ... - } - - -``pointee`` ------------ - -It turns out to be impossible to come up with a fully-general -algorithm to do determine *what-goes-here* directly, but it is -possible to require that ``pointee::type`` is -correct. Naturally, ``pointee`` has the same difficulty: it can't -determine the appropriate ``::type`` reliably for all -``Dereferenceable``\ s, but it makes very good guesses (it works -for all pointers, standard and boost smart pointers, and -iterators), and when it guesses wrongly, it can be specialized as -neccessary:: - - namespace boost - { - template - struct pointee > - { - typedef T type; - }; - } - -``indirect_reference`` ----------------------- - -``indirect_reference::type`` is rather more specialized than -``pointee``, and is meant to be used to forward the result of -dereferencing an object of its argument type. Most dereferenceable -types just return a reference to their pointee, but some return -proxy references or return the pointee by value. When that -information is needed, call on ``indirect_reference``. - -Both of these templates are essential to the correct functioning of -|indirect_iterator|_. - -.. |indirect_iterator| replace:: ``indirect_iterator`` -.. _indirect_iterator: indirect_iterator.html - -Reference -========= - -``pointee`` ------------ - -.. include:: pointee_ref.rst - -``indirect_reference`` ----------------------- - -.. include:: indirect_reference_ref.rst - diff --git a/doc/pointee_ref.rst b/doc/pointee_ref.rst deleted file mode 100755 index 19aed24..0000000 --- a/doc/pointee_ref.rst +++ /dev/null @@ -1,38 +0,0 @@ -.. 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) - -:: - - template - struct pointee - { - typedef /* see below */ type; - }; - -:Requires: For an object ``x`` of type ``Dereferenceable``, ``*x`` - is well-formed. If ``++x`` is ill-formed it shall neither be - ambiguous nor shall it violate access control, and - ``Dereferenceable::element_type`` shall be an accessible type. - Otherwise ``iterator_traits::value_type`` shall - be well formed. [Note: These requirements need not apply to - explicit or partial specializations of ``pointee``] - -``type`` is determined according to the following algorithm, where -``x`` is an object of type ``Dereferenceable``:: - - if ( ++x is ill-formed ) - { - return ``Dereferenceable::element_type`` - } - else if (``*x`` is a mutable reference to - std::iterator_traits::value_type) - { - return iterator_traits::value_type - } - else - { - return iterator_traits::value_type const - } - - \ No newline at end of file diff --git a/doc/ref_problem.rst b/doc/ref_problem.rst deleted file mode 100644 index 2f2908a..0000000 --- a/doc/ref_problem.rst +++ /dev/null @@ -1,63 +0,0 @@ -++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - Problem with ``reference`` and old/new iterator category correspondance -++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -.. _N1550: http://www.boost-consulting.com/writing/n1550.html -.. _N1530: http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1530.html - -:Author: David Abrahams and Jeremy Siek -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu -:Organization: `Boost Consulting`_, Indiana University Bloomington -:date: $Date$ -:Copyright: Copyright David Abrahams, Jeremy Siek 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) - -.. _`Boost Consulting`: http://www.boost-consulting.com - -============== - Introduction -============== - -The new iterator categories are intended to correspond to the old -iterator categories, as specified in a diagram in N1550_. For example, -an iterator categorized as a mutable Forward Iterator under the old -scheme is now a Writable, Lvalue, and Foward Traversal iterator. -However, there is a problem with this correspondance, the new iterator -categories place requirements on the ``iterator_traits::reference`` -type whereas the standard iterator requirements say nothing about the -``reference`` type . In particular, the new Readable Iterator -requirements say that the return type of ``*a`` must be -``iterator_traits::reference`` and the Lvalue Iterator requirements -says that ``iterator_traits::reference`` must be ``T&`` or ``const -T&``. - - -==================== - Proposed Resolution -==================== - -Change the standard requirements to match the requirements of the new -iterators. (more details to come) - - -========== - Rationale -========== - -The lack of specification in the standard of the ``reference`` type is -certainly a defect. Without specification, it is entirely useless in a -generic function. The current practice in the community is generally -to assume there are requirements on the ``reference`` type, such as -those proposed in the new iterator categories. - -There is some danger in *adding* requirements to existing concepts. -This will mean that some existing iterator types will no longer meet -the iterator requirements. However, we feel that the impact of this is -small enough to warrant going ahead with this change. - -An alternative solution would be to leave the standard requirements as -is, and to remove the requirements for the ``reference`` type in the -new iterator concepts. We are not in favor of this approach because it -extends what we see as a defect further into the future. diff --git a/doc/reverse_iterator.html b/doc/reverse_iterator.html deleted file mode 100644 index acc42cb..0000000 --- a/doc/reverse_iterator.html +++ /dev/null @@ -1,279 +0,0 @@ - - - - - - -Reverse Iterator - - - - - - - -
-

Reverse Iterator

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-01-13
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved
- --- - - - -
abstract:The reverse iterator adaptor iterates through the adapted iterator -range in the opposite direction.
- -
-

reverse_iterator synopsis

-
-template <class Iterator>
-class reverse_iterator
-{
-public:
-  typedef iterator_traits<Iterator>::value_type value_type;
-  typedef iterator_traits<Iterator>::reference reference;
-  typedef iterator_traits<Iterator>::pointer pointer;
-  typedef iterator_traits<Iterator>::difference_type difference_type;
-  typedef /* see below */ iterator_category;
-
-  reverse_iterator() {}
-  explicit reverse_iterator(Iterator x) ;
-
-  template<class OtherIterator>
-  reverse_iterator(
-      reverse_iterator<OtherIterator> const& r
-    , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-  );
-  Iterator const& base() const;
-  reference operator*() const;
-  reverse_iterator& operator++();
-  reverse_iterator& operator--();
-private:
-  Iterator m_iterator; // exposition
-};
-
-

If Iterator models Random Access Traversal Iterator and Readable -Lvalue Iterator, then iterator_category is convertible to -random_access_iterator_tag. Otherwise, if -Iterator models Bidirectional Traversal Iterator and Readable -Lvalue Iterator, then iterator_category is convertible to -bidirectional_iterator_tag. Otherwise, iterator_category is -convertible to input_iterator_tag.

-
-
-

reverse_iterator requirements

-

Iterator must be a model of Bidirectional Traversal Iterator.

-
-
-

reverse_iterator models

-

A specialization of reverse_iterator models the same iterator -traversal and iterator access concepts modeled by its Iterator -argument. In addition, it may model old iterator concepts -specified in the following table:

- ---- - - - - - - - - - - - - - - - - - - - -
If I modelsthen reverse_iterator<I> models
Readable Lvalue Iterator, -Bidirectional Traversal IteratorBidirectional Iterator
Writable Lvalue Iterator, -Bidirectional Traversal IteratorMutable Bidirectional Iterator
Readable Lvalue Iterator, -Random Access Traversal IteratorRandom Access Iterator
Writable Lvalue Iterator, -Random Access Traversal IteratorMutable Random Access Iterator
-

reverse_iterator<X> is interoperable with -reverse_iterator<Y> if and only if X is interoperable with -Y.

-
-
-

reverse_iterator operations

-

In addition to the operations required by the concepts modeled by -reverse_iterator, reverse_iterator provides the following -operations.

-

reverse_iterator();

- --- - - - - - -
Requires:Iterator must be Default Constructible.
Effects:Constructs an instance of reverse_iterator with m_iterator -default constructed.
-

explicit reverse_iterator(Iterator x);

- --- - - - -
Effects:Constructs an instance of reverse_iterator with -m_iterator copy constructed from x.
-
-template<class OtherIterator>
-reverse_iterator(
-    reverse_iterator<OtherIterator> const& r
-  , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-);
-
- --- - - - - - -
Requires:OtherIterator is implicitly convertible to Iterator.
Effects:Constructs instance of reverse_iterator whose -m_iterator subobject is constructed from y.base().
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Effects:
-
-Iterator tmp = m_iterator;
-return *--tmp;
-
-

reverse_iterator& operator++();

- --- - - - - - -
Effects:--m_iterator
Returns:*this
-

reverse_iterator& operator--();

- --- - - - - - -
Effects:++m_iterator
Returns:*this
-
-template <class BidirectionalIterator>
-reverse_iterator<BidirectionalIterator>n
-make_reverse_iterator(BidirectionalIterator x);
-
- --- - - - -
Returns:An instance of reverse_iterator<BidirectionalIterator> -with a current constructed from x.
-
-
-

Example

-

The following example prints an array of characters in reverse order -using reverse_iterator.

-
-char letters_[] = "hello world!";
-const int N = sizeof(letters_)/sizeof(char) - 1;
-typedef char* base_iterator;
-base_iterator letters(letters_);
-std::cout << "original sequence of letters:\t\t\t" << letters_ << std::endl;
-
-boost::reverse_iterator<base_iterator>
-  reverse_letters_first(letters + N),
-  reverse_letters_last(letters);
-
-std::cout << "sequence in reverse order:\t\t\t";
-std::copy(reverse_letters_first, reverse_letters_last,
-          std::ostream_iterator<char>(std::cout));
-std::cout << std::endl;
-
-std::cout << "sequence in double-reversed (normal) order:\t";
-std::copy(boost::make_reverse_iterator(reverse_letters_last),
-          boost::make_reverse_iterator(reverse_letters_first),
-          std::ostream_iterator<char>(std::cout));
-std::cout << std::endl;
-
-

The output is:

-
-original sequence of letters:                   hello world!
-sequence in reverse order:                      !dlrow olleh
-sequence in double-reversed (normal) order:     hello world!
-
-

The source code for this example can be found here.

-
-
- - - - diff --git a/doc/reverse_iterator.rst b/doc/reverse_iterator.rst deleted file mode 100644 index 0f4979b..0000000 --- a/doc/reverse_iterator.rst +++ /dev/null @@ -1,29 +0,0 @@ -++++++++++++++++++ - Reverse Iterator -++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: - - .. include:: reverse_iterator_abstract.rst - -.. contents:: Table of Contents - -``reverse_iterator`` synopsis -............................. - -.. include:: reverse_iterator_ref.rst -.. include:: make_reverse_iterator.rst - -.. include:: reverse_iterator_eg.rst diff --git a/doc/reverse_iterator_abstract.rst b/doc/reverse_iterator_abstract.rst deleted file mode 100644 index a4caee5..0000000 --- a/doc/reverse_iterator_abstract.rst +++ /dev/null @@ -1,9 +0,0 @@ - -The reverse iterator adaptor iterates through the adapted iterator -range in the opposite direction. - - - - - - diff --git a/doc/reverse_iterator_eg.rst b/doc/reverse_iterator_eg.rst deleted file mode 100644 index 7923f2f..0000000 --- a/doc/reverse_iterator_eg.rst +++ /dev/null @@ -1,42 +0,0 @@ - -Example -....... - -The following example prints an array of characters in reverse order -using ``reverse_iterator``. - -:: - - char letters_[] = "hello world!"; - const int N = sizeof(letters_)/sizeof(char) - 1; - typedef char* base_iterator; - base_iterator letters(letters_); - std::cout << "original sequence of letters:\t\t\t" << letters_ << std::endl; - - boost::reverse_iterator - reverse_letters_first(letters + N), - reverse_letters_last(letters); - - std::cout << "sequence in reverse order:\t\t\t"; - std::copy(reverse_letters_first, reverse_letters_last, - std::ostream_iterator(std::cout)); - std::cout << std::endl; - - std::cout << "sequence in double-reversed (normal) order:\t"; - std::copy(boost::make_reverse_iterator(reverse_letters_last), - boost::make_reverse_iterator(reverse_letters_first), - std::ostream_iterator(std::cout)); - std::cout << std::endl; - - - -The output is:: - - original sequence of letters: hello world! - sequence in reverse order: !dlrow olleh - sequence in double-reversed (normal) order: hello world! - - -The source code for this example can be found `here`__. - -__ ../example/reverse_iterator_example.cpp diff --git a/doc/reverse_iterator_ref.rst b/doc/reverse_iterator_ref.rst deleted file mode 100644 index 2e56040..0000000 --- a/doc/reverse_iterator_ref.rst +++ /dev/null @@ -1,135 +0,0 @@ -:: - - template - class reverse_iterator - { - public: - typedef iterator_traits::value_type value_type; - typedef iterator_traits::reference reference; - typedef iterator_traits::pointer pointer; - typedef iterator_traits::difference_type difference_type; - typedef /* see below */ iterator_category; - - reverse_iterator() {} - explicit reverse_iterator(Iterator x) ; - - template - reverse_iterator( - reverse_iterator const& r - , typename enable_if_convertible::type* = 0 // exposition - ); - Iterator const& base() const; - reference operator*() const; - reverse_iterator& operator++(); - reverse_iterator& operator--(); - private: - Iterator m_iterator; // exposition - }; - - -If ``Iterator`` models Random Access Traversal Iterator and Readable -Lvalue Iterator, then ``iterator_category`` is convertible to -``random_access_iterator_tag``. Otherwise, if -``Iterator`` models Bidirectional Traversal Iterator and Readable -Lvalue Iterator, then ``iterator_category`` is convertible to -``bidirectional_iterator_tag``. Otherwise, ``iterator_category`` is -convertible to ``input_iterator_tag``. - - - -``reverse_iterator`` requirements -................................. - -``Iterator`` must be a model of Bidirectional Traversal Iterator. - - - -``reverse_iterator`` models -........................... - -A specialization of ``reverse_iterator`` models the same iterator -traversal and iterator access concepts modeled by its ``Iterator`` -argument. In addition, it may model old iterator concepts -specified in the following table: - -+---------------------------------------+-----------------------------------+ -| If ``I`` models |then ``reverse_iterator`` models| -+=======================================+===================================+ -| Readable Lvalue Iterator, | Bidirectional Iterator | -| Bidirectional Traversal Iterator | | -+---------------------------------------+-----------------------------------+ -| Writable Lvalue Iterator, | Mutable Bidirectional Iterator | -| Bidirectional Traversal Iterator | | -+---------------------------------------+-----------------------------------+ -| Readable Lvalue Iterator, | Random Access Iterator | -| Random Access Traversal Iterator | | -+---------------------------------------+-----------------------------------+ -| Writable Lvalue Iterator, | Mutable Random Access Iterator | -| Random Access Traversal Iterator | | -+---------------------------------------+-----------------------------------+ - - -``reverse_iterator`` is interoperable with -``reverse_iterator`` if and only if ``X`` is interoperable with -``Y``. - -``reverse_iterator`` operations -............................... - -In addition to the operations required by the concepts modeled by -``reverse_iterator``, ``reverse_iterator`` provides the following -operations. - - - -``reverse_iterator();`` - -:Requires: ``Iterator`` must be Default Constructible. -:Effects: Constructs an instance of ``reverse_iterator`` with ``m_iterator`` - default constructed. - -``explicit reverse_iterator(Iterator x);`` - -:Effects: Constructs an instance of ``reverse_iterator`` with - ``m_iterator`` copy constructed from ``x``. - - -:: - - template - reverse_iterator( - reverse_iterator const& r - , typename enable_if_convertible::type* = 0 // exposition - ); - -:Requires: ``OtherIterator`` is implicitly convertible to ``Iterator``. -:Effects: Constructs instance of ``reverse_iterator`` whose - ``m_iterator`` subobject is constructed from ``y.base()``. - - - -``Iterator const& base() const;`` - -:Returns: ``m_iterator`` - - -``reference operator*() const;`` - -:Effects: - -:: - - Iterator tmp = m_iterator; - return *--tmp; - - -``reverse_iterator& operator++();`` - -:Effects: ``--m_iterator`` -:Returns: ``*this`` - - -``reverse_iterator& operator--();`` - -:Effects: ``++m_iterator`` -:Returns: ``*this`` diff --git a/doc/rst2html b/doc/rst2html deleted file mode 100755 index bd8dc8f..0000000 --- a/doc/rst2html +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -PYTHONPATH="c:/src/docutils/docutils;c:/src/docutils/docutils/extras" -export PYTHONPATH -python c:/src/docutils/docutils/tools/html.py -gs $1 `echo $1 | sed 's/\(.*\)\..*/\1.html/'` - - - diff --git a/doc/scanrst.py b/doc/scanrst.py deleted file mode 100644 index 484d879..0000000 --- a/doc/scanrst.py +++ /dev/null @@ -1,29 +0,0 @@ -# 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) - -# This script accepts a list of .rst files to be processed and -# generates Makefile dependencies for .html and .rst files to stdout. -import os,sys -import re - -include = re.compile(r' *\.\. +(include|image):: +(.*)', re.MULTILINE) - -def deps(path, found): - dir = os.path.split(path)[0] - for m in re.findall(include, open(path).read()): - - dependency = os.path.normpath(os.path.join(dir,m[1])) - if dependency not in found: - found[dependency] = 1 - - if m[0] == 'include': - deps(dependency, found) - - return found - -for file in sys.argv[1:]: - found = deps(file, {}) - if found: - base = os.path.splitext(os.path.basename(file))[0] - print '%s.tex %s.html: %s' % (base, base, ' '.join(found.keys())) diff --git a/doc/sources.py b/doc/sources.py deleted file mode 100644 index c85e307..0000000 --- a/doc/sources.py +++ /dev/null @@ -1,19 +0,0 @@ -# This is where we list the ReStructuredText source files that form -# the book. When you're ready to expose a new chapter, add the -# filename here and put links in index.rst - -sources = [ -'counting_iterator.rst', -'facade-and-adaptor.rst', -'filter_iterator.rst', -'function_output_iterator.rst', -'index.rst', -'indirect_iterator.rst', -'pointee.rst', -'iterator_adaptor.rst', -'iterator_facade.rst', -'new-iter-concepts.rst', -'permutation_iterator.rst', -'reverse_iterator.rst' - ] - diff --git a/doc/style.tex b/doc/style.tex deleted file mode 100755 index 681d6b3..0000000 --- a/doc/style.tex +++ /dev/null @@ -1,41 +0,0 @@ -% donot indent first line. -\setlength{\parindent}{0pt} -\setlength{\parskip}{5pt plus 2pt minus 1pt} - -% sloppy -% ------ -% Less strict (opposite to default fussy) space size between words. Therefore -% less hyphenation. -\sloppy - -% fonts -% ----- -% times for pdf generation, gives smaller pdf files. -% -% But in standard postscript fonts: courier and times/helvetica do not fit. -% Maybe use pslatex. -\usepackage{times} -\usepackage{pslatex} - -% pagestyle -% \usepackage{fancyhdr} -\pagestyle{headings} -\setlength{\paperwidth}{8.5in} -\setlength{\paperheight}{11in} - -\setlength{\oddsidemargin}{0.375in} -\setlength{\evensidemargin}{0.375in} -\setlength{\textwidth}{6.125in} -\setlength{\textheight}{8.875in} - -\setlength{\topmargin}{-0.375in} -\setlength{\headheight}{0.25in} -\setlength{\headsep}{0.25in} -\setlength{\footskip}{0.25in} - -\setlength{\admonitionwidth}{0.9\textwidth} -\setlength{\docinfowidth}{0.9\textwidth} - - - - diff --git a/doc/transform_iterator.html b/doc/transform_iterator.html deleted file mode 100644 index e5a715f..0000000 --- a/doc/transform_iterator.html +++ /dev/null @@ -1,322 +0,0 @@ - - - - - - -Transform Iterator - - - - - - - -
-

Transform Iterator

- --- - - - - - - - - - - - -
Author:David Abrahams, Jeremy Siek, Thomas Witt
Contact:dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de
Organization:Boost Consulting, Indiana University Open Systems -Lab, University of Hanover Institute for Transport -Railway Operation and Construction
Date:2004-01-13
Copyright:Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved
- --- - - - -
abstract:The transform iterator adapts an iterator by modifying the -operator* to apply a function object to the result of -dereferencing the iterator and returning the result.
- -
-

transform_iterator synopsis

- -
-template <class UnaryFunction,
-          class Iterator, 
-          class Reference = use_default, 
-          class Value = use_default>
-class transform_iterator
-{
-public:
-  typedef /* see below */ value_type;
-  typedef /* see below */ reference;
-  typedef /* see below */ pointer;
-  typedef iterator_traits<Iterator>::difference_type difference_type;
-  typedef /* see below */ iterator_category;
-
-  transform_iterator();
-  transform_iterator(Iterator const& x, UnaryFunction f);
-
-  template<class F2, class I2, class R2, class V2>
-  transform_iterator(
-        transform_iterator<F2, I2, R2, V2> const& t
-      , typename enable_if_convertible<I2, Iterator>::type* = 0      // exposition only
-      , typename enable_if_convertible<F2, UnaryFunction>::type* = 0 // exposition only
-  );
-  UnaryFunction functor() const;
-  Iterator const& base() const;
-  reference operator*() const;
-  transform_iterator& operator++();
-  transform_iterator& operator--();
-private:
-  Iterator m_iterator; // exposition only
-  UnaryFunction m_f;   // exposition only
-};
-
-

If Reference is use_default then the reference member of -transform_iterator is -result_of<UnaryFunction(iterator_traits<Iterator>::reference)>::type. -Otherwise, reference is Reference.

-

If Value is use_default then the value_type member is -remove_cv<remove_reference<reference> >::type. Otherwise, -value_type is Value.

-

If Iterator models Readable Lvalue Iterator and if Iterator -models Random Access Traversal Iterator, then iterator_category is -convertible to random_access_iterator_tag. Otherwise, if -Iterator models Bidirectional Traversal Iterator, then -iterator_category is convertible to -bidirectional_iterator_tag. Otherwise iterator_category is -convertible to forward_iterator_tag. If Iterator does not -model Readable Lvalue Iterator then iterator_category is -convertible to input_iterator_tag.

-
-
-

transform_iterator requirements

-

The type UnaryFunction must be Assignable, Copy Constructible, and -the expression f(*i) must be valid where f is an object of -type UnaryFunction, i is an object of type Iterator, and -where the type of f(*i) must be -result_of<UnaryFunction(iterator_traits<Iterator>::reference)>::type.

-

The argument Iterator shall model Readable Iterator.

-
-
-

transform_iterator models

-

The resulting transform_iterator models the most refined of the -following that is also modeled by Iterator.

-
-
    -
  • Writable Lvalue Iterator if transform_iterator::reference is a non-const reference.
  • -
  • Readable Lvalue Iterator if transform_iterator::reference is a const reference.
  • -
  • Readable Iterator otherwise.
  • -
-
-

The transform_iterator models the most refined standard traversal -concept that is modeled by the Iterator argument.

-

If transform_iterator is a model of Readable Lvalue Iterator then -it models the following original iterator concepts depending on what -the Iterator argument models.

- ---- - - - - - - - - - - - - - - - - - - - -
If Iterator modelsthen filter_iterator models
Single Pass IteratorInput Iterator
Forward Traversal IteratorForward Iterator
Bidirectional Traversal IteratorBidirectional Iterator
Random Access Traversal IteratorRandom Access Iterator
-

If transform_iterator models Writable Lvalue Iterator then it is a -mutable iterator (as defined in the old iterator requirements).

-

transform_iterator<F1, X, R1, V1> is interoperable with -transform_iterator<F2, Y, R2, V2> if and only if X is -interoperable with Y.

-
-
-

transform_iterator operations

-

In addition to the operations required by the concepts modeled by -transform_iterator, transform_iterator provides the following -operations.

-

transform_iterator();

- --- - - - -
Returns:An instance of transform_iterator with m_f -and m_iterator default constructed.
-

transform_iterator(Iterator const& x, UnaryFunction f);

- --- - - - -
Returns:An instance of transform_iterator with m_f -initialized to f and m_iterator initialized to x.
-
-template<class OtherIterator, class R2, class V2>
-transform_iterator(
-      transform_iterator<UnaryFunction, OtherIterator, R2, V2> const& t
-    , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition
-);
-
- --- - - - - - -
Returns:An instance of transform_iterator that is a copy of t.
Requires:OtherIterator is implicitly convertible to Iterator.
-

UnaryFunction functor() const;

- --- - - - -
Returns:m_f
-

Iterator const& base() const;

- --- - - - -
Returns:m_iterator
-

reference operator*() const;

- --- - - - -
Returns:m_f(*m_iterator)
-

transform_iterator& operator++();

- --- - - - - - -
Effects:++m_iterator
Returns:*this
-

transform_iterator& operator--();

- --- - - - - - -
Effects:--m_iterator
Returns:*this
-
-template <class UnaryFunction, class Iterator>
-transform_iterator<UnaryFunction, Iterator>
-make_transform_iterator(Iterator it, UnaryFunction fun);
-
- --- - - - -
Returns:An instance of transform_iterator<UnaryFunction, Iterator> with m_f -initialized to f and m_iterator initialized to x.
-
-template <class UnaryFunction, class Iterator>
-transform_iterator<UnaryFunction, Iterator>
-make_transform_iterator(Iterator it);
-
- --- - - - -
Returns:An instance of transform_iterator<UnaryFunction, Iterator> with m_f -default constructed and m_iterator initialized to x.
-
-
-

Example

-

This is a simple example of using the transform_iterators class to -generate iterators that multiply (or add to) the value returned by -dereferencing the iterator. It would be cooler to use lambda library -in this example.

-
-int x[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
-const int N = sizeof(x)/sizeof(int);
-
-typedef boost::binder1st< std::multiplies<int> > Function;
-typedef boost::transform_iterator<Function, int*> doubling_iterator;
-
-doubling_iterator i(x, boost::bind1st(std::multiplies<int>(), 2)),
-  i_end(x + N, boost::bind1st(std::multiplies<int>(), 2));
-
-std::cout << "multiplying the array by 2:" << std::endl;
-while (i != i_end)
-  std::cout << *i++ << " ";
-std::cout << std::endl;
-
-std::cout << "adding 4 to each element in the array:" << std::endl;
-std::copy(boost::make_transform_iterator(x, boost::bind1st(std::plus<int>(), 4)),
-          boost::make_transform_iterator(x + N, boost::bind1st(std::plus<int>(), 4)),
-          std::ostream_iterator<int>(std::cout, " "));
-std::cout << std::endl;
-
-

The output is:

-
-multiplying the array by 2:
-2 4 6 8 10 12 14 16 
-adding 4 to each element in the array:
-5 6 7 8 9 10 11 12
-
-

The source code for this example can be found here.

-
-
- - diff --git a/doc/transform_iterator.rst b/doc/transform_iterator.rst deleted file mode 100644 index 362db85..0000000 --- a/doc/transform_iterator.rst +++ /dev/null @@ -1,28 +0,0 @@ -++++++++++++++++++++ - Transform Iterator -++++++++++++++++++++ - -:Author: David Abrahams, Jeremy Siek, Thomas Witt -:Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@ive.uni-hannover.de -:organization: `Boost Consulting`_, Indiana University `Open Systems - Lab`_, University of Hanover `Institute for Transport - Railway Operation and Construction`_ -:date: $Date$ -:copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. All rights reserved - -.. _`Boost Consulting`: http://www.boost-consulting.com -.. _`Open Systems Lab`: http://www.osl.iu.edu -.. _`Institute for Transport Railway Operation and Construction`: http://www.ive.uni-hannover.de - -:abstract: - - .. include:: transform_iterator_abstract.rst - -.. contents:: Table of Contents - -``transform_iterator`` synopsis -............................... - -.. include:: transform_iterator_ref.rst -.. include:: make_transform_iterator.rst -.. include:: transform_iterator_eg.rst diff --git a/doc/transform_iterator_abstract.rst b/doc/transform_iterator_abstract.rst deleted file mode 100644 index 4d40536..0000000 --- a/doc/transform_iterator_abstract.rst +++ /dev/null @@ -1,3 +0,0 @@ -The transform iterator adapts an iterator by modifying the -``operator*`` to apply a function object to the result of -dereferencing the iterator and returning the result. diff --git a/doc/transform_iterator_eg.rst b/doc/transform_iterator_eg.rst deleted file mode 100755 index a6629ca..0000000 --- a/doc/transform_iterator_eg.rst +++ /dev/null @@ -1,42 +0,0 @@ -Example -....... - -This is a simple example of using the transform_iterators class to -generate iterators that multiply (or add to) the value returned by -dereferencing the iterator. It would be cooler to use lambda library -in this example. - -:: - - int x[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; - const int N = sizeof(x)/sizeof(int); - - typedef boost::binder1st< std::multiplies > Function; - typedef boost::transform_iterator doubling_iterator; - - doubling_iterator i(x, boost::bind1st(std::multiplies(), 2)), - i_end(x + N, boost::bind1st(std::multiplies(), 2)); - - std::cout << "multiplying the array by 2:" << std::endl; - while (i != i_end) - std::cout << *i++ << " "; - std::cout << std::endl; - - std::cout << "adding 4 to each element in the array:" << std::endl; - std::copy(boost::make_transform_iterator(x, boost::bind1st(std::plus(), 4)), - boost::make_transform_iterator(x + N, boost::bind1st(std::plus(), 4)), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - -The output is:: - - multiplying the array by 2: - 2 4 6 8 10 12 14 16 - adding 4 to each element in the array: - 5 6 7 8 9 10 11 12 - - -The source code for this example can be found `here`__. - -__ ../example/transform_iterator_example.cpp diff --git a/doc/transform_iterator_ref.diff b/doc/transform_iterator_ref.diff deleted file mode 100644 index 0f2d704..0000000 --- a/doc/transform_iterator_ref.diff +++ /dev/null @@ -1,202 +0,0 @@ -Index: transform_iterator_ref.rst -=================================================================== -RCS file: /cvsroot/boost/boost/libs/iterator/doc/transform_iterator_ref.rst,v -retrieving revision 1.3 -retrieving revision 1.15 -diff -w -d -u -b -r1.3 -r1.15 ---- transform_iterator_ref.rst 21 Sep 2003 11:13:46 -0000 1.3 -+++ transform_iterator_ref.rst 15 Jan 2004 00:06:57 -0000 1.15 -@@ -1,3 +1,5 @@ -+.. Version 1.3 of this document was accepted for TR1 -+ - :: - - template - class transform_iterator - -Issue 9.37x - -- : public iterator_adaptor - { -- friend class iterator_core_access; - public: -+ typedef /* see below */ value_type; -+ typedef /* see below */ reference; -+ typedef /* see below */ pointer; -+ typedef iterator_traits::difference_type difference_type; -+ typedef /* see below */ iterator_category; -+ - transform_iterator(); - transform_iterator(Iterator const& x, UnaryFunction f); - - -Issue 9.43x - -- template -+ template - transform_iterator( -- transform_iterator const& t -- , typename enable_if_convertible::type* = 0 // exposition -+ transform_iterator const& t -+ , typename enable_if_convertible::type* = 0 // exposition only -+ , typename enable_if_convertible::type* = 0 // exposition only - ); -- - -Issues 9.37x and 9.12 - -+ Iterator const& base() const; -+ reference operator*() const; -+ transform_iterator& operator++(); -+ transform_iterator& operator--(); - private: -- typename transform_iterator::value_type dereference() const; -- UnaryFunction m_f; -+ Iterator m_iterator; // exposition only -+ UnaryFunction m_f; // exposition only - }; - - -Issue 9.41x - -+If ``Reference`` is ``use_default`` then the ``reference`` member of -+``transform_iterator`` is -+``result_of::reference)>::type``. -+Otherwise, ``reference`` is ``Reference``. -+ -+If ``Value`` is ``use_default`` then the ``value_type`` member is -+``remove_cv >::type``. Otherwise, -+``value_type`` is ``Value``. -+ -+ - -Issue 9.37x - -+If ``Iterator`` models Readable Lvalue Iterator and if ``Iterator`` -+models Random Access Traversal Iterator, then ``iterator_category`` is -+convertible to ``random_access_iterator_tag``. Otherwise, if -+``Iterator`` models Bidirectional Traversal Iterator, then -+``iterator_category`` is convertible to -+``bidirectional_iterator_tag``. Otherwise ``iterator_category`` is -+convertible to ``forward_iterator_tag``. If ``Iterator`` does not -+model Readable Lvalue Iterator then ``iterator_category`` is -+convertible to ``input_iterator_tag``. -+ -+ - ``transform_iterator`` requirements - ................................... - -@@ -34,27 +65,55 @@ - where the type of ``f(*i)`` must be - ``result_of::reference)>::type``. - - -Issue 9.37x - --The type ``Iterator`` must at least model Readable Iterator. The --resulting ``transform_iterator`` models the most refined of the -+The argument ``Iterator`` shall model Readable Iterator. -+ -+ -+``transform_iterator`` models -+............................. -+ -+The resulting ``transform_iterator`` models the most refined of the - following options that is also modeled by ``Iterator``. - -- * Writable Lvalue Iterator if ``result_of::reference)>::type`` is a non-const reference. -+ * Writable Lvalue Iterator if ``transform_iterator::reference`` is a non-const reference. - -- * Readable Lvalue Iterator if ``result_of::reference)>::type`` is a const -- reference. -+ * Readable Lvalue Iterator if ``transform_iterator::reference`` is a const reference. - - * Readable Iterator otherwise. - -- - The ``transform_iterator`` models the most refined standard traversal --concept that is modeled by ``Iterator``. -+concept that is modeled by the ``Iterator`` argument. - -Issue 9.41x - --The ``reference`` type of ``transform_iterator`` is --``result_of::reference)>::type``. --The ``value_type`` is ``remove_cv >::type``. - -Issue 9.37x. - -+If ``transform_iterator`` is a model of Readable Lvalue Iterator then -+it models the following original iterator concepts depending on what -+the ``Iterator`` argument models. - --``transform_iterator`` public operations --........................................ -++-----------------------------------+---------------------------------+ -+| If ``Iterator`` models | then ``filter_iterator`` models | -++===================================+=================================+ -+| Single Pass Iterator | Input Iterator | -++-----------------------------------+---------------------------------+ -+| Forward Traversal Iterator | Forward Iterator | -++-----------------------------------+---------------------------------+ -+| Bidirectional Traversal Iterator | Bidirectional Iterator | -++-----------------------------------+---------------------------------+ -+| Random Access Traversal Iterator | Random Access Iterator | -++-----------------------------------+---------------------------------+ -+ -+If ``transform_iterator`` models Writable Lvalue Iterator then it is a -+mutable iterator (as defined in the old iterator requirements). -+ -+``transform_iterator`` is interoperable with -+``transform_iterator`` if and only if ``X`` is -+interoperable with ``Y``. -+ -+ -+ -+``transform_iterator`` operations -+................................. -+ -+In addition to the operations required by the concepts modeled by -+``transform_iterator``, ``transform_iterator`` provides the following -+operations. - - - ``transform_iterator();`` -@@ -80,14 +139,30 @@ - :Returns: An instance of ``transform_iterator`` that is a copy of ``t``. - :Requires: ``OtherIterator`` is implicitly convertible to ``Iterator``. - -+ -+``Iterator const& base() const;`` -+ -+:Returns: ``m_iterator`` -+ -+ - ``UnaryFunction functor() const;`` - - :Returns: ``m_f`` - --``transform_iterator`` private operations --......................................... - --``typename transform_iterator::value_type dereference() const;`` -+``reference operator*() const;`` - --:Returns: ``m_f(transform_iterator::dereference());`` -+:Returns: ``m_f(*m_iterator)`` -+ -+ -+``transform_iterator& operator++();`` -+ -+:Effects: ``++m_iterator`` -+:Returns: ``*this`` -+ -+ -+``transform_iterator& operator--();`` -+ -+:Effects: ``--m_iterator`` -+:Returns: ``*this`` - diff --git a/doc/transform_iterator_ref.rst b/doc/transform_iterator_ref.rst deleted file mode 100644 index 2e31a20..0000000 --- a/doc/transform_iterator_ref.rst +++ /dev/null @@ -1,168 +0,0 @@ -.. Version 1.3 of this document was accepted for TR1 - -:: - - template - class transform_iterator - { - public: - typedef /* see below */ value_type; - typedef /* see below */ reference; - typedef /* see below */ pointer; - typedef iterator_traits::difference_type difference_type; - typedef /* see below */ iterator_category; - - transform_iterator(); - transform_iterator(Iterator const& x, UnaryFunction f); - - template - transform_iterator( - transform_iterator const& t - , typename enable_if_convertible::type* = 0 // exposition only - , typename enable_if_convertible::type* = 0 // exposition only - ); - UnaryFunction functor() const; - Iterator const& base() const; - reference operator*() const; - transform_iterator& operator++(); - transform_iterator& operator--(); - private: - Iterator m_iterator; // exposition only - UnaryFunction m_f; // exposition only - }; - - -If ``Reference`` is ``use_default`` then the ``reference`` member of -``transform_iterator`` is -``result_of::reference)>::type``. -Otherwise, ``reference`` is ``Reference``. - -If ``Value`` is ``use_default`` then the ``value_type`` member is -``remove_cv >::type``. Otherwise, -``value_type`` is ``Value``. - - -If ``Iterator`` models Readable Lvalue Iterator and if ``Iterator`` -models Random Access Traversal Iterator, then ``iterator_category`` is -convertible to ``random_access_iterator_tag``. Otherwise, if -``Iterator`` models Bidirectional Traversal Iterator, then -``iterator_category`` is convertible to -``bidirectional_iterator_tag``. Otherwise ``iterator_category`` is -convertible to ``forward_iterator_tag``. If ``Iterator`` does not -model Readable Lvalue Iterator then ``iterator_category`` is -convertible to ``input_iterator_tag``. - - -``transform_iterator`` requirements -................................... - -The type ``UnaryFunction`` must be Assignable, Copy Constructible, and -the expression ``f(*i)`` must be valid where ``f`` is an object of -type ``UnaryFunction``, ``i`` is an object of type ``Iterator``, and -where the type of ``f(*i)`` must be -``result_of::reference)>::type``. - -The argument ``Iterator`` shall model Readable Iterator. - - -``transform_iterator`` models -............................. - -The resulting ``transform_iterator`` models the most refined of the -following that is also modeled by ``Iterator``. - - * Writable Lvalue Iterator if ``transform_iterator::reference`` is a non-const reference. - - * Readable Lvalue Iterator if ``transform_iterator::reference`` is a const reference. - - * Readable Iterator otherwise. - -The ``transform_iterator`` models the most refined standard traversal -concept that is modeled by the ``Iterator`` argument. - -If ``transform_iterator`` is a model of Readable Lvalue Iterator then -it models the following original iterator concepts depending on what -the ``Iterator`` argument models. - -+-----------------------------------+---------------------------------------+ -| If ``Iterator`` models | then ``transform_iterator`` models | -+===================================+=======================================+ -| Single Pass Iterator | Input Iterator | -+-----------------------------------+---------------------------------------+ -| Forward Traversal Iterator | Forward Iterator | -+-----------------------------------+---------------------------------------+ -| Bidirectional Traversal Iterator | Bidirectional Iterator | -+-----------------------------------+---------------------------------------+ -| Random Access Traversal Iterator | Random Access Iterator | -+-----------------------------------+---------------------------------------+ - -If ``transform_iterator`` models Writable Lvalue Iterator then it is a -mutable iterator (as defined in the old iterator requirements). - -``transform_iterator`` is interoperable with -``transform_iterator`` if and only if ``X`` is -interoperable with ``Y``. - - - -``transform_iterator`` operations -................................. - -In addition to the operations required by the concepts modeled by -``transform_iterator``, ``transform_iterator`` provides the following -operations. - - -``transform_iterator();`` - -:Returns: An instance of ``transform_iterator`` with ``m_f`` - and ``m_iterator`` default constructed. - - -``transform_iterator(Iterator const& x, UnaryFunction f);`` - -:Returns: An instance of ``transform_iterator`` with ``m_f`` - initialized to ``f`` and ``m_iterator`` initialized to ``x``. - - -:: - - template - transform_iterator( - transform_iterator const& t - , typename enable_if_convertible::type* = 0 // exposition - ); - -:Returns: An instance of ``transform_iterator`` that is a copy of ``t``. -:Requires: ``OtherIterator`` is implicitly convertible to ``Iterator``. - - -``UnaryFunction functor() const;`` - -:Returns: ``m_f`` - - -``Iterator const& base() const;`` - -:Returns: ``m_iterator`` - - -``reference operator*() const;`` - -:Returns: ``m_f(*m_iterator)`` - - -``transform_iterator& operator++();`` - -:Effects: ``++m_iterator`` -:Returns: ``*this`` - - -``transform_iterator& operator--();`` - -:Effects: ``--m_iterator`` -:Returns: ``*this`` - diff --git a/doc/traversal.png b/doc/traversal.png deleted file mode 100644 index a9bbe98..0000000 Binary files a/doc/traversal.png and /dev/null differ diff --git a/example/Jamfile b/example/Jamfile deleted file mode 100644 index cb49f1a..0000000 --- a/example/Jamfile +++ /dev/null @@ -1,20 +0,0 @@ -subproject libs/iterator/example ; - -import testing ; - -# Make tests run by default. -DEPENDS all : test ; - -test-suite iterator_examples - : [ run reverse_iterator.cpp ] - [ run node_iterator1.cpp ] - [ run node_iterator2.cpp ] - [ run node_iterator3.cpp ] - [ run counting_iterator_example.cpp ] - [ run filter_iterator_example.cpp ] - [ run function_output_iterator_example.cpp ] - [ run indirect_iterator_example.cpp ] - [ run permutation_iterator_example.cpp ] - [ run reverse_iterator_example.cpp ] - [ run transform_iterator_example.cpp ] - ; diff --git a/example/counting_iterator_example.cpp b/example/counting_iterator_example.cpp deleted file mode 100644 index 4113075..0000000 --- a/example/counting_iterator_example.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// (C) Copyright Jeremy Siek 2000-2004. -// 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 -#include -#include -#include -#include -#include -#include -#include - -int main(int, char*[]) -{ - // Example of using counting_iterator - std::cout << "counting from 0 to 4:" << std::endl; - boost::counting_iterator first(0), last(4); - std::copy(first, last, std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - // Example of using counting iterator to create an array of pointers. - int N = 7; - std::vector numbers; - typedef std::vector::iterator n_iter; - // Fill "numbers" array with [0,N) - std::copy( - boost::counting_iterator(0) - , boost::counting_iterator(N) - , std::back_inserter(numbers)); - - std::vector::iterator> pointers; - - // Use counting iterator to fill in the array of pointers. - // causes an ICE with MSVC6 - std::copy(boost::make_counting_iterator(numbers.begin()), - boost::make_counting_iterator(numbers.end()), - std::back_inserter(pointers)); - - // Use indirect iterator to print out numbers by accessing - // them through the array of pointers. - std::cout << "indirectly printing out the numbers from 0 to " - << N << std::endl; - std::copy(boost::make_indirect_iterator(pointers.begin()), - boost::make_indirect_iterator(pointers.end()), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - return boost::exit_success; -} diff --git a/example/filter_iterator_example.cpp b/example/filter_iterator_example.cpp deleted file mode 100644 index 5748daa..0000000 --- a/example/filter_iterator_example.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// (C) Copyright Jeremy Siek 1999-2004. -// 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 -#include -#include -#include -#include -#include // for exit_success - -struct is_positive_number { - bool operator()(int x) { return 0 < x; } -}; - -int main() -{ - int numbers_[] = { 0, -1, 4, -3, 5, 8, -2 }; - const int N = sizeof(numbers_)/sizeof(int); - - typedef int* base_iterator; - base_iterator numbers(numbers_); - - // Example using make_filter_iterator() - std::copy(boost::make_filter_iterator(numbers, numbers + N), - boost::make_filter_iterator(numbers + N, numbers + N), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - // Example using filter_iterator - typedef boost::filter_iterator - FilterIter; - - is_positive_number predicate; - FilterIter filter_iter_first(predicate, numbers, numbers + N); - FilterIter filter_iter_last(predicate, numbers + N, numbers + N); - - std::copy(filter_iter_first, filter_iter_last, std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - // Another example using make_filter_iterator() - std::copy( - boost::make_filter_iterator( - std::bind2nd(std::greater(), -2) - , numbers, numbers + N) - - , boost::make_filter_iterator( - std::bind2nd(std::greater(), -2) - , numbers + N, numbers + N) - - , std::ostream_iterator(std::cout, " ") - ); - - std::cout << std::endl; - - return boost::exit_success; -} diff --git a/example/function_output_iterator_example.cpp b/example/function_output_iterator_example.cpp deleted file mode 100644 index de0feae..0000000 --- a/example/function_output_iterator_example.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// (C) Copyright Jeremy Siek 2001-2004. -// 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. - -#include -#include -#include - -#include - -struct string_appender -{ - string_appender(std::string& s) - : m_str(&s) - {} - - void operator()(const std::string& x) const - { - *m_str += x; - } - - std::string* m_str; -}; - -int main(int, char*[]) -{ - std::vector x; - x.push_back("hello"); - x.push_back(" "); - x.push_back("world"); - x.push_back("!"); - - std::string s = ""; - std::copy(x.begin(), x.end(), - boost::make_function_output_iterator(string_appender(s))); - - std::cout << s << std::endl; - - return 0; -} diff --git a/example/indirect_iterator_example.cpp b/example/indirect_iterator_example.cpp deleted file mode 100644 index 7d74072..0000000 --- a/example/indirect_iterator_example.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// (C) Copyright Jeremy Siek 2000-2004. -// 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 -#include -#include -#include -#include -#include -#include - -int main(int, char*[]) -{ - char characters[] = "abcdefg"; - const int N = sizeof(characters)/sizeof(char) - 1; // -1 since characters has a null char - char* pointers_to_chars[N]; // at the end. - for (int i = 0; i < N; ++i) - pointers_to_chars[i] = &characters[i]; - - // Example of using indirect_iterator - - boost::indirect_iterator - indirect_first(pointers_to_chars), indirect_last(pointers_to_chars + N); - - std::copy(indirect_first, indirect_last, std::ostream_iterator(std::cout, ",")); - std::cout << std::endl; - - - // Example of making mutable and constant indirect iterators - - char mutable_characters[N]; - char* pointers_to_mutable_chars[N]; - for (int j = 0; j < N; ++j) - pointers_to_mutable_chars[j] = &mutable_characters[j]; - - boost::indirect_iterator mutable_indirect_first(pointers_to_mutable_chars), - mutable_indirect_last(pointers_to_mutable_chars + N); - boost::indirect_iterator const_indirect_first(pointers_to_chars), - const_indirect_last(pointers_to_chars + N); - - std::transform(const_indirect_first, const_indirect_last, - mutable_indirect_first, std::bind1st(std::plus(), 1)); - - std::copy(mutable_indirect_first, mutable_indirect_last, - std::ostream_iterator(std::cout, ",")); - std::cout << std::endl; - - - // Example of using make_indirect_iterator() - - std::copy(boost::make_indirect_iterator(pointers_to_chars), - boost::make_indirect_iterator(pointers_to_chars + N), - std::ostream_iterator(std::cout, ",")); - std::cout << std::endl; - - return 0; -} diff --git a/example/node.hpp b/example/node.hpp deleted file mode 100755 index 4e80d96..0000000 --- a/example/node.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// 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 NODE_DWA2004110_HPP -# define NODE_DWA2004110_HPP - -# include - -// Polymorphic list node base class - -struct node_base -{ - node_base() : m_next(0) {} - - virtual ~node_base() - { - delete m_next; - } - - node_base* next() const - { - return m_next; - } - - virtual void print(std::ostream& s) const = 0; - virtual void double_me() = 0; - - void append(node_base* p) - { - if (m_next) - m_next->append(p); - else - m_next = p; - } - - private: - node_base* m_next; -}; - -inline std::ostream& operator<<(std::ostream& s, node_base const& n) -{ - n.print(s); - return s; -} - -template -struct node : node_base -{ - node(T x) - : m_value(x) - {} - - void print(std::ostream& s) const { s << this->m_value; } - void double_me() { m_value += m_value; } - - private: - T m_value; -}; - -#endif // NODE_DWA2004110_HPP diff --git a/example/node_iterator1.cpp b/example/node_iterator1.cpp deleted file mode 100755 index 6411b03..0000000 --- a/example/node_iterator1.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// 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) - -#include "node_iterator1.hpp" -#include -#include -#include -#include -#include - -int main() -{ - std::auto_ptr > nodes(new node(42)); - nodes->append(new node(" is greater than ")); - nodes->append(new node(13)); - - std::copy( - node_iterator(nodes.get()), node_iterator() - , std::ostream_iterator(std::cout, " ") - ); - std::cout << std::endl; - - std::for_each( - node_iterator(nodes.get()), node_iterator() - , std::mem_fun_ref(&node_base::double_me) - ); - - std::copy( - node_iterator(nodes.get()), node_iterator() - , std::ostream_iterator(std::cout, "/") - ); - std::cout << std::endl; -} diff --git a/example/node_iterator1.hpp b/example/node_iterator1.hpp deleted file mode 100755 index 1188c7c..0000000 --- a/example/node_iterator1.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// 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 NODE_ITERATOR1_DWA2004110_HPP -# define NODE_ITERATOR1_DWA2004110_HPP - -# include "node.hpp" -# include - -class node_iterator - : public boost::iterator_facade< - node_iterator - , node_base - , boost::forward_traversal_tag - > -{ - public: - node_iterator() - : m_node(0) - {} - - explicit node_iterator(node_base* p) - : m_node(p) - {} - - private: - friend class boost::iterator_core_access; - - void increment() - { m_node = m_node->next(); } - - bool equal(node_iterator const& other) const - { return this->m_node == other.m_node; } - - node_base& dereference() const - { return *m_node; } - - node_base* m_node; -}; - - -#endif // NODE_ITERATOR1_DWA2004110_HPP diff --git a/example/node_iterator2.cpp b/example/node_iterator2.cpp deleted file mode 100755 index 62211b2..0000000 --- a/example/node_iterator2.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// 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) - -#include "node_iterator2.hpp" -#include -#include -#include -#include -#include -#include - -int main() -{ - std::auto_ptr > nodes(new node(42)); - nodes->append(new node(" is greater than ")); - nodes->append(new node(13)); - - // Check interoperability - assert(node_iterator(nodes.get()) == node_const_iterator(nodes.get())); - assert(node_const_iterator(nodes.get()) == node_iterator(nodes.get())); - - assert(node_iterator(nodes.get()) != node_const_iterator()); - assert(node_const_iterator(nodes.get()) != node_iterator()); - - std::copy( - node_iterator(nodes.get()), node_iterator() - , std::ostream_iterator(std::cout, " ") - ); - std::cout << std::endl; - - std::for_each( - node_iterator(nodes.get()), node_iterator() - , boost::mem_fn(&node_base::double_me) - ); - - std::copy( - node_const_iterator(nodes.get()), node_const_iterator() - , std::ostream_iterator(std::cout, "/") - ); - std::cout << std::endl; - return 0; -} diff --git a/example/node_iterator2.hpp b/example/node_iterator2.hpp deleted file mode 100755 index 15b40aa..0000000 --- a/example/node_iterator2.hpp +++ /dev/null @@ -1,73 +0,0 @@ -// 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 NODE_ITERATOR2_DWA2004110_HPP -# define NODE_ITERATOR2_DWA2004110_HPP - -# include "node.hpp" -# include - -# ifndef BOOST_NO_SFINAE -# include -# include -# endif - -template -class node_iter - : public boost::iterator_facade< - node_iter - , Value - , boost::forward_traversal_tag - > -{ - private: - struct enabler {}; // a private type avoids misuse - - public: - node_iter() - : m_node(0) {} - - explicit node_iter(Value* p) - : m_node(p) {} - - template - node_iter( - node_iter const& other -# ifndef BOOST_NO_SFINAE - , typename boost::enable_if< - boost::is_convertible - , enabler - >::type = enabler() -# endif - ) - : m_node(other.m_node) {} - - -# if !BOOST_WORKAROUND(__GNUC__, == 2) - private: // GCC2 can't even grant that friendship to template member functions -# endif - friend class boost::iterator_core_access; - - template - bool equal(node_iter const& other) const - { - return this->m_node == other.m_node; - } - - private: - void increment() { m_node = m_node->next(); } - - Value& dereference() const { return *m_node; } - -# ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS - public: -# else - template friend class node_iter; -# endif - Value* m_node; -}; - -typedef node_iter node_iterator; -typedef node_iter node_const_iterator; - -#endif // NODE_ITERATOR2_DWA2004110_HPP diff --git a/example/node_iterator3.cpp b/example/node_iterator3.cpp deleted file mode 100755 index 331cc93..0000000 --- a/example/node_iterator3.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// 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) - -#include "node_iterator3.hpp" -#include -#include -#include -#include -#include -#include - -int main() -{ - std::auto_ptr > nodes(new node(42)); - nodes->append(new node(" is greater than ")); - nodes->append(new node(13)); - - // Check interoperability - assert(node_iterator(nodes.get()) == node_const_iterator(nodes.get())); - assert(node_const_iterator(nodes.get()) == node_iterator(nodes.get())); - - assert(node_iterator(nodes.get()) != node_const_iterator()); - assert(node_const_iterator(nodes.get()) != node_iterator()); - - std::copy( - node_iterator(nodes.get()), node_iterator() - , std::ostream_iterator(std::cout, " ") - ); - std::cout << std::endl; - - std::for_each( - node_iterator(nodes.get()), node_iterator() - , boost::mem_fn(&node_base::double_me) - ); - - std::copy( - node_const_iterator(nodes.get()), node_const_iterator() - , std::ostream_iterator(std::cout, "/") - ); - std::cout << std::endl; - return 0; -} diff --git a/example/node_iterator3.hpp b/example/node_iterator3.hpp deleted file mode 100755 index 12e7652..0000000 --- a/example/node_iterator3.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// 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 NODE_ITERATOR3_DWA2004110_HPP -# define NODE_ITERATOR3_DWA2004110_HPP - -# include "node.hpp" -# include - -# ifndef BOOST_NO_SFINAE -# include -# include -# endif - -template -class node_iter - : public boost::iterator_adaptor< - node_iter // Derived - , Value* // Base - , boost::use_default // Value - , boost::forward_traversal_tag // CategoryOrTraversal - > -{ - private: - struct enabler {}; // a private type avoids misuse - - typedef boost::iterator_adaptor< - node_iter, Value*, boost::use_default, boost::forward_traversal_tag - > super_t; - - public: - node_iter() - : super_t(0) {} - - explicit node_iter(Value* p) - : super_t(p) {} - - template - node_iter( - node_iter const& other -# ifndef BOOST_NO_SFINAE - , typename boost::enable_if< - boost::is_convertible - , enabler - >::type = enabler() -# endif - ) - : super_t(other.base()) {} - - private: - friend class boost::iterator_core_access; - void increment() { this->base_reference() = this->base()->next(); } -}; - -typedef node_iter node_iterator; -typedef node_iter node_const_iterator; - -#endif // NODE_ITERATOR3_DWA2004110_HPP diff --git a/example/permutation_iterator_example.cpp b/example/permutation_iterator_example.cpp deleted file mode 100644 index 195f39d..0000000 --- a/example/permutation_iterator_example.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include -#include -#include -#include - - -int main() { - using namespace boost; - int i = 0; - - typedef std::vector< int > element_range_type; - typedef std::list< int > index_type; - - static const int element_range_size = 10; - static const int index_size = 4; - - 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 permutation_iterator< element_range_type::iterator, index_type::iterator > permutation_type; - permutation_type begin = make_permutation_iterator( elements.begin(), indices.begin() ); - permutation_type it = begin; - permutation_type end = make_permutation_iterator( elements.begin(), indices.end() ); - - std::cout << "The original range is : "; - std::copy( elements.begin(), elements.end(), std::ostream_iterator< int >( std::cout, " " ) ); - std::cout << "\n"; - - std::cout << "The reindexing scheme is : "; - std::copy( indices.begin(), indices.end(), std::ostream_iterator< int >( std::cout, " " ) ); - std::cout << "\n"; - - std::cout << "The permutated range is : "; - std::copy( begin, end, std::ostream_iterator< int >( std::cout, " " ) ); - std::cout << "\n"; - - std::cout << "Elements at even indices in the permutation : "; - it = begin; - for(i = 0; i < index_size / 2 ; ++i, it+=2 ) std::cout << *it << " "; - std::cout << "\n"; - - std::cout << "Permutation backwards : "; - it = begin + (index_size); - assert( it != begin ); - for( ; it-- != begin ; ) std::cout << *it << " "; - std::cout << "\n"; - - std::cout << "Iterate backward with stride 2 : "; - it = begin + (index_size - 1); - for(i = 0 ; i < index_size / 2 ; ++i, it-=2 ) std::cout << *it << " "; - std::cout << "\n"; - - return boost::exit_success; -} diff --git a/example/reverse_iterator.cpp b/example/reverse_iterator.cpp deleted file mode 100644 index 522cb9f..0000000 --- a/example/reverse_iterator.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include -#include -#include - -int main() -{ - int x[] = { 1, 2, 3, 4 }; - boost::reverse_iterator first(x + 4), last(x); - std::copy(first, last, std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - return 0; -} diff --git a/example/reverse_iterator_example.cpp b/example/reverse_iterator_example.cpp deleted file mode 100644 index 34c14a8..0000000 --- a/example/reverse_iterator_example.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// (C) Copyright Jeremy Siek 2000-2004. -// 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 -#include -#include -#include -#include - -int main(int, char*[]) -{ - char letters_[] = "hello world!"; - const int N = sizeof(letters_)/sizeof(char) - 1; - typedef char* base_iterator; - base_iterator letters(letters_); - - std::cout << "original sequence of letters:\t\t\t" - << letters_ << std::endl; - - // Use reverse_iterator to print a sequence of letters in reverse - // order. - - boost::reverse_iterator - reverse_letters_first(letters + N), - reverse_letters_last(letters); - - std::cout << "sequence in reverse order:\t\t\t"; - std::copy(reverse_letters_first, reverse_letters_last, - std::ostream_iterator(std::cout)); - std::cout << std::endl; - - std::cout << "sequence in double-reversed (normal) order:\t"; - std::copy(boost::make_reverse_iterator(reverse_letters_last), - boost::make_reverse_iterator(reverse_letters_first), - std::ostream_iterator(std::cout)); - std::cout << std::endl; - - return boost::exit_success; -} diff --git a/example/transform_iterator_example.cpp b/example/transform_iterator_example.cpp deleted file mode 100644 index 4733997..0000000 --- a/example/transform_iterator_example.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// (C) Copyright Jeremy Siek 2000-2004. -// 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 -#include -#include -#include - -// What a bummer. We can't use std::binder1st with transform iterator -// because it does not have a default constructor. Here's a version -// that does. - -namespace boost { - - template - class binder1st - : public std::unary_function { - protected: - Operation op; - typename Operation::first_argument_type value; - public: - binder1st() { } // this had to be added! - binder1st(const Operation& x, - const typename Operation::first_argument_type& y) - : op(x), value(y) {} - typename Operation::result_type - operator()(const typename Operation::second_argument_type& x) const { - return op(value, x); - } - }; - - template - inline binder1st bind1st(const Operation& op, const T& x) { - typedef typename Operation::first_argument_type arg1_type; - return binder1st(op, arg1_type(x)); - } - -} // namespace boost - -int -main(int, char*[]) -{ - // This is a simple example of using the transform_iterators class to - // generate iterators that multiply the value returned by dereferencing - // the iterator. In this case we are multiplying by 2. - // Would be cooler to use lambda library in this example. - - int x[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; - const int N = sizeof(x)/sizeof(int); - - typedef boost::binder1st< std::multiplies > Function; - typedef boost::transform_iterator doubling_iterator; - - doubling_iterator i(x, boost::bind1st(std::multiplies(), 2)), - i_end(x + N, boost::bind1st(std::multiplies(), 2)); - - std::cout << "multiplying the array by 2:" << std::endl; - while (i != i_end) - std::cout << *i++ << " "; - std::cout << std::endl; - - std::cout << "adding 4 to each element in the array:" << std::endl; - - std::copy(boost::make_transform_iterator(x, boost::bind1st(std::plus(), 4)), - boost::make_transform_iterator(x + N, boost::bind1st(std::plus(), 4)), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - return 0; -} - - diff --git a/include/boost/function_output_iterator.hpp b/include/boost/function_output_iterator.hpp deleted file mode 100644 index 764c118..0000000 --- a/include/boost/function_output_iterator.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// (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 - -namespace boost { - - template - 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 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 - inline function_output_iterator - make_function_output_iterator(const UnaryFunction& f = UnaryFunction()) { - return function_output_iterator(f); - } - -} // namespace boost - -#endif // BOOST_FUNCTION_OUTPUT_ITERATOR_HPP diff --git a/include/boost/half_open_range.hpp b/include/boost/half_open_range.hpp deleted file mode 100644 index c281846..0000000 --- a/include/boost/half_open_range.hpp +++ /dev/null @@ -1,426 +0,0 @@ -// (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 -# include -# include -# include -# include -# include -# include - -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 - const T& choose_finish(const T&, const T& finish, std::input_iterator_tag) - { - return finish; - } - - template - const T& choose_finish(const T&, const T& finish, std::output_iterator_tag) - { - return finish; - } - - template - const T& choose_finish(const T& start, const T& finish, std::random_access_iterator_tag) - { - return finish < start ? start : finish; - } -#else - template struct finish_chooser; - - template <> - struct finish_chooser - { - template - struct rebind - { - static T choose(const T&, const T& finish) - { return finish; } - }; - }; - - template <> - struct finish_chooser - { - template - struct rebind - { - static T choose(const T& start, const T& finish) - { return finish < start ? start : finish; } - }; - }; - - template - struct choose_finish - { - static const Incrementable choose(const Incrementable& start, const Incrementable& finish) - { - return finish_chooser<( - ::boost::is_convertible::value - )>::template rebind::choose(start, finish); - } - }; -#endif -} - -template -struct half_open_range -{ - typedef typename counting_iterator_generator::type iterator; - - private: // utility type definitions - // Using iter_t prevents compiler confusion with boost::iterator - typedef typename counting_iterator_generator::type iter_t; - - typedef std::less less_value; - typedef typename iter_t::iterator_category category; - typedef half_open_range 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::choose(start, finish) -#else - detail::choose_finish(start, finish, category()) -#endif - ) - {} - - // Implicit conversion from std::pair allows us - // to accept the results of std::equal_range(), for example. - half_open_range(const std::pair& x) - : m_start(x.first), - m_finish( -#ifndef __MWERKS__ - detail::choose_finish::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& x) - { - m_start = x.first; - m_finish = -#ifndef __MWERKS__ - detail::choose_finish::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::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::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::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::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::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::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 -half_open_range operator|( - half_open_range x, - const half_open_range& y) -{ - return x |= y; -} - -template -half_open_range operator&( - half_open_range x, - const half_open_range& y) -{ - return x &= y; -} - -template -inline bool operator==( - const half_open_range& x, - const half_open_range& y) -{ - const bool y_empty = y.empty(); - return x.empty() ? y_empty : !y_empty && x.start() == y.start() && x.finish() == y.finish(); -} - -template -inline bool operator!=( - const half_open_range& x, - const half_open_range& y) -{ - return !(x == y); -} - -template -inline half_open_range -make_half_open_range(Incrementable first, Incrementable last) -{ - return half_open_range(first, last); -} - -template -bool intersects( - const half_open_range& x, - const half_open_range& y) -{ - return x.intersects(y); -} - -template -bool contains( - const half_open_range& x, - const half_open_range& y) -{ - return x.contains(y); -} - -} // namespace boost - -#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - -namespace std { -template struct less > - : binary_function< - boost::half_open_range, - boost::half_open_range,bool> -{ - bool operator()( - const boost::half_open_range& x, - const boost::half_open_range& y) const - { - less cmp; - return !y.empty() && ( - cmp(x.start(), y.start()) - || !cmp(y.start(), x.start()) - && cmp(x.finish(), y.finish())); - } -}; - -template struct less_equal > - : binary_function< - boost::half_open_range, - boost::half_open_range,bool> -{ - bool operator()( - const boost::half_open_range& x, - const boost::half_open_range& y) const - { - typedef boost::half_open_range range; - less cmp; - return !cmp(y,x); - } -}; -template struct greater > - : binary_function< - boost::half_open_range, - boost::half_open_range,bool> -{ - bool operator()( - const boost::half_open_range& x, - const boost::half_open_range& y) const - { - typedef boost::half_open_range range; - less cmp; - return cmp(y,x); - } -}; - -template struct greater_equal > - : binary_function< - boost::half_open_range, - boost::half_open_range,bool> -{ - bool operator()( - const boost::half_open_range& x, - const boost::half_open_range& y) const - { - typedef boost::half_open_range range; - less 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 -bool operator<(const half_open_range& x, - const half_open_range& y) -{ - return !y.empty() && ( - x.empty() || std::less()(x.start(), y.start()) - || !std::less()(y.start(), x.start()) - && std::less()(x.finish(), y.finish())); -} - -template -bool operator>(const half_open_range& x, - const half_open_range& y) -{ - return y < x; -} - -template -bool operator<=(const half_open_range& x, - const half_open_range& y) -{ - return !(y < x); -} - -template -bool operator>=(const half_open_range& x, - const half_open_range& y) -{ - return !(x < y); -} -} // namespace boost - -#endif - - -#endif // BOOST_HALF_OPEN_RANGE_HPP_ diff --git a/include/boost/iterator.hpp b/include/boost/iterator.hpp deleted file mode 100644 index 8b82097..0000000 --- a/include/boost/iterator.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// 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 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 -#include // std::ptrdiff_t -#include - -namespace boost -{ -# if defined(BOOST_NO_STD_ITERATOR) && !defined(BOOST_MSVC_STD_ITERATOR) - template - 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 -# if !defined(BOOST_MSVC_STD_ITERATOR) - struct iterator_base : std::iterator {}; -# else - struct iterator_base : std::iterator - { - typedef Reference reference; - typedef Pointer pointer; - typedef Distance difference_type; - }; -# endif - } - - template - struct iterator : detail::iterator_base {}; -# endif -} // namespace boost - -#endif // BOOST_ITERATOR_HPP diff --git a/include/boost/iterator/counting_iterator.hpp b/include/boost/iterator/counting_iterator.hpp deleted file mode 100644 index 0a55967..0000000 --- a/include/boost/iterator/counting_iterator.hpp +++ /dev/null @@ -1,216 +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 COUNTING_ITERATOR_DWA200348_HPP -# define COUNTING_ITERATOR_DWA200348_HPP - -# include -# include -# include -# include -# include -# include - -namespace boost { - -template < - class Incrementable - , class CategoryOrTraversal - , class Difference -> -class counting_iterator; - -namespace detail -{ - // Try to detect numeric types at compile time in ways compatible - // with the limitations of the compiler and library. - template - struct is_numeric_impl - { - // For a while, this wasn't true, but we rely on it below. This is a regression assert. - BOOST_STATIC_ASSERT(::boost::is_integral::value); - -# ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS - - BOOST_STATIC_CONSTANT(bool, value = std::numeric_limits::is_specialized); - -# else - -# if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) - BOOST_STATIC_CONSTANT( - bool, value = ( - boost::is_convertible::value - && boost::is_convertible::value - )); -# else - BOOST_STATIC_CONSTANT(bool, value = ::boost::is_arithmetic::value); -# endif - -# endif - }; - - template - struct is_numeric - : mpl::bool_<(::boost::detail::is_numeric_impl::value)> - {}; - -# if defined(BOOST_HAS_LONG_LONG) - template <> - struct is_numeric - : mpl::true_ {}; - - template <> - struct is_numeric - : mpl::true_ {}; -# endif - - // Some compilers fail to have a numeric_limits specialization - template <> - struct is_numeric - : mpl::true_ {}; - - template - struct numeric_difference - { - typedef typename boost::detail::numeric_traits::difference_type type; - }; - - BOOST_STATIC_ASSERT(is_numeric::value); - - template - struct counting_iterator_base - { - typedef typename detail::ia_dflt_help< - CategoryOrTraversal - , mpl::apply_if< - is_numeric - , mpl::identity - , iterator_traversal - > - >::type traversal; - - typedef typename detail::ia_dflt_help< - Difference - , mpl::apply_if< - is_numeric - , numeric_difference - , iterator_difference - > - >::type difference; - - typedef iterator_adaptor< - counting_iterator // self - , Incrementable // Base - , Incrementable // Value -# ifndef BOOST_ITERATOR_REF_CONSTNESS_KILLS_WRITABILITY - const // MSVC won't strip this. Instead we enable Thomas' - // criterion (see boost/iterator/detail/facade_iterator_category.hpp) -# endif - , traversal - , Incrementable const& // reference - , difference - > type; - }; - - // Template class distance_policy_select -- choose a policy for computing the - // distance between counting_iterators at compile-time based on whether or not - // the iterator wraps an integer or an iterator, using "poor man's partial - // specialization". - - template struct distance_policy_select; - - // A policy for wrapped iterators - template - struct iterator_distance - { - static Difference distance(Incrementable1 x, Incrementable2 y) - { - return boost::detail::distance(x, y); - } - }; - - // A policy for wrapped numbers - template - struct number_distance - { - static Difference distance(Incrementable1 x, Incrementable2 y) - { - return numeric_distance(x, y); - } - }; -} - -template < - class Incrementable - , class CategoryOrTraversal = use_default - , class Difference = use_default -> -class counting_iterator - : public detail::counting_iterator_base< - Incrementable, CategoryOrTraversal, Difference - >::type -{ - typedef typename detail::counting_iterator_base< - Incrementable, CategoryOrTraversal, Difference - >::type super_t; - - friend class iterator_core_access; - - public: - typedef typename super_t::difference_type difference_type; - - counting_iterator() { } - - counting_iterator(counting_iterator const& rhs) : super_t(rhs.base()) {} - - counting_iterator(Incrementable x) - : super_t(x) - { - } - -# if 0 - template - counting_iterator( - counting_iterator const& t - , typename enable_if_convertible::type* = 0 - ) - : super_t(t.base()) - {} -# endif - - private: - - typename super_t::reference dereference() const - { - return this->base_reference(); - } - - template - difference_type - distance_to(counting_iterator const& y) const - { - typedef typename mpl::if_< - detail::is_numeric - , detail::number_distance - , detail::iterator_distance - >::type d; - - return d::distance(this->base(), y.base()); - } -}; - -// Manufacture a counting iterator for an arbitrary incrementable type -template -inline counting_iterator -make_counting_iterator(Incrementable x) -{ - typedef counting_iterator result_t; - return result_t(x); -} - - -} // namespace boost::iterator - -#endif // COUNTING_ITERATOR_DWA200348_HPP diff --git a/include/boost/iterator/detail/any_conversion_eater.hpp b/include/boost/iterator/detail/any_conversion_eater.hpp deleted file mode 100755 index 25fa644..0000000 --- a/include/boost/iterator/detail/any_conversion_eater.hpp +++ /dev/null @@ -1,19 +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) -#ifndef ANY_CONVERSION_EATER_DWA20031117_HPP -# define ANY_CONVERSION_EATER_DWA20031117_HPP - -namespace boost { namespace detail { - -// This type can be used in traits to "eat" up the one user-defined -// implicit conversion allowed. -struct any_conversion_eater -{ - template - any_conversion_eater(T const&); -}; - -}} // namespace boost::detail - -#endif // ANY_CONVERSION_EATER_DWA20031117_HPP diff --git a/include/boost/iterator/detail/categories.hpp b/include/boost/iterator/detail/categories.hpp deleted file mode 100644 index 841ac4c..0000000 --- a/include/boost/iterator/detail/categories.hpp +++ /dev/null @@ -1 +0,0 @@ -#error obsolete diff --git a/include/boost/iterator/detail/config_def.hpp b/include/boost/iterator/detail/config_def.hpp deleted file mode 100644 index 37cdf6d..0000000 --- a/include/boost/iterator/detail/config_def.hpp +++ /dev/null @@ -1,125 +0,0 @@ -// (C) Copyright David Abrahams 2002. -// (C) Copyright Jeremy Siek 2002. -// (C) Copyright Thomas Witt 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. - -// no include guard multiple inclusion intended - -// -// This is a temporary workaround until the bulk of this is -// available in boost config. -// 23/02/03 thw -// - -#include // for prior -#include - -#ifdef BOOST_ITERATOR_CONFIG_DEF -# error you have nested config_def #inclusion. -#else -# define BOOST_ITERATOR_CONFIG_DEF -#endif - -#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ - || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x531)) - -// Recall that in general, compilers without partial specialization -// can't strip constness. Consider counting_iterator, which normally -// passes a const Value to iterator_facade. As a result, any code -// which makes a std::vector of the iterator's value_type will fail -// when its allocator declares functions overloaded on reference and -// const_reference (the same type). -// -// Furthermore, Borland 5.5.1 drops constness in enough ways that we -// end up using a proxy for operator[] when we otherwise shouldn't. -// Using reference constness gives it an extra hint that it can -// return the value_type from operator[] directly, but is not -// strictly neccessary. Not sure how best to resolve this one. - -# define BOOST_ITERATOR_REF_CONSTNESS_KILLS_WRITABILITY 1 - -#endif - -#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) \ - || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x531)) \ - || (BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 700) && defined(_MSC_VER)) -# define BOOST_NO_LVALUE_RETURN_DETECTION - -# if 0 // test code - struct v {}; - - typedef char (&no)[3]; - - template - no foo(T const&, ...); - - template - char foo(T&, int); - - - struct value_iterator - { - v operator*() const; - }; - - template - struct lvalue_deref_helper - { - static T& x; - enum { value = (sizeof(foo(*x,0)) == 1) }; - }; - - int z2[(lvalue_deref_helper::value == 1) ? 1 : -1]; - int z[(lvalue_deref_helper::value) == 1 ? -1 : 1 ]; -# 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__, == 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 - template - struct foo - { - foo(T); - - template - foo(foo const& other) : p(other.p) { } - - T p; - }; - - bool x = boost::is_convertible, foo >::value; -# endif - -#endif - -#if BOOST_WORKAROUND(__GNUC__, == 2 && __GNUC_MINOR__ == 95) \ - || BOOST_WORKAROUND(__MWERKS__, <= 0x2407) \ - || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) -# define BOOST_ITERATOR_NO_MPL_AUX_HAS_XXX // "MPL's has_xxx facility doesn't work" -#endif - -#if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_IS_CONVERTIBLE) || defined(BOOST_NO_IS_CONVERTIBLE_TEMPLATE) -# define BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY -#endif - -# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) -# define BOOST_ARG_DEPENDENT_TYPENAME typename -# else -# define BOOST_ARG_DEPENDENT_TYPENAME -# endif - -// no include guard multiple inclusion intended diff --git a/include/boost/iterator/detail/config_undef.hpp b/include/boost/iterator/detail/config_undef.hpp deleted file mode 100644 index 535b486..0000000 --- a/include/boost/iterator/detail/config_undef.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// (C) Copyright Thomas Witt 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. - -// no include guard multiple inclusion intended - -// -// This is a temporary workaround until the bulk of this is -// available in boost config. -// 23/02/03 thw -// - -#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 - -#ifdef BOOST_ITERATOR_CONFIG_DEF -# undef BOOST_ITERATOR_CONFIG_DEF -#else -# error missing or nested #include config_def -#endif diff --git a/include/boost/iterator/detail/enable_if.hpp b/include/boost/iterator/detail/enable_if.hpp deleted file mode 100644 index f0a7bc7..0000000 --- a/include/boost/iterator/detail/enable_if.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// (C) Copyright David Abrahams 2002. -// (C) Copyright Jeremy Siek 2002. -// (C) Copyright Thomas Witt 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. -#ifndef BOOST_ENABLE_IF_23022003THW_HPP -#define BOOST_ENABLE_IF_23022003THW_HPP - -#include -#include - -#include - -// -// Boost iterators uses its own enable_if cause we need -// special semantics for deficient compilers. -// 23/02/03 thw -// - -namespace boost -{ - - namespace iterators - { - // - // Base machinery for all kinds of enable if - // - template - struct enabled - { - template - struct base - { - typedef T type; - }; - }; - - // - // For compilers that don't support "Substitution Failure Is Not An Error" - // enable_if falls back to always enabled. See comments - // on operator implementation for consequences. - // - template<> - struct enabled - { - template - struct base - { -#ifdef BOOST_NO_SFINAE - - typedef T type; - - // This way to do it would give a nice error message containing - // invalid overload, but has the big disadvantage that - // there is no reference to user code in the error message. - // - // struct invalid_overload; - // typedef invalid_overload type; - // -#endif - }; - }; - - - template - struct enable_if -# if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_IS_CONVERTIBLE) - : enabled<(Cond::value)>::template base -# else - : mpl::identity -# endif - { -# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) - typedef Return type; -# endif - }; - - } // namespace iterators - -} // namespace boost - -#include - -#endif // BOOST_ENABLE_IF_23022003THW_HPP diff --git a/include/boost/iterator/detail/facade_iterator_category.hpp b/include/boost/iterator/detail/facade_iterator_category.hpp deleted file mode 100755 index 5bee4b8..0000000 --- a/include/boost/iterator/detail/facade_iterator_category.hpp +++ /dev/null @@ -1,209 +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) -#ifndef FACADE_ITERATOR_CATEGORY_DWA20031118_HPP -# define FACADE_ITERATOR_CATEGORY_DWA20031118_HPP - -# include - -# include - -# include // used in iterator_tag inheritance logic -# include -# include -# include -# include - -# include -# include -# include -# include - -# include - -# include // try to keep this last - -# ifdef BOOST_ITERATOR_REF_CONSTNESS_KILLS_WRITABILITY -# include -# endif - -// -// iterator_category deduction for iterator_facade -// - -// forward declaration -namespace boost { struct use_default; } - -namespace boost { namespace detail { - -struct input_output_iterator_tag - : std::input_iterator_tag -{ - // Using inheritance for only input_iterator_tag helps to avoid - // ambiguities when a stdlib implementation dispatches on a - // function which is overloaded on both input_iterator_tag and - // output_iterator_tag, as STLPort does, in its __valid_range - // function. I claim it's better to avoid the ambiguity in these - // cases. - operator std::output_iterator_tag() const - { - return std::output_iterator_tag(); - } -}; - -// -// True iff the user has explicitly disabled writability of this -// iterator. Pass the iterator_facade's Value parameter and its -// nested ::reference type. -// -template -struct iterator_writability_disabled -# ifdef BOOST_ITERATOR_REF_CONSTNESS_KILLS_WRITABILITY // Adding Thomas' logic? - : mpl::or_< - is_const - , python::detail::is_reference_to_const - , is_const - > -# else - : is_const -# endif -{}; - - -// -// Convert an iterator_facade's traversal category, Value parameter, -// and ::reference type to an appropriate old-style category. -// -// If writability has been disabled per the above metafunction, the -// result will not be convertible to output_iterator_tag. -// -// Otherwise, if Traversal == single_pass_traversal_tag, the following -// conditions will result in a tag that is convertible both to -// input_iterator_tag and output_iterator_tag: -// -// 1. Reference is a reference to non-const -// 2. Reference is not a reference and is convertible to Value -// -template -struct iterator_facade_default_category - : mpl::apply_if< - mpl::and_< - is_reference - , is_convertible - > - , mpl::apply_if< - is_convertible - , mpl::identity - , mpl::if_< - is_convertible - , std::bidirectional_iterator_tag - , std::forward_iterator_tag - > - > - , typename mpl::apply_if< - mpl::and_< - is_convertible - - // check for readability - , is_convertible - > - , mpl::identity - , mpl::identity - > - > -{ -}; - -// True iff T is convertible to an old-style iterator category. -template -struct is_iterator_category - : mpl::or_< - is_convertible - , is_convertible - > -{ -}; - -template -struct is_iterator_traversal - : is_convertible -{}; - -// -// A composite iterator_category tag convertible to Category (a pure -// old-style category) and Traversal (a pure traversal tag). -// Traversal must be a strict increase of the traversal power given by -// Category. -// -template -struct iterator_category_with_traversal - : Category, Traversal -{ -# if 0 - // Because of limitations on multiple user-defined conversions, - // this should be a good test of whether convertibility is enough - // in the spec, or whether we need to specify inheritance. - operator Category() const { return Category(); } - operator Traversal() const { return Traversal(); } -# endif - -# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) - // Make sure this isn't used to build any categories where - // convertibility to Traversal is redundant. Should just use the - // Category element in that case. - BOOST_STATIC_ASSERT( - !(is_convertible< - typename iterator_category_to_traversal::type - , Traversal - >::value)); - - BOOST_STATIC_ASSERT(is_iterator_category::value); - BOOST_STATIC_ASSERT(!is_iterator_category::value); - BOOST_STATIC_ASSERT(!is_iterator_traversal::value); -# if !BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310)) - BOOST_STATIC_ASSERT(is_iterator_traversal::value); -# endif -# endif -}; - -// Computes an iterator_category tag whose traversal is Traversal and -// which is appropriate for an iterator -template -struct facade_iterator_category_impl -{ -# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) - BOOST_STATIC_ASSERT(!is_iterator_category::value); -# endif - - typedef typename iterator_facade_default_category< - Traversal,ValueParam,Reference - >::type category; - - typedef typename mpl::if_< - is_same< - Traversal - , typename iterator_category_to_traversal::type - > - , category - , iterator_category_with_traversal - >::type type; -}; - -// -// Compute an iterator_category for iterator_facade -// -template -struct facade_iterator_category - : mpl::apply_if< - is_iterator_category - , mpl::identity // old-style categories are fine as-is - , facade_iterator_category_impl - > -{ -}; - -}} // namespace boost::detail - -# include - -#endif // FACADE_ITERATOR_CATEGORY_DWA20031118_HPP diff --git a/include/boost/iterator/detail/minimum_category.hpp b/include/boost/iterator/detail/minimum_category.hpp deleted file mode 100755 index 89d79db..0000000 --- a/include/boost/iterator/detail/minimum_category.hpp +++ /dev/null @@ -1,110 +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) -#ifndef MINIMUM_CATEGORY_DWA20031119_HPP -# define MINIMUM_CATEGORY_DWA20031119_HPP - -# include -# include - -# include - -namespace boost { namespace detail { -// -// Returns the minimum category type or error_type -// if T1 and T2 are unrelated. -// -// For compilers not supporting is_convertible this only -// works with the new boost return and traversal category -// types. The exact boost _types_ are required. No derived types -// will work. -// -// -template -struct minimum_category_impl -# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) -{ - typedef void type; -} -# endif -; - -template -struct error_not_related_by_convertibility; - -template <> -struct minimum_category_impl -{ - template struct apply - { - typedef T2 type; - }; -}; - -template <> -struct minimum_category_impl -{ - template struct apply - { - typedef T1 type; - }; -}; - -template <> -struct minimum_category_impl -{ - template struct apply - { - BOOST_STATIC_ASSERT((is_same::value)); - typedef T1 type; - }; -}; - -template <> -struct minimum_category_impl -{ - template struct apply - : error_not_related_by_convertibility - { - }; -}; - -template -struct minimum_category -{ - typedef minimum_category_impl< -# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) // ETI workaround - is_same::value || -# endif - ::boost::is_convertible::value - , ::boost::is_convertible::value -# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) // ETI workaround - || is_same::value -# endif - > outer; - - typedef typename outer::template apply inner; - typedef typename inner::type type; - - BOOST_MPL_AUX_LAMBDA_SUPPORT(2,minimum_category,(T1,T2)) -}; - -template <> -struct minimum_category -{ - template - struct apply : minimum_category - {}; -}; - -# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) // ETI workaround -template <> -struct minimum_category -{ - typedef int type; -}; -# endif - -}} // namespace boost::detail - -#endif // MINIMUM_CATEGORY_DWA20031119_HPP diff --git a/include/boost/iterator/filter_iterator.hpp b/include/boost/iterator/filter_iterator.hpp deleted file mode 100644 index fee0184..0000000 --- a/include/boost/iterator/filter_iterator.hpp +++ /dev/null @@ -1,137 +0,0 @@ -// (C) Copyright David Abrahams 2002. -// (C) Copyright Jeremy Siek 2002. -// (C) Copyright Thomas Witt 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. -#ifndef BOOST_FILTER_ITERATOR_23022003THW_HPP -#define BOOST_FILTER_ITERATOR_23022003THW_HPP - -#include -#include -#include - -#include -#include - -namespace boost -{ - template - class filter_iterator; - - namespace detail - { - template - struct filter_iterator_base - { - typedef iterator_adaptor< - filter_iterator - , Iterator - , use_default - , typename mpl::if_< - is_convertible< - typename iterator_traversal::type - , bidirectional_traversal_tag - > - , forward_traversal_tag - , use_default - >::type - > type; - }; - } - - template - class filter_iterator - : public detail::filter_iterator_base::type - { - typedef typename detail::filter_iterator_base< - Predicate, Iterator - >::type super_t; - - friend class iterator_core_access; - - public: - filter_iterator() { } - - filter_iterator(Predicate f, Iterator x, Iterator end = Iterator()) - : super_t(x), m_predicate(f), m_end(end) - { - satisfy_predicate(); - } - - filter_iterator(Iterator x, Iterator end = Iterator()) - : super_t(x), m_predicate(), m_end(end) - { - // Pro8 is a little too aggressive about instantiating the - // body of this function. -#if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) - // Don't allow use of this constructor if Predicate is a - // function pointer type, since it will be 0. - BOOST_STATIC_ASSERT(is_class::value); -#endif - satisfy_predicate(); - } - - template - filter_iterator( - filter_iterator const& t - , typename enable_if_convertible::type* = 0 - ) - : super_t(t.base()), m_predicate(t.predicate()), m_end(t.end()) {} - - Predicate predicate() const { return m_predicate; } - - Iterator end() const { return m_end; } - - private: - void increment() - { - ++(this->base_reference()); - satisfy_predicate(); - } - - void decrement() - { - while(!this->m_predicate(*--(this->base_reference()))){}; - } - - void satisfy_predicate() - { - while (this->base() != this->m_end && !this->m_predicate(*this->base())) - ++(this->base_reference()); - } - - // Probably should be the initial base class so it can be - // optimized away via EBO if it is an empty class. - Predicate m_predicate; - Iterator m_end; - }; - - template - filter_iterator - make_filter_iterator(Predicate f, Iterator x, Iterator end = Iterator()) - { - return filter_iterator(f,x,end); - } - - template - filter_iterator - make_filter_iterator( - typename iterators::enable_if< - is_class - , Iterator - >::type x - , Iterator end = Iterator() -#if BOOST_WORKAROUND(BOOST_MSVC, == 1200) - , Predicate* = 0 -#endif - ) - { - return filter_iterator(x,end); - } - -} // namespace boost - -#endif // BOOST_FILTER_ITERATOR_23022003THW_HPP diff --git a/include/boost/iterator/indirect_iterator.hpp b/include/boost/iterator/indirect_iterator.hpp deleted file mode 100644 index 91c4283..0000000 --- a/include/boost/iterator/indirect_iterator.hpp +++ /dev/null @@ -1,141 +0,0 @@ -// (C) Copyright David Abrahams 2002. -// (C) Copyright Jeremy Siek 2002. -// (C) Copyright Thomas Witt 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. -#ifndef BOOST_INDIRECT_ITERATOR_23022003THW_HPP -#define BOOST_INDIRECT_ITERATOR_23022003THW_HPP - -#include -#include - -#include -#include -#include - -#include - -#include -#include - -#include -#include -#include -#include -#include - -#ifdef BOOST_MPL_NO_AUX_HAS_XXX -# include -# include -# include -# include -#endif - -#include // must be last #include - -namespace boost -{ - template - class indirect_iterator; - - namespace detail - { - template - struct indirect_base - { - typedef typename iterator_traits::value_type dereferenceable; - - typedef iterator_adaptor< - indirect_iterator - , Iter - , typename ia_dflt_help< - Value, pointee - >::type - , Category - , typename ia_dflt_help< - Reference - , mpl::apply_if< - is_same - , indirect_reference - , add_reference - > - >::type - , Difference - > type; - }; - - template <> - struct indirect_base {}; - } // namespace detail - - - template < - class Iterator - , class Value = use_default - , class Category = use_default - , class Reference = use_default - , class Difference = use_default - > - class indirect_iterator - : public detail::indirect_base< - Iterator, Value, Category, Reference, Difference - >::type - { - typedef typename detail::indirect_base< - Iterator, Value, Category, Reference, Difference - >::type super_t; - - friend class iterator_core_access; - - public: - indirect_iterator() {} - - indirect_iterator(Iterator iter) - : super_t(iter) {} - - template < - class Iterator2, class Value2, class Category2 - , class Reference2, class Difference2 - > - indirect_iterator( - indirect_iterator< - Iterator2, Value2, Category2, Reference2, Difference2 - > const& y - , typename enable_if_convertible::type* = 0 - ) - : super_t(y.base()) - {} - - private: - typename super_t::reference dereference() const - { -# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) - return const_cast(**this->base()); -# else - return **this->base(); -# endif - } - }; - - template - inline - indirect_iterator make_indirect_iterator(Iter x) - { - return indirect_iterator(x); - } - - template - inline - indirect_iterator make_indirect_iterator(Iter x, Traits* = 0) - { - return indirect_iterator(x); - } - -} // namespace boost - -#include - -#endif // BOOST_INDIRECT_ITERATOR_23022003THW_HPP diff --git a/include/boost/iterator/interoperable.hpp b/include/boost/iterator/interoperable.hpp deleted file mode 100644 index b326250..0000000 --- a/include/boost/iterator/interoperable.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// (C) Copyright David Abrahams 2002. -// (C) Copyright Jeremy Siek 2002. -// (C) Copyright Thomas Witt 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. -#ifndef BOOST_INTEROPERABLE_23022003THW_HPP -# define BOOST_INTEROPERABLE_23022003THW_HPP - -# include -# include - -# include - -# include // must appear last - -namespace boost -{ - - // - // Meta function that determines whether two - // iterator types are considered interoperable. - // - // Two iterator types A,B are considered interoperable if either - // A is convertible to B or vice versa. - // This interoperability definition is in sync with the - // standards requirements on constant/mutable container - // iterators (23.1 [lib.container.requirements]). - // - // For compilers that don't support is_convertible - // is_interoperable gives false positives. See comments - // on operator implementation for consequences. - // - template - struct is_interoperable -# ifdef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY - : mpl::true_ -# else - : mpl::or_< - is_convertible< A, B > - , is_convertible< B, A > > -# endif - { - }; - -} // namespace boost - -# include - -#endif // BOOST_INTEROPERABLE_23022003THW_HPP diff --git a/include/boost/iterator/is_lvalue_iterator.hpp b/include/boost/iterator/is_lvalue_iterator.hpp deleted file mode 100755 index 4938151..0000000 --- a/include/boost/iterator/is_lvalue_iterator.hpp +++ /dev/null @@ -1,150 +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) -#ifndef IS_LVALUE_ITERATOR_DWA2003112_HPP -# define IS_LVALUE_ITERATOR_DWA2003112_HPP - -#include - -#include -#include - -#include - -// should be the last #includes -#include -#include - -#ifndef BOOST_NO_IS_CONVERTIBLE - -namespace boost { - -namespace detail -{ -#ifndef BOOST_NO_LVALUE_RETURN_DETECTION - // Calling lvalue_preserver( , 0 ) returns a reference - // to the expression's result if is an lvalue, or - // not_an_lvalue() otherwise. - struct not_an_lvalue {}; - - template - T& lvalue_preserver(T&, int); - - template - not_an_lvalue lvalue_preserver(U const&, ...); - -# define BOOST_LVALUE_PRESERVER(expr) lvalue_preserver(expr,0) - -#else - -# define BOOST_LVALUE_PRESERVER(expr) expr - -#endif - - // Guts of is_lvalue_iterator. Value is the iterator's value_type - // and the result is computed in the nested rebind template. - template - struct is_lvalue_iterator_impl - { - // Eat implicit conversions so we don't report true for things - // convertible to Value const& - struct conversion_eater - { - conversion_eater(Value&); - }; - - static char tester(conversion_eater, int); - static char (& tester(any_conversion_eater, ...) )[2]; - - template - struct rebind - { - static It& x; - - BOOST_STATIC_CONSTANT( - bool - , value = ( - sizeof( - is_lvalue_iterator_impl::tester( - BOOST_LVALUE_PRESERVER(*x), 0 - ) - ) == 1 - ) - ); - }; - }; - -#undef BOOST_LVALUE_PRESERVER - - // - // void specializations to handle std input and output iterators - // - template <> - struct is_lvalue_iterator_impl - { - template - struct rebind : boost::mpl::false_ - {}; - }; - -#ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS - template <> - struct is_lvalue_iterator_impl - { - template - struct rebind : boost::mpl::false_ - {}; - }; - - template <> - struct is_lvalue_iterator_impl - { - template - struct rebind : boost::mpl::false_ - {}; - }; - - template <> - struct is_lvalue_iterator_impl - { - template - struct rebind : boost::mpl::false_ - {}; - }; -#endif - - // - // This level of dispatching is required for Borland. We might save - // an instantiation by removing it for others. - // - template - struct is_readable_lvalue_iterator_impl - : is_lvalue_iterator_impl< - BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits::value_type const - >::template rebind - {}; - - template - struct is_non_const_lvalue_iterator_impl - : is_lvalue_iterator_impl< - BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits::value_type - >::template rebind - {}; -} // namespace detail - -// Define the trait with full mpl lambda capability and various broken -// compiler workarounds -BOOST_TT_AUX_BOOL_TRAIT_DEF1( - is_lvalue_iterator,T,::boost::detail::is_readable_lvalue_iterator_impl::value) - -BOOST_TT_AUX_BOOL_TRAIT_DEF1( - is_non_const_lvalue_iterator,T,::boost::detail::is_non_const_lvalue_iterator_impl::value) - -} // namespace boost - -#endif - -#include -#include - -#endif // IS_LVALUE_ITERATOR_DWA2003112_HPP diff --git a/include/boost/iterator/is_readable_iterator.hpp b/include/boost/iterator/is_readable_iterator.hpp deleted file mode 100755 index 60d6ff0..0000000 --- a/include/boost/iterator/is_readable_iterator.hpp +++ /dev/null @@ -1,108 +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) -#ifndef IS_READABLE_ITERATOR_DWA2003112_HPP -# define IS_READABLE_ITERATOR_DWA2003112_HPP - -#include -#include - -#include -#include - -// should be the last #include -#include - -#ifndef BOOST_NO_IS_CONVERTIBLE - -namespace boost { - -namespace detail -{ - // Guts of is_readable_iterator. Value is the iterator's value_type - // and the result is computed in the nested rebind template. - template - struct is_readable_iterator_impl - { - static char tester(Value&, int); - static char (& tester(any_conversion_eater, ...) )[2]; - - template - struct rebind - { - static It& x; - - BOOST_STATIC_CONSTANT( - bool - , value = ( - sizeof( - is_readable_iterator_impl::tester(*x, 1) - ) == 1 - ) - ); - }; - }; - -#undef BOOST_READABLE_PRESERVER - - // - // void specializations to handle std input and output iterators - // - template <> - struct is_readable_iterator_impl - { - template - struct rebind : boost::mpl::false_ - {}; - }; - -#ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS - template <> - struct is_readable_iterator_impl - { - template - struct rebind : boost::mpl::false_ - {}; - }; - - template <> - struct is_readable_iterator_impl - { - template - struct rebind : boost::mpl::false_ - {}; - }; - - template <> - struct is_readable_iterator_impl - { - template - struct rebind : boost::mpl::false_ - {}; - }; -#endif - - // - // This level of dispatching is required for Borland. We might save - // an instantiation by removing it for others. - // - template - struct is_readable_iterator_impl2 - : is_readable_iterator_impl< - BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits::value_type const - >::template rebind - {}; -} // namespace detail - -// Define the trait with full mpl lambda capability and various broken -// compiler workarounds -BOOST_TT_AUX_BOOL_TRAIT_DEF1( - is_readable_iterator,T,::boost::detail::is_readable_iterator_impl2::value) - -} // namespace boost - -#endif - -#include - -#endif // IS_READABLE_ITERATOR_DWA2003112_HPP diff --git a/include/boost/iterator/iterator_adaptor.hpp b/include/boost/iterator/iterator_adaptor.hpp deleted file mode 100644 index 77d9990..0000000 --- a/include/boost/iterator/iterator_adaptor.hpp +++ /dev/null @@ -1,345 +0,0 @@ -// (C) Copyright David Abrahams 2002. -// (C) Copyright Jeremy Siek 2002. -// (C) Copyright Thomas Witt 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. -#ifndef BOOST_ITERATOR_ADAPTOR_23022003THW_HPP -#define BOOST_ITERATOR_ADAPTOR_23022003THW_HPP - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include - -#ifdef BOOST_ITERATOR_REF_CONSTNESS_KILLS_WRITABILITY -# include -#else -# include -#endif - -#include - -#include - -namespace boost -{ - // Used as a default template argument internally, merely to - // indicate "use the default", this can also be passed by users - // explicitly in order to specify that the default should be used. - struct use_default; - -# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - // the incompleteness of use_default causes massive problems for - // is_convertible (naturally). This workaround is fortunately not - // needed for vc6/vc7. - template - struct is_convertible - : mpl::false_ {}; -# endif - - namespace detail - { - - // - // Result type used in enable_if_convertible meta function. - // This can be an incomplete type, as only pointers to - // enable_if_convertible< ... >::type are used. - // We could have used void for this, but conversion to - // void* is just to easy. - // - struct enable_type; - } - - - // - // enable_if for use in adapted iterators constructors. - // - // In order to provide interoperability between adapted constant and - // mutable iterators, adapted iterators will usually provide templated - // conversion constructors of the following form - // - // template - // class adapted_iterator : - // public iterator_adaptor< adapted_iterator, Iterator > - // { - // public: - // - // ... - // - // template - // adapted_iterator( - // OtherIterator const& it - // , typename enable_if_convertible::type* = 0); - // - // ... - // }; - // - // enable_if_convertible is used to remove those overloads from the overload - // set that cannot be instantiated. For all practical purposes only overloads - // for constant/mutable interaction will remain. This has the advantage that - // meta functions like boost::is_convertible do not return false positives, - // as they can only look at the signature of the conversion constructor - // and not at the actual instantiation. - // - // enable_if_interoperable can be safely used in user code. It falls back to - // always enabled for compilers that don't support enable_if or is_convertible. - // There is no need for compiler specific workarounds in user code. - // - // The operators implementation relies on boost::is_convertible not returning - // false positives for user/library defined iterator types. See comments - // on operator implementation for consequences. - // -# if defined(BOOST_NO_IS_CONVERTIBLE) || defined(BOOST_NO_SFINAE) - - template - struct enable_if_convertible - { - typedef detail::enable_type type; - }; - -# elif BOOST_WORKAROUND(_MSC_FULL_VER, BOOST_TESTED_AT(13102292)) && BOOST_MSVC > 1300 - - // For some reason vc7.1 needs us to "cut off" instantiation - // of is_convertible in a few cases. - template - struct enable_if_convertible - : iterators::enable_if< - mpl::or_< - is_same - , is_convertible - > - , detail::enable_type - > - {}; - -# else - - template - struct enable_if_convertible - : iterators::enable_if< - is_convertible - , detail::enable_type - > - {}; - -# endif - - // - // Default template argument handling for iterator_adaptor - // - namespace detail - { - // If T is use_default, return the result of invoking - // DefaultNullaryFn, otherwise return T. - template - struct ia_dflt_help - : mpl::apply_if< - is_same - , DefaultNullaryFn - , mpl::identity - > - { - }; - - // A metafunction which computes an iterator_adaptor's base class, - // a specialization of iterator_facade. - template < - class Derived - , class Base - , class Value - , class Traversal - , class Reference - , class Difference - > - struct iterator_adaptor_base - { - typedef iterator_facade< - Derived - -# ifdef BOOST_ITERATOR_REF_CONSTNESS_KILLS_WRITABILITY - , typename detail::ia_dflt_help< - Value - , mpl::apply_if< - is_same - , iterator_value - , remove_reference - > - >::type -# else - , typename detail::ia_dflt_help< - Value, iterator_value - >::type -# endif - - , typename detail::ia_dflt_help< - Traversal - , iterator_traversal - >::type - - , typename detail::ia_dflt_help< - Reference - , mpl::apply_if< - is_same - , iterator_reference - , add_reference - > - >::type - - , typename detail::ia_dflt_help< - Difference, iterator_difference - >::type - > - type; - }; - template int static_assert_convertible_to(T); - } - - // - // Iterator Adaptor - // - // The parameter ordering changed slightly with respect to former - // versions of iterator_adaptor The idea is that when the user needs - // to fiddle with the reference type it is highly likely that the - // iterator category has to be adjusted as well. Any of the - // following four template arguments may be ommitted or explicitly - // replaced by use_default. - // - // Value - if supplied, the value_type of the resulting iterator, unless - // const. If const, a conforming compiler strips constness for the - // value_type. If not supplied, iterator_traits::value_type is used - // - // Category - the traversal category of the resulting iterator. If not - // supplied, iterator_traversal::type is used. - // - // Reference - the reference type of the resulting iterator, and in - // particular, the result type of operator*(). If not supplied but - // Value is supplied, Value& is used. Otherwise - // iterator_traits::reference is used. - // - // Difference - the difference_type of the resulting iterator. If not - // supplied, iterator_traits::difference_type is used. - // - template < - class Derived - , class Base - , class Value = use_default - , class Traversal = use_default - , class Reference = use_default - , class Difference = use_default - > - class iterator_adaptor - : public detail::iterator_adaptor_base< - Derived, Base, Value, Traversal, Reference, Difference - >::type - { - friend class iterator_core_access; - - typedef typename detail::iterator_adaptor_base< - Derived, Base, Value, Traversal, Reference, Difference - >::type super_t; - - public: - iterator_adaptor() {} - - explicit iterator_adaptor(Base const &iter) - : m_iterator(iter) - { - } - - Base const& base() const - { return m_iterator; } - - protected: - // - // lvalue access to the Base object for Derived - // - Base const& base_reference() const - { return m_iterator; } - - Base& base_reference() - { return m_iterator; } - - private: - // - // Core iterator interface for iterator_facade. This is private - // to prevent temptation for Derived classes to use it, which - // will often result in an error. Derived classes should use - // base_reference(), above, to get direct access to m_iterator. - // - typename super_t::reference dereference() const - { return *m_iterator; } - - template < - class OtherDerived, class OtherIterator, class V, class C, class R, class D - > - bool equal(iterator_adaptor const& x) const - { - // Maybe readd with same_distance - // BOOST_STATIC_ASSERT( - // (detail::same_category_and_difference::value) - // ); - return m_iterator == x.base(); - } - - typedef typename iterator_category_to_traversal< - typename super_t::iterator_category - >::type my_traversal; - -# define BOOST_ITERATOR_ADAPTOR_ASSERT_TRAVERSAL(cat) \ - typedef int assertion[sizeof(detail::static_assert_convertible_to(my_traversal()))]; -// BOOST_STATIC_ASSERT((is_convertible::value)); - - void advance(typename super_t::difference_type n) - { - BOOST_ITERATOR_ADAPTOR_ASSERT_TRAVERSAL(random_access_traversal_tag) - m_iterator += n; - } - - void increment() { ++m_iterator; } - - void decrement() - { - BOOST_ITERATOR_ADAPTOR_ASSERT_TRAVERSAL(bidirectional_traversal_tag) - --m_iterator; - } - - template < - class OtherDerived, class OtherIterator, class V, class C, class R, class D - > - typename super_t::difference_type distance_to( - iterator_adaptor const& y) const - { - BOOST_ITERATOR_ADAPTOR_ASSERT_TRAVERSAL(random_access_traversal_tag) - // Maybe readd with same_distance - // BOOST_STATIC_ASSERT( - // (detail::same_category_and_difference::value) - // ); - return y.base() - m_iterator; - } - -# undef BOOST_ITERATOR_ADAPTOR_ASSERT_TRAVERSAL - - private: // data members - Base m_iterator; - }; - -} // namespace boost - -#include - -#endif // BOOST_ITERATOR_ADAPTOR_23022003THW_HPP diff --git a/include/boost/iterator/iterator_archetypes.hpp b/include/boost/iterator/iterator_archetypes.hpp deleted file mode 100644 index e216647..0000000 --- a/include/boost/iterator/iterator_archetypes.hpp +++ /dev/null @@ -1,501 +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. - -#ifndef BOOST_ITERATOR_ARCHETYPES_HPP -#define BOOST_ITERATOR_ARCHETYPES_HPP - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace boost { - -template -struct access_archetype; - -template -struct traversal_archetype; - -namespace iterator_archetypes -{ - enum { - readable_iterator_bit = 1 - , writable_iterator_bit = 2 - , swappable_iterator_bit = 4 - , lvalue_iterator_bit = 8 - }; - - // Not quite tags, since dispatching wouldn't work. - typedef mpl::int_::type readable_iterator_t; - typedef mpl::int_::type writable_iterator_t; - - typedef mpl::int_< - (readable_iterator_bit|writable_iterator_bit) - >::type readable_writable_iterator_t; - - typedef mpl::int_< - (readable_iterator_bit|lvalue_iterator_bit) - >::type readable_lvalue_iterator_t; - - typedef mpl::int_< - (lvalue_iterator_bit|writable_iterator_bit) - >::type writable_lvalue_iterator_t; - - typedef mpl::int_::type swappable_iterator_t; - typedef mpl::int_::type lvalue_iterator_t; - - template - struct has_access - : mpl::equal_to< - mpl::bitand_ - , Base - > - {}; -} - -namespace detail -{ - template - struct assign_proxy - { - assign_proxy& operator=(T) { return *this; } - }; - - template - struct read_proxy - { - operator T() { return static_object::get(); } - }; - - template - struct read_write_proxy - : read_proxy // Use to inherit from assign_proxy, but that doesn't work. -JGS - { - read_write_proxy& operator=(T) { return *this; } - }; - - template - struct arrow_proxy - { - T const* operator->() const { return 0; } - }; - - struct no_operator_brackets {}; - - template - struct readable_operator_brackets - { - read_proxy operator[](std::ptrdiff_t n) const { return read_proxy(); } - }; - - template - struct writable_operator_brackets - { - read_write_proxy operator[](std::ptrdiff_t n) const { return read_write_proxy(); } - }; - - template - struct operator_brackets - : mpl::aux::msvc_eti_base< - typename mpl::apply_if< - is_convertible - , mpl::apply_if< - iterator_archetypes::has_access< - AccessCategory - , iterator_archetypes::writable_iterator_t - > - , mpl::identity > - , mpl::if_< - iterator_archetypes::has_access< - AccessCategory - , iterator_archetypes::readable_iterator_t - > - , readable_operator_brackets - , no_operator_brackets - > - > - , mpl::identity - >::type - >::type - {}; - - template - struct traversal_archetype_impl - { - template struct archetype; - }; - - // Constructor argument for those iterators that - // are not default constructible - struct ctor_arg {}; - - template - struct traversal_archetype_ - : mpl::aux::msvc_eti_base< - typename traversal_archetype_impl::template archetype - >::type - { - typedef typename - traversal_archetype_impl::template archetype - base; - - traversal_archetype_() {} - - traversal_archetype_(ctor_arg arg) - : base(arg) - {} - }; - - template <> - struct traversal_archetype_impl - { - template - struct archetype - { - explicit archetype(ctor_arg) {} - - 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::get(); } - Derived operator++(int) const { return (Derived&)static_object::get(); } - }; - }; - - template <> - struct traversal_archetype_impl - { - template - struct archetype - : public equality_comparable< traversal_archetype_ >, - public traversal_archetype_ - { - explicit archetype(ctor_arg arg) - : traversal_archetype_(arg) - {} - }; - }; - - template - bool operator==(traversal_archetype_ const&, - traversal_archetype_ const&) { return true; } - -#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) - // doesn't seem to pick up != from equality_comparable - template - bool operator!=(traversal_archetype_ const&, - traversal_archetype_ const&) { return true; } -#endif - template <> - struct traversal_archetype_impl - { - template - struct archetype - : public traversal_archetype_ - { - archetype() - : traversal_archetype_(ctor_arg()) - {} - typedef std::ptrdiff_t difference_type; - }; - }; - - template <> - struct traversal_archetype_impl - { - template - struct archetype - : public traversal_archetype_ - { - Derived& operator--() { return static_object::get(); } - Derived operator--(int) const { return static_object::get(); } - }; - }; - - template <> - struct traversal_archetype_impl - { - template - struct archetype - : public partially_ordered >, - public traversal_archetype_ - { - Derived& operator+=(std::ptrdiff_t) { return static_object::get(); } - Derived& operator-=(std::ptrdiff_t) { return static_object::get(); } - }; - }; - - template - Derived& operator+(traversal_archetype_ const&, - std::ptrdiff_t) { return static_object::get(); } - - template - Derived& operator+(std::ptrdiff_t, - traversal_archetype_ const&) - { return static_object::get(); } - - template - Derived& operator-(traversal_archetype_ const&, - std::ptrdiff_t) - { return static_object::get(); } - - template - std::ptrdiff_t operator-(traversal_archetype_ const&, - traversal_archetype_ const&) - { return 0; } - - template - bool operator<(traversal_archetype_ const&, - traversal_archetype_ const&) - { return true; } - - struct bogus_type; - - template - struct convertible_type - : mpl::if_< is_const, - typename remove_const::type, - bogus_type > - {}; - -} // namespace detail - - -template struct undefined; - -template -struct iterator_access_archetype_impl -{ - template struct archetype; -}; - -template -struct iterator_access_archetype - : mpl::aux::msvc_eti_base< - typename iterator_access_archetype_impl< - AccessCategory - >::template archetype - >::type -{ -}; - -template <> -struct iterator_access_archetype_impl< - iterator_archetypes::readable_iterator_t -> -{ - template - struct archetype - { - typedef typename remove_cv::type value_type; - typedef Value reference; - typedef Value* pointer; - - value_type operator*() const { return static_object::get(); } - - detail::arrow_proxy operator->() const { return detail::arrow_proxy(); } - }; -}; - -template <> -struct iterator_access_archetype_impl< - iterator_archetypes::writable_iterator_t -> -{ - template - struct archetype - { -# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) - BOOST_STATIC_ASSERT(!is_const::value); -# endif - typedef void value_type; - typedef void reference; - typedef void pointer; - - detail::assign_proxy operator*() const { return detail::assign_proxy(); } - }; -}; - -template <> -struct iterator_access_archetype_impl< - iterator_archetypes::readable_writable_iterator_t -> -{ - template - struct archetype - : public virtual iterator_access_archetype< - Value, iterator_archetypes::readable_iterator_t - > - { - typedef detail::read_write_proxy reference; - - detail::read_write_proxy operator*() const { return detail::read_write_proxy(); } - }; -}; - -template <> -struct iterator_access_archetype_impl -{ - template - struct archetype - : public virtual iterator_access_archetype< - Value, iterator_archetypes::readable_iterator_t - > - { - typedef Value& reference; - - Value& operator*() const { return static_object::get(); } - Value* operator->() const { return 0; } - }; -}; - -template <> -struct iterator_access_archetype_impl -{ - template - struct archetype - : public virtual iterator_access_archetype< - Value, iterator_archetypes::readable_lvalue_iterator_t - > - { -# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) - BOOST_STATIC_ASSERT((!is_const::value)); -# endif - }; -}; - - -template -struct iterator_archetype; - -template -struct traversal_archetype_base - : detail::operator_brackets< - typename remove_cv::type - , AccessCategory - , TraversalCategory - > - , detail::traversal_archetype_< - iterator_archetype - , Value - , TraversalCategory - > -{ -}; - -namespace detail -{ - template - struct iterator_archetype_base - : iterator_access_archetype - , traversal_archetype_base - { - typedef iterator_access_archetype access; - - typedef typename detail::facade_iterator_category< - TraversalCategory - , typename mpl::apply_if< - iterator_archetypes::has_access< - AccessCategory, iterator_archetypes::writable_iterator_t - > - , remove_const - , add_const - >::type - , typename access::reference - >::type iterator_category; - - // Needed for some broken libraries (see below) - typedef boost::iterator< - iterator_category - , Value - , typename traversal_archetype_base< - Value, AccessCategory, TraversalCategory - >::difference_type - , typename access::pointer - , typename access::reference - > workaround_iterator_base; - }; -} - -template -struct iterator_archetype - : public detail::iterator_archetype_base - - // These broken libraries require derivation from std::iterator - // (or related magic) in order to handle iter_swap and other - // iterator operations -# if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, < 310) \ - || BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(0x20101)) - , public detail::iterator_archetype_base< - Value, AccessCategory, TraversalCategory - >::workaround_iterator_base -# endif -{ - // Derivation from std::iterator above caused references to nested - // types to be ambiguous, so now we have to redeclare them all - // here. -# if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, < 310) \ - || BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(0x20101)) - - typedef detail::iterator_archetype_base< - Value,AccessCategory,TraversalCategory - > base; - - typedef typename base::value_type value_type; - typedef typename base::reference reference; - typedef typename base::pointer pointer; - typedef typename base::difference_type difference_type; - typedef typename base::iterator_category iterator_category; -# endif - - iterator_archetype() { } - iterator_archetype(iterator_archetype const& x) - : detail::iterator_archetype_base< - Value - , AccessCategory - , TraversalCategory - >(x) - {} - - iterator_archetype& operator=(iterator_archetype const&) - { return *this; } - -# if 0 - // Optional conversion from mutable - iterator_archetype( - iterator_archetype< - typename detail::convertible_type::type - , AccessCategory - , TraversalCategory> const& - ); -# endif -}; - -} // namespace boost - - -#endif // BOOST_ITERATOR_ARCHETYPES_HPP diff --git a/include/boost/iterator/iterator_categories.hpp b/include/boost/iterator/iterator_categories.hpp deleted file mode 100644 index 6153c6f..0000000 --- a/include/boost/iterator/iterator_categories.hpp +++ /dev/null @@ -1,169 +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. - -#ifndef BOOST_ITERATOR_CATEGORIES_HPP -# define BOOST_ITERATOR_CATEGORIES_HPP - -# include -# include -# include - -# include - -# include -# include -# include -# include - -# include - -# include - -namespace boost { - -// -// Traversal Categories -// - -struct no_traversal_tag {}; - -struct incrementable_traversal_tag - : no_traversal_tag {}; - -struct single_pass_traversal_tag - : incrementable_traversal_tag {}; - -struct forward_traversal_tag - : single_pass_traversal_tag {}; - -struct bidirectional_traversal_tag - : forward_traversal_tag {}; - -struct random_access_traversal_tag - : bidirectional_traversal_tag {}; - -namespace detail -{ - // - // Convert a "strictly old-style" iterator category to a traversal - // tag. This is broken out into a separate metafunction to reduce - // the cost of instantiating iterator_category_to_traversal, below, - // for new-style types. - // - template - struct old_category_to_traversal - : mpl::apply_if< - is_convertible - , mpl::identity - , mpl::apply_if< - is_convertible - , mpl::identity - , mpl::apply_if< - is_convertible - , mpl::identity - , mpl::apply_if< - is_convertible - , mpl::identity - , mpl::apply_if< - is_convertible - , mpl::identity - , void - > - > - > - > - > - {}; - -# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) - template <> - struct old_category_to_traversal - { - typedef int type; - }; -# endif - - template - struct pure_traversal_tag - : mpl::apply_if< - is_convertible - , mpl::identity - , mpl::apply_if< - is_convertible - , mpl::identity - , mpl::apply_if< - is_convertible - , mpl::identity - , mpl::apply_if< - is_convertible - , mpl::identity - , mpl::apply_if< - is_convertible - , mpl::identity - , void - > - > - > - > - > - { - }; - -# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) - template <> - struct pure_traversal_tag - { - typedef int type; - }; -# endif - -} // namespace detail - - -// -// Convert an iterator category into a traversal tag -// -template -struct iterator_category_to_traversal - : mpl::apply_if< // if already convertible to a traversal tag, we're done. - is_convertible - , mpl::identity - , detail::old_category_to_traversal - > -{}; - -// Trait to get an iterator's traversal category -template -struct iterator_traversal - : iterator_category_to_traversal< - typename boost::detail::iterator_traits::iterator_category - > -{}; - -# ifdef BOOST_MPL_NO_FULL_LAMBDA_SUPPORT -// Hack because BOOST_MPL_AUX_LAMBDA_SUPPORT doesn't seem to work -// out well. Instantiating the nested apply template also -// requires instantiating iterator_traits on the -// placeholder. Instead we just specialize it as a metafunction -// class. -template <> -struct iterator_traversal -{ - template - struct apply : iterator_traversal - {}; -}; -template <> -struct iterator_traversal - : iterator_traversal -{}; -# endif - -} // namespace boost - -#include - -#endif // BOOST_ITERATOR_CATEGORIES_HPP diff --git a/include/boost/iterator/iterator_concepts.hpp b/include/boost/iterator/iterator_concepts.hpp deleted file mode 100644 index 663917e..0000000 --- a/include/boost/iterator/iterator_concepts.hpp +++ /dev/null @@ -1,328 +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. - -#ifndef BOOST_ITERATOR_CONCEPTS_HPP -#define BOOST_ITERATOR_CONCEPTS_HPP - -// Revision History -// 26 Apr 2003 thw -// Adapted to new iterator concepts -// 22 Nov 2002 Thomas Witt -// Added interoperable concept. - -#include -#include - -// Use boost::detail::iterator_traits to work around some MSVC/Dinkumware problems. -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include - -// Use boost/limits to work around missing limits headers on some compilers -#include - -#include - -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. - - // We use this in place of STATIC_ASSERT((is_convertible<...>)) - // because some compilers (CWPro7.x) can't detect convertibility. - // - // Of course, that just gets us a different error at the moment with - // some tests, since new iterator category deduction still depends - // on convertibility detection. We might need some specializations - // to support this compiler. - template - struct static_assert_base_and_derived - { - static_assert_base_and_derived(Target* = (Source*)0) {} - }; - - //=========================================================================== - // Iterator Access Concepts - - template - class ReadableIteratorConcept { - public: - typedef BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits::value_type value_type; - - void constraints() { - boost::function_requires< boost::AssignableConcept >(); - boost::function_requires< boost::CopyConstructibleConcept >(); - - value_type v = *i; - boost::ignore_unused_variable_warning(v); - } - Iterator i; - }; - - template < - typename Iterator - , typename ValueType = BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits::value_type - > - class WritableIteratorConcept { - public: - - void constraints() { - boost::function_requires< boost::CopyConstructibleConcept >(); - *i = v; - } - ValueType v; - Iterator i; - }; - - template - class SwappableIteratorConcept { - public: - - void constraints() { - std::iter_swap(i1, i2); - } - Iterator i1; - Iterator i2; - }; - - template - class ReadableLvalueIteratorConcept - { - public: - typedef typename boost::detail::iterator_traits::value_type value_type; - - void constraints() - { - boost::function_requires< ReadableIteratorConcept >(); - const value_type& v = *i; - boost::ignore_unused_variable_warning(v); - } - Iterator i; - }; - - template - class WritableLvalueIteratorConcept { - public: - typedef typename boost::detail::iterator_traits::value_type value_type; - typedef typename boost::detail::iterator_traits::reference reference; - - void constraints() { - boost::function_requires< - ReadableLvalueIteratorConcept >(); - boost::function_requires< - WritableIteratorConcept >(); - boost::function_requires< - SwappableIteratorConcept >(); - - - BOOST_STATIC_ASSERT((boost::is_same::value)); - } - }; - - //=========================================================================== - // Iterator Traversal Concepts - - template - class IncrementableIteratorConcept { - public: - typedef typename boost::iterator_traversal::type traversal_category; - - void constraints() { - boost::function_requires< boost::AssignableConcept >(); - boost::function_requires< boost::CopyConstructibleConcept >(); - - BOOST_STATIC_ASSERT( - (boost::is_convertible< - traversal_category - , boost::incrementable_traversal_tag - >::value - )); - - ++i; - (void)i++; - } - Iterator i; - }; - - template - class SinglePassIteratorConcept { - public: - typedef typename boost::iterator_traversal::type traversal_category; - typedef typename boost::detail::iterator_traits::difference_type difference_type; - - void constraints() { - boost::function_requires< IncrementableIteratorConcept >(); - boost::function_requires< boost::EqualityComparableConcept >(); - - BOOST_STATIC_ASSERT( - (boost::is_convertible< - traversal_category - , boost::single_pass_traversal_tag - >::value - )); - } - }; - - template - class ForwardTraversalConcept { - public: - typedef typename boost::iterator_traversal::type traversal_category; - typedef typename boost::detail::iterator_traits::difference_type difference_type; - - void constraints() { - boost::function_requires< SinglePassIteratorConcept >(); - boost::function_requires< - boost::DefaultConstructibleConcept >(); - - typedef boost::mpl::and_< - boost::is_integral, - boost::mpl::bool_< std::numeric_limits::is_signed > - > difference_type_is_signed_integral; - - BOOST_STATIC_ASSERT(difference_type_is_signed_integral::value); - BOOST_STATIC_ASSERT( - (boost::is_convertible< - traversal_category - , boost::forward_traversal_tag - >::value - )); - } - }; - - template - class BidirectionalTraversalConcept { - public: - typedef typename boost::iterator_traversal::type traversal_category; - - void constraints() { - boost::function_requires< ForwardTraversalConcept >(); - - BOOST_STATIC_ASSERT( - (boost::is_convertible< - traversal_category - , boost::bidirectional_traversal_tag - >::value - )); - - --i; - (void)i--; - } - Iterator i; - }; - - template - class RandomAccessTraversalConcept { - public: - typedef typename boost::iterator_traversal::type traversal_category; - typedef typename boost::detail::iterator_traits::difference_type - difference_type; - - void constraints() { - boost::function_requires< BidirectionalTraversalConcept >(); - - BOOST_STATIC_ASSERT( - (boost::is_convertible< - traversal_category - , boost::random_access_traversal_tag - >::value - )); - - i += n; - i = i + n; - i = n + i; - i -= n; - i = i - n; - n = i - j; - } - difference_type n; - Iterator i, j; - }; - - //=========================================================================== - // Iterator Interoperability Concept - - namespace detail - { - - template - void interop_single_pass_constraints(Iterator1 const& i1, Iterator2 const& i2) - { - bool b; - b = i1 == i2; - b = i1 != i2; - - b = i2 == i1; - b = i2 != i1; - } - - template - 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::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 - void interop_rand_access_constraints(Iterator1 const& i1, Iterator2 const& i2, - boost::single_pass_traversal_tag, boost::single_pass_traversal_tag) - { } - - } // namespace detail - - template - class InteroperableIteratorConcept - { - public: - typedef typename boost::detail::pure_traversal_tag< - typename boost::iterator_traversal< - Iterator - >::type - >::type traversal_category; - - typedef typename boost::detail::pure_traversal_tag< - typename boost::iterator_traversal< - ConstIterator - >::type - >::type const_traversal_category; - - void constraints() - { - boost::function_requires< SinglePassIteratorConcept >(); - boost::function_requires< SinglePassIteratorConcept >(); - - detail::interop_single_pass_constraints(i, ci); - detail::interop_rand_access_constraints(i, ci, traversal_category(), const_traversal_category()); - - ci = i; - } - Iterator i; - ConstIterator ci; - }; - -} // namespace boost_concepts - - -#endif // BOOST_ITERATOR_CONCEPTS_HPP diff --git a/include/boost/iterator/iterator_facade.hpp b/include/boost/iterator/iterator_facade.hpp deleted file mode 100644 index 1e2ec70..0000000 --- a/include/boost/iterator/iterator_facade.hpp +++ /dev/null @@ -1,640 +0,0 @@ -// (C) Copyright David Abrahams 2002. -// (C) Copyright Jeremy Siek 2002. -// (C) Copyright Thomas Witt 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. -#ifndef BOOST_ITERATOR_FACADE_23022003THW_HPP -#define BOOST_ITERATOR_FACADE_23022003THW_HPP - -#include - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#if BOOST_WORKAROUND(BOOST_MSVC, == 1200) -# include -#endif - -#include // this goes last - -namespace boost -{ - // This forward declaration is required for the friend declaration - // in iterator_core_access - template class iterator_facade; - - namespace detail - { - // - // 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 - , is_convertible - > - , Return - > -#endif - { -#ifdef BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY - typedef Return type; -#endif - }; - - // - // Generates associated types for an iterator_facade with the - // given parameters. - // - template < - class ValueParam - , class CategoryOrTraversal - , class Reference - , class Difference - > - struct iterator_facade_types - { - typedef typename facade_iterator_category< - CategoryOrTraversal, ValueParam, Reference - >::type iterator_category; - - typedef typename remove_const::type value_type; - - typedef typename mpl::apply_if< - detail::iterator_writability_disabled - , add_pointer::type> - , add_pointer - >::type pointer; - -# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ - && (BOOST_WORKAROUND(_STLPORT_VERSION, BOOST_TESTED_AT(0x452)) \ - || 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 - base; -# endif - }; - - - // 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 - struct operator_arrow_proxy - { - operator_arrow_proxy(T const* px) : m_value(*px) {} - const T* operator->() const { return &m_value; } - // This function is needed for MWCW and BCC, which won't call operator-> - // again automatically per 13.3.1.2 para 8 - operator const T*() const { return &m_value; } - T m_value; - }; - - // A metafunction that gets the result type for operator->. Also - // has a static function make() which builds the result from a - // Reference - template - struct operator_arrow_result - { - // CWPro8.3 won't accept "operator_arrow_result::type", and we - // need that type below, so metafunction forwarding would be a - // losing proposition here. - typedef typename mpl::if_< - is_reference - , Pointer - , operator_arrow_proxy - >::type type; - - static type make(Reference x) - { - return type(&x); - } - }; - -# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) - // Deal with ETI - template<> - struct operator_arrow_result - { - typedef int type; - }; -# endif - - // - // Iterator is actually an iterator_facade, so we do not have to - // go through iterator_traits to access the traits. - // - template - class operator_brackets_proxy - { - typedef typename Iterator::reference reference; - typedef typename Iterator::value_type value_type; - - public: - operator_brackets_proxy(Iterator const& iter) - : m_iter(iter) - {} - - operator reference() const - { - return *m_iter; - } - - operator_brackets_proxy& operator=(value_type const& val) - { - *m_iter = val; - return *this; - } - - private: - Iterator m_iter; - }; - - template - struct use_operator_brackets_proxy - : mpl::and_< - // Really we want an is_copy_constructible trait here, - // but is_POD will have to suffice in the meantime. - boost::is_POD - , iterator_writability_disabled - > - {}; - - template - struct operator_brackets_result - { - typedef typename mpl::if_< - use_operator_brackets_proxy - , Value - , operator_brackets_proxy - >::type type; - }; - - template - operator_brackets_proxy make_operator_brackets_result(Iterator const& iter, mpl::false_) - { - return operator_brackets_proxy(iter); - } - - template - typename Iterator::value_type make_operator_brackets_result(Iterator const& iter, mpl::true_) - { - return *iter; - } - - struct choose_difference_type - { - template - struct apply - : -# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) - mpl::if_< - is_convertible - , typename I1::difference_type - , typename I2::difference_type - > -# else - mpl::apply_if< - is_convertible - , iterator_difference - , iterator_difference - > -# endif - {}; - - }; - } // namespace detail - - - // Macros which describe the declarations of binary operators -# 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 \ - , typename mpl::apply2::type \ - >::type \ - operator op( \ - iterator_facade const& lhs \ - , iterator_facade const& rhs) - -# define BOOST_ITERATOR_FACADE_PLUS_HEAD(prefix,args) \ - template \ - prefix Derived operator+ args - - // - // Helper class for granting access to the iterator core interface. - // - // The simple core interface is used by iterator_facade. The core - // interface of a user/library defined iterator type should not be made public - // so that it does not clutter the public interface. Instead iterator_core_access - // should be made friend so that iterator_facade can access the core - // interface through iterator_core_access. - // - class iterator_core_access - { -# if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) \ - || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) - // Tasteless as this may seem, making all members public allows member templates - // to work in the absence of member template friends. - public: -# else - - template friend class iterator_facade; - -# define BOOST_ITERATOR_FACADE_RELATION(op) \ - BOOST_ITERATOR_FACADE_INTEROP_HEAD(friend,op, mpl::always); - - BOOST_ITERATOR_FACADE_RELATION(==) - BOOST_ITERATOR_FACADE_RELATION(!=) - - BOOST_ITERATOR_FACADE_RELATION(<) - BOOST_ITERATOR_FACADE_RELATION(>) - BOOST_ITERATOR_FACADE_RELATION(<=) - BOOST_ITERATOR_FACADE_RELATION(>=) -# undef BOOST_ITERATOR_FACADE_RELATION - - BOOST_ITERATOR_FACADE_INTEROP_HEAD( - friend, -, detail::choose_difference_type) - ; - - BOOST_ITERATOR_FACADE_PLUS_HEAD( - friend - , (iterator_facade const& - , typename Derived::difference_type) - ) - ; - - BOOST_ITERATOR_FACADE_PLUS_HEAD( - friend - , (typename Derived::difference_type - , iterator_facade const&) - ) - ; - -# endif - - template - static typename Facade::reference dereference(Facade const& f) - { - return f.dereference(); - } - - template - static void increment(Facade& f) - { - f.increment(); - } - - template - static void decrement(Facade& f) - { - f.decrement(); - } - - template - static bool equal(Facade1 const& f1, Facade2 const& f2, mpl::true_) - { - return f1.equal(f2); - } - - template - static bool equal(Facade1 const& f1, Facade2 const& f2, mpl::false_) - { - return f2.equal(f1); - } - - template - static void advance(Facade& f, typename Facade::difference_type n) - { - f.advance(n); - } - - template - static typename Facade1::difference_type minus( - Facade1 const& f1, Facade2 const& f2, mpl::true_) - { - return -f1.distance_to(f2); - } - - template - static typename Facade2::difference_type minus( - Facade1 const& f1, Facade2 const& f2, mpl::false_) - { - return f2.distance_to(f1); - } - - private: - // objects of this class are useless - iterator_core_access(); //undefined - }; - - // - // iterator_facade - use as a public base class for defining new - // standard-conforming iterators. - // - template < - class Derived // The derived iterator type being constructed - , class Value - , class CategoryOrTraversal - , class Reference = Value& - , class Difference = std::ptrdiff_t - > - class iterator_facade -# ifdef BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE - : public detail::iterator_facade_types< - Value, CategoryOrTraversal, Reference, Difference - >::base -# undef BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE -# endif - { - private: - // - // Curiously Recurring Template interface. - // - typedef Derived derived_t; - - Derived& derived() - { - return static_cast(*this); - } - - Derived const& derived() const - { - return static_cast(*this); - } - - typedef detail::iterator_facade_types< - Value, CategoryOrTraversal, Reference, Difference - > associated_types; - - public: - - typedef typename associated_types::value_type value_type; - typedef Reference reference; - typedef Difference difference_type; - typedef typename associated_types::pointer pointer; - typedef typename associated_types::iterator_category iterator_category; - - reference operator*() const - { - return iterator_core_access::dereference(this->derived()); - } - - typename detail::operator_arrow_result< - value_type - , reference - , pointer - >::type - operator->() const - { - return detail::operator_arrow_result< - value_type - , reference - , pointer - >::make(*this->derived()); - } - - typename detail::operator_brackets_result::type - operator[](difference_type n) const - { - typedef detail::use_operator_brackets_proxy use_proxy; - - return detail::make_operator_brackets_result( - this->derived() + n - , use_proxy() - ); - } - - Derived& operator++() - { - iterator_core_access::increment(this->derived()); - return this->derived(); - } - - Derived operator++(int) - { - Derived tmp(this->derived()); - ++*this; - return tmp; - } - - 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()); - return result -= x; - } - -# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) - // There appears to be a bug which trashes the data of classes - // derived from iterator_facade when they are assigned unless we - // define this assignment operator. This bug is only revealed - // (so far) in STLPort debug mode, but it's clearly a codegen - // problem so we apply the workaround for all MSVC6. - iterator_facade& operator=(iterator_facade const&) - { - return *this; - } -# endif - }; - - // - // 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. - // - // Note though that this kind of interoperability for constant/mutable - // 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 - // them for only a few iterators.) - // - // ?? Maybe a BOOST_ITERATOR_NO_FULL_INTEROPERABILITY macro should - // enable the user to turn off mixed type operators - // - // The library takes care to provide only the right operator overloads. - // I.e. - // - // bool operator==(Iterator, Iterator); - // bool operator==(ConstIterator, Iterator); - // bool operator==(Iterator, ConstIterator); - // bool operator==(ConstIterator, ConstIterator); - // - // ... - // - // In order to do so it uses c++ idioms that are not yet widely supported - // by current compiler releases. The library is designed to degrade gracefully - // in the face of compiler deficiencies. In general compiler - // 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" - // (aka. enable_if) and boost::is_convertible is required. - // - // The following problems occur if support is lacking. - // - // Pseudo code - // - // --------------- - // AdaptorA a1; - // AdaptorA a2; - // - // // This will result in a no such overload error in full operation - // // If enable_if or is_convertible is not supported - // // The instantiation will fail with an error hopefully indicating that - // // there is no operator== for Iterator1, Iterator2 - // // The same will happen if no enable_if is used to remove - // // false overloads from the templated conversion constructor - // // of AdaptorA. - // - // a1 == a2; - // ---------------- - // - // AdaptorA a; - // AdaptorB b; - // - // // This will result in a no such overload error in full operation - // // If enable_if is not supported the static assert used - // // in the operator implementation will fail. - // // This will accidently work if is_convertible is not supported. - // - // a == b; - // ---------------- - // - -# 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(lhs) \ - , static_cast(rhs) \ - , is_convertible() \ - ); \ - } - -# define BOOST_ITERATOR_FACADE_RELATION(op, return_prefix, base_op) \ - BOOST_ITERATOR_FACADE_INTEROP( \ - op \ - , mpl::always \ - , return_prefix \ - , base_op \ - ) - - BOOST_ITERATOR_FACADE_RELATION(==, return, equal) - BOOST_ITERATOR_FACADE_RELATION(!=, return !, equal) - - BOOST_ITERATOR_FACADE_RELATION(<, return 0 >, minus) - BOOST_ITERATOR_FACADE_RELATION(>, return 0 <, minus) - BOOST_ITERATOR_FACADE_RELATION(<=, return 0 >=, minus) - BOOST_ITERATOR_FACADE_RELATION(>=, return 0 <=, minus) -# undef BOOST_ITERATOR_FACADE_RELATION - - // operator- requires an additional part in the static assertion - BOOST_ITERATOR_FACADE_INTEROP( - - - , detail::choose_difference_type - , return - , minus - ) -# undef BOOST_ITERATOR_FACADE_INTEROP -# undef BOOST_ITERATOR_FACADE_INTEROP_HEAD - -# define BOOST_ITERATOR_FACADE_PLUS(args) \ - BOOST_ITERATOR_FACADE_PLUS_HEAD(inline, args) \ - { \ - Derived tmp(static_cast(i)); \ - return tmp += n; \ - } - -BOOST_ITERATOR_FACADE_PLUS(( - iterator_facade const& i - , typename Derived::difference_type n -)) - -BOOST_ITERATOR_FACADE_PLUS(( - typename Derived::difference_type n - , iterator_facade const& i -)) -# undef BOOST_ITERATOR_FACADE_PLUS -# undef BOOST_ITERATOR_FACADE_PLUS_HEAD - -} // namespace boost - -#include - -#endif // BOOST_ITERATOR_FACADE_23022003THW_HPP diff --git a/include/boost/iterator/iterator_traits.hpp b/include/boost/iterator/iterator_traits.hpp deleted file mode 100644 index 4f0d46f..0000000 --- a/include/boost/iterator/iterator_traits.hpp +++ /dev/null @@ -1,93 +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 ITERATOR_TRAITS_DWA200347_HPP -# define ITERATOR_TRAITS_DWA200347_HPP - -# include -# include - -namespace boost { - -// Unfortunately, g++ 2.95.x chokes when we define a class template -// iterator_category which has the same name as its -// std::iterator_category() function, probably due in part to the -// "std:: is visible globally" hack it uses. Use -// BOOST_ITERATOR_CATEGORY to write code that's portable to older -// GCCs. - -# if BOOST_WORKAROUND(__GNUC__, <= 2) -# define BOOST_ITERATOR_CATEGORY iterator_category_ -# else -# define BOOST_ITERATOR_CATEGORY iterator_category -# endif - - -template -struct iterator_value -{ - typedef typename detail::iterator_traits::value_type type; -}; - -template -struct iterator_reference -{ - typedef typename detail::iterator_traits::reference type; -}; - - -template -struct iterator_pointer -{ - typedef typename detail::iterator_traits::pointer type; -}; - -template -struct iterator_difference -{ - typedef typename detail::iterator_traits::difference_type type; -}; - -template -struct BOOST_ITERATOR_CATEGORY -{ - typedef typename detail::iterator_traits::iterator_category type; -}; - -# if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) -template <> -struct iterator_value -{ - typedef void type; -}; - -template <> -struct iterator_reference -{ - typedef void type; -}; - -template <> -struct iterator_pointer -{ - typedef void type; -}; - -template <> -struct iterator_difference -{ - typedef void type; -}; - -template <> -struct BOOST_ITERATOR_CATEGORY -{ - typedef void type; -}; -# endif - -} // namespace boost::iterator - -#endif // ITERATOR_TRAITS_DWA200347_HPP diff --git a/include/boost/iterator/new_iterator_tests.hpp b/include/boost/iterator/new_iterator_tests.hpp deleted file mode 100644 index c16b826..0000000 --- a/include/boost/iterator/new_iterator_tests.hpp +++ /dev/null @@ -1,214 +0,0 @@ -#ifndef BOOST_NEW_ITERATOR_TESTS_HPP -# define BOOST_NEW_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 Oct 2002 Started update for new iterator categories -// (Jeremy Siek) -// 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 -# include -# include -# include -# include // for detail::dummy_constructor -# include -# include -# include -# include - -# include - -namespace boost { - -// Preconditions: *i == v -template -void readable_iterator_test(const Iterator i1, T v) -{ - Iterator i2(i1); // Copy Constructible - typedef typename detail::iterator_traits::reference ref_t; - ref_t r1 = *i1; - ref_t r2 = *i2; - T v1 = r1; - T v2 = r2; - assert(v1 == v); - assert(v2 == v); - -# if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407) - // I think we don't really need this as it checks the same things as - // the above code. - BOOST_STATIC_ASSERT(is_readable_iterator::value); -# endif -} - -template -void writable_iterator_test(Iterator i, T v) -{ - Iterator i2(i); // Copy Constructible - *i2 = v; -} - -template -void swappable_iterator_test(Iterator i, Iterator j) -{ - Iterator i2(i), j2(j); - typename detail::iterator_traits::value_type bi = *i, bj = *j; - iter_swap(i2, j2); - typename detail::iterator_traits::value_type ai = *i, aj = *j; - assert(bi == aj && bj == ai); -} - -template -void constant_lvalue_iterator_test(Iterator i, T v1) -{ - Iterator i2(i); - typedef typename detail::iterator_traits::value_type value_type; - typedef typename detail::iterator_traits::reference reference; - BOOST_STATIC_ASSERT((is_same::value)); - const T& v2 = *i2; - assert(v1 == v2); -# ifndef BOOST_NO_LVALUE_RETURN_DETECTION - BOOST_STATIC_ASSERT(is_lvalue_iterator::value); - BOOST_STATIC_ASSERT(!is_non_const_lvalue_iterator::value); -# endif -} - -template -void non_const_lvalue_iterator_test(Iterator i, T v1, T v2) -{ - Iterator i2(i); - typedef typename detail::iterator_traits::value_type value_type; - typedef typename detail::iterator_traits::reference reference; - BOOST_STATIC_ASSERT((is_same::value)); - T& v3 = *i2; - assert(v1 == v3); - - // A non-const lvalue iterator is not neccessarily writable, but we - // are assuming the value_type is assignable here - *i = v2; - - T& v4 = *i2; - assert(v2 == v4); -# ifndef BOOST_NO_LVALUE_RETURN_DETECTION - BOOST_STATIC_ASSERT(is_lvalue_iterator::value); - BOOST_STATIC_ASSERT(is_non_const_lvalue_iterator::value); -# endif -} - -template -void forward_readable_iterator_test(Iterator i, Iterator j, T val1, T val2) -{ - Iterator i2; - Iterator i3(i); - i2 = i; - assert(i2 == i3); - assert(i != j); - assert(i2 != j); - readable_iterator_test(i, val1); - readable_iterator_test(i2, val1); - readable_iterator_test(i3, val1); - - assert(i == i2++); - assert(i != ++i3); - - readable_iterator_test(i2, val2); - readable_iterator_test(i3, val2); - - readable_iterator_test(i, val1); -} - -template -void forward_swappable_iterator_test(Iterator i, Iterator j, T val1, T val2) -{ - forward_readable_iterator_test(i, j, val1, val2); - Iterator i2 = i; - ++i2; - swappable_iterator_test(i, i2); -} - -// bidirectional -// Preconditions: *i == v1, *++i == v2 -template -void bidirectional_readable_iterator_test(Iterator i, T v1, T v2) -{ - Iterator j(i); - ++j; - forward_readable_iterator_test(i, j, v1, v2); - ++i; - - Iterator i1 = i, i2 = i; - - assert(i == i1--); - assert(i != --i2); - - readable_iterator_test(i, v2); - readable_iterator_test(i1, v1); - readable_iterator_test(i2, v1); - - --i; - assert(i == i1); - assert(i == i2); - ++i1; - ++i2; - - readable_iterator_test(i, v1); - readable_iterator_test(i1, v2); - readable_iterator_test(i2, v2); -} - -// random access -// Preconditions: [i,i+N) is a valid range -template -void random_access_readable_iterator_test(Iterator i, int N, TrueVals vals) -{ - bidirectional_readable_iterator_test(i, vals[0], vals[1]); - const Iterator j = i; - int c; - - for (c = 0; c < N-1; ++c) - { - assert(i == j + c); - assert(*i == vals[c]); - typename detail::iterator_traits::value_type x = j[c]; - assert(*i == x); - 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]); - typename detail::iterator_traits::value_type x = j[N - 1 - c]; - assert(*i == x); - Iterator q = k - c; - assert(*i == *q); - assert(i > j); - assert(i >= j); - assert(j <= i); - assert(j < i); - --i; - } -} - -} // namespace boost - -# include - -#endif // BOOST_NEW_ITERATOR_TESTS_HPP diff --git a/include/boost/iterator/permutation_iterator.hpp b/include/boost/iterator/permutation_iterator.hpp deleted file mode 100644 index bb601c8..0000000 --- a/include/boost/iterator/permutation_iterator.hpp +++ /dev/null @@ -1,68 +0,0 @@ -// (C) Copyright Toon Knapen 2001. -// (C) Copyright David Abrahams 2003. -// (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. - -#ifndef BOOST_PERMUTATION_ITERATOR_HPP -#define BOOST_PERMUTATION_ITERATOR_HPP - -#include - -#include - - -namespace boost -{ - -template< class ElementIterator - , class IndexIterator> -class permutation_iterator - : public iterator_adaptor< - permutation_iterator - , IndexIterator, typename detail::iterator_traits::value_type - , use_default, typename detail::iterator_traits::reference> -{ - typedef iterator_adaptor< - permutation_iterator - , IndexIterator, typename detail::iterator_traits::value_type - , use_default, typename detail::iterator_traits::reference> super_t; - - friend class iterator_core_access; - -public: - permutation_iterator() : m_elt_iter() {} - - explicit permutation_iterator(ElementIterator x, IndexIterator y) - : super_t(y), m_elt_iter(x) {} - - template - permutation_iterator( - permutation_iterator const& r - , typename enable_if_convertible::type* = 0 - , typename enable_if_convertible::type* = 0 - ) - : super_t(r.base()), m_elt_iter(r.m_elt_iter) - {} - -private: - typename super_t::reference dereference() const - { return *(m_elt_iter + *this->base()); } - - ElementIterator m_elt_iter; -}; - - -template -permutation_iterator -make_permutation_iterator( ElementIterator e, IndexIterator i ) -{ - return permutation_iterator( e, i ); -} - - -} // namespace boost - -#endif diff --git a/include/boost/iterator/reverse_iterator.hpp b/include/boost/iterator/reverse_iterator.hpp deleted file mode 100644 index 43942eb..0000000 --- a/include/boost/iterator/reverse_iterator.hpp +++ /dev/null @@ -1,71 +0,0 @@ -// (C) Copyright David Abrahams 2002. -// (C) Copyright Jeremy Siek 2002. -// (C) Copyright Thomas Witt 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. -#ifndef BOOST_REVERSE_ITERATOR_23022003THW_HPP -#define BOOST_REVERSE_ITERATOR_23022003THW_HPP - -#include -#include -#include - -namespace boost -{ - - // - // - // - template - class reverse_iterator - : public iterator_adaptor< reverse_iterator, Iterator > - { - typedef iterator_adaptor< reverse_iterator, Iterator > super_t; - - friend class iterator_core_access; - - public: - reverse_iterator() {} - - explicit reverse_iterator(Iterator x) - : super_t(x) {} - - template - reverse_iterator( - reverse_iterator const& r - , typename enable_if_convertible::type* = 0 - ) - : super_t(r.base()) - {} - - private: - typename super_t::reference dereference() const { return *boost::prior(this->base()); } - - void increment() { --this->base_reference(); } - void decrement() { ++this->base_reference(); } - - void advance(typename super_t::difference_type n) - { - this->base_reference() += -n; - } - - template - typename super_t::difference_type - distance_to(reverse_iterator const& y) const - { - return this->base_reference() - y.base(); - } - }; - - template - reverse_iterator make_reverse_iterator(BidirectionalIterator x) - { - return reverse_iterator(x); - } - -} // namespace boost - -#endif // BOOST_REVERSE_ITERATOR_23022003THW_HPP diff --git a/include/boost/iterator/transform_iterator.hpp b/include/boost/iterator/transform_iterator.hpp deleted file mode 100644 index 20da1ab..0000000 --- a/include/boost/iterator/transform_iterator.hpp +++ /dev/null @@ -1,183 +0,0 @@ -// (C) Copyright David Abrahams 2002. -// (C) Copyright Jeremy Siek 2002. -// (C) Copyright Thomas Witt 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. -#ifndef BOOST_TRANSFORM_ITERATOR_23022003THW_HPP -#define BOOST_TRANSFORM_ITERATOR_23022003THW_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310)) -# include - -#endif -#include - - -namespace boost -{ - template - class transform_iterator; - - namespace detail - { - - template - struct function_object_result - { - typedef typename UnaryFunction::result_type type; - }; - -#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - template - struct function_object_result - { - typedef Return type; - }; -#endif - - // Compute the iterator_adaptor instantiation to be used for transform_iterator - template - struct transform_iterator_base - { - private: - // By default, dereferencing the iterator yields the same as - // the function. Do we need to adjust the way - // function_object_result is computed for the standard - // proposal (e.g. using Doug's result_of)? - typedef typename ia_dflt_help< - Reference - , function_object_result - >::type reference; - - // To get the default for Value: remove any reference on the - // result type, but retain any constness to signal - // non-writability. Note that if we adopt Thomas' suggestion - // to key non-writability *only* on the Reference argument, - // we'd need to strip constness here as well. - typedef typename ia_dflt_help< - Value - , remove_reference - >::type cv_value_type; - - public: - typedef iterator_adaptor< - transform_iterator - , Iterator - , cv_value_type - , use_default // Leave the traversal category alone - , reference - > type; - }; - } - - template - class transform_iterator - : public detail::transform_iterator_base::type - { - typedef typename - detail::transform_iterator_base::type - super_t; - - friend class iterator_core_access; - - public: - transform_iterator() { } - - transform_iterator(Iterator const& x, UnaryFunction f) - : super_t(x), m_f(f) { } - - explicit transform_iterator(Iterator const& x) - : super_t(x) - { - // Pro8 is a little too aggressive about instantiating the - // body of this function. -#if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) - // don't provide this constructor if UnaryFunction is a - // function pointer type, since it will be 0. Too dangerous. - BOOST_STATIC_ASSERT(is_class::value); -#endif - } - - template< - class OtherUnaryFunction - , class OtherIterator - , class OtherReference - , class OtherValue> - transform_iterator( - transform_iterator const& t - , typename enable_if_convertible::type* = 0 -#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1310) - , typename enable_if_convertible::type* = 0 -#endif - ) - : super_t(t.base()), m_f(t.functor()) - {} - - UnaryFunction functor() const - { return m_f; } - - private: - typename super_t::reference dereference() const - { return m_f(*this->base()); } - - // Probably should be the initial base class so it can be - // optimized away via EBO if it is an empty class. - UnaryFunction m_f; - }; - - template - transform_iterator - make_transform_iterator(Iterator it, UnaryFunction fun) - { - return transform_iterator(it, fun); - } - - // Version which allows explicit specification of the UnaryFunction - // type. - // - // This generator is not provided if UnaryFunction is a function - // pointer type, because it's too dangerous: the default-constructed - // function pointer in the iterator be 0, leading to a runtime - // crash. - template - typename iterators::enable_if< - is_class // We should probably find a cheaper test than is_class<> - , transform_iterator - >::type - make_transform_iterator(Iterator it) - { - return transform_iterator(it, UnaryFunction()); - } - -#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) - template - transform_iterator< Return (*)(Argument), Iterator, Return> - make_transform_iterator(Iterator it, Return (*fun)(Argument)) - { - return transform_iterator(it, fun); - } -#endif - -} // namespace boost - -#include - -#endif // BOOST_TRANSFORM_ITERATOR_23022003THW_HPP diff --git a/include/boost/iterator/zip_iterator.hpp b/include/boost/iterator/zip_iterator.hpp deleted file mode 100755 index aee58a2..0000000 --- a/include/boost/iterator/zip_iterator.hpp +++ /dev/null @@ -1,613 +0,0 @@ -// (C) Copyright David Abrahams and Thomas Becker 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. -// -// 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) - -#ifndef BOOST_ZIP_ITERATOR_TMB_07_13_2003_HPP_ - -#include -#include -#include -#include -#include // for enable_if_convertible -#include -#include - -#include - -#include - -#if BOOST_WORKAROUND(__GNUC__, == 2) || BOOST_WORKAROUND(__MWERKS__, <= 0x2407) -# include -#endif - -#include -#include -#include -#include -#include -#include -#include - -namespace boost { - - // Zip iterator forward declaration for zip_iterator_base - template - class zip_iterator; - - // One important design goal of the zip_iterator is to isolate all - // functionality whose implementation relies on the current tuple - // implementation. This goal has been achieved as follows: Inside - // the namespace detail there is a namespace tuple_impl_specific. - // This namespace encapsulates all functionality that is specific - // to the current Boost tuple implementation. More precisely, the - // namespace tuple_impl_specific provides the following tuple - // algorithms and meta-algorithms for the current Boost tuple - // implementation: - // - // tuple_meta_transform - // tuple_meta_accumulate - // tuple_transform - // tuple_for_each - // - // If the tuple implementation changes, all that needs to be - // replaced is the implementation of these four (meta-)algorithms. - - namespace detail - { - - // Functors to be used with tuple algorithms - // - template - class advance_iterator - { - public: - advance_iterator(DiffType step) : m_step(step) {} - - template - void operator()(Iterator& it) const - { it += m_step; } - - private: - DiffType m_step; - }; - // - struct increment_iterator - { - template - void operator()(Iterator& it) - { ++it; } - }; - // - struct decrement_iterator - { - template - void operator()(Iterator& it) - { --it; } - }; - // - struct dereference_iterator - { - template - struct apply - { -#if BOOST_WORKAROUND(__EDG_VERSION__, != 0) \ - || BOOST_WORKAROUND(__GNUC__, == 2) \ - || BOOST_WORKAROUND(__MWERKS__, <= 0x2407) - typedef typename - iterator_traits< - typename boost::remove_cv::type - >::reference - type; -#else - typedef typename - iterator_traits::reference - type; -#endif - }; - - template - typename apply::type operator()(Iterator& it) - { return *it; } - }; - - - // The namespace tuple_impl_specific provides two meta- - // algorithms and two algorithms for tuples. - // - namespace tuple_impl_specific - { - // Meta-transform algorithm for tuples - // - template - struct tuple_meta_transform; - - template - struct tuple_meta_transform_impl - { - typedef tuples::cons< - typename mpl::apply1< - typename mpl::lambda::type - , typename Tuple::head_type - >::type - , typename tuple_meta_transform< - typename Tuple::tail_type - , UnaryMetaFun - >::type - > type; - }; - - template - struct tuple_meta_transform - : mpl::apply_if< - boost::is_same - , mpl::identity - , tuple_meta_transform_impl - > - { - }; - - // Meta-accumulate algorithm for tuples. Note: The template - // parameter StartType corresponds to the initial value in - // ordinary accumulation. - // - template - struct tuple_meta_accumulate; - - template< - typename Tuple - , class BinaryMetaFun - , typename StartType - > - struct tuple_meta_accumulate_impl - { - typedef typename mpl::apply2< - typename mpl::lambda::type - , typename Tuple::head_type - , typename tuple_meta_accumulate< - typename Tuple::tail_type - , BinaryMetaFun - , StartType - >::type - >::type type; - }; - - template< - typename Tuple - , class BinaryMetaFun - , typename StartType - > - struct tuple_meta_accumulate - : mpl::apply_if< -#if BOOST_WORKAROUND(BOOST_MSVC, == 1200) - mpl::or_< -#endif - boost::is_same -#if BOOST_WORKAROUND(BOOST_MSVC, == 1200) - , boost::is_same - > -#endif - , mpl::identity - , tuple_meta_accumulate_impl< - Tuple - , BinaryMetaFun - , StartType - > - > - { - }; - -#if defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) \ - || ( \ - BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, != 0) && defined(_MSC_VER) \ - ) -// Not sure why intel's partial ordering fails in this case, but I'm -// assuming int's an MSVC bug-compatibility feature. - -# define BOOST_TUPLE_ALGO_DISPATCH -# define BOOST_TUPLE_ALGO(algo) algo##_impl -# define BOOST_TUPLE_ALGO_TERMINATOR , int -# define BOOST_TUPLE_ALGO_RECURSE , ... -#else -# define BOOST_TUPLE_ALGO(algo) algo -# define BOOST_TUPLE_ALGO_TERMINATOR -# define BOOST_TUPLE_ALGO_RECURSE -#endif - - // transform algorithm for tuples. The template parameter Fun - // must be a unary functor which is also a unary metafunction - // class that computes its return type based on its argument - // type. For example: - // - // struct to_ptr - // { - // template - // struct apply - // { - // typedef Arg* type; - // } - // - // template - // Arg* operator()(Arg x); - // }; - template - tuples::null_type BOOST_TUPLE_ALGO(tuple_transform) - (tuples::null_type const&, Fun BOOST_TUPLE_ALGO_TERMINATOR) - { return tuples::null_type(); } - - template - typename tuple_meta_transform< - Tuple - , Fun - >::type - - BOOST_TUPLE_ALGO(tuple_transform)( - const Tuple& t, - Fun f - BOOST_TUPLE_ALGO_RECURSE - ) - { - typedef typename tuple_meta_transform< - BOOST_DEDUCED_TYPENAME Tuple::tail_type - , Fun - >::type transformed_tail_type; - - return tuples::cons< - BOOST_DEDUCED_TYPENAME mpl::apply1< - Fun, BOOST_DEDUCED_TYPENAME Tuple::head_type - >::type - , transformed_tail_type - >( - f(boost::tuples::get<0>(t)), tuple_transform(t.get_tail(), f) - ); - } - -#ifdef BOOST_TUPLE_ALGO_DISPATCH - template - typename tuple_meta_transform< - Tuple - , Fun - >::type - - tuple_transform( - const Tuple& t, - Fun f - ) - { - return tuple_transform_impl(t, f, 1); - } -#endif - - // for_each algorithm for tuples. - // - template - Fun BOOST_TUPLE_ALGO(tuple_for_each)( - tuples::null_type - , Fun f BOOST_TUPLE_ALGO_TERMINATOR - ) - { return f; } - - - template - Fun BOOST_TUPLE_ALGO(tuple_for_each)( - Tuple& t - , Fun f BOOST_TUPLE_ALGO_RECURSE) - { - f( t.get_head() ); - return tuple_for_each(t.get_tail(), f); - } - -#ifdef BOOST_TUPLE_ALGO_DISPATCH - template - Fun - tuple_for_each( - Tuple& t, - Fun f - ) - { - return tuple_for_each_impl(t, f, 1); - } -#endif - - // Equality of tuples. NOTE: "==" for tuples currently (7/2003) - // has problems under some compilers, so I just do my own. - // No point in bringing in a bunch of #ifdefs here. This is - // going to go away with the next tuple implementation anyway. - // - bool tuple_equal(tuples::null_type, tuples::null_type) - { return true; } - - template - bool tuple_equal( - Tuple1 const& t1, - Tuple2 const& t2 - ) - { - return t1.get_head() == t2.get_head() && - tuple_equal(t1.get_tail(), t2.get_tail()); - } - } - // - // end namespace tuple_impl_specific - - template - struct iterator_reference - { - typedef typename iterator_traits::reference type; - }; - -#ifdef BOOST_MPL_NO_FULL_LAMBDA_SUPPORT - // Hack because BOOST_MPL_AUX_LAMBDA_SUPPORT doesn't seem to work - // out well. Instantiating the nested apply template also - // requires instantiating iterator_traits on the - // placeholder. Instead we just specialize it as a metafunction - // class. - template<> - struct iterator_reference - { - template - struct apply : iterator_reference {}; - }; -#endif - - // Metafunction to obtain the type of the tuple whose element types - // are the reference types of an iterator tuple. - // - template - struct tuple_of_references - : tuple_impl_specific::tuple_meta_transform< - IteratorTuple, - iterator_reference - > - { - }; - - // Metafunction to obtain the minimal traversal tag in a tuple - // of iterators. - // - template - struct minimum_traversal_category_in_iterator_tuple - { - typedef typename tuple_impl_specific::tuple_meta_transform< - IteratorTuple - , iterator_traversal<> - >::type tuple_of_traversal_tags; - - typedef typename tuple_impl_specific::tuple_meta_accumulate< - tuple_of_traversal_tags - , minimum_category<> - , random_access_traversal_tag - >::type type; - }; - -#if BOOST_WORKAROUND(BOOST_MSVC, == 1200) // ETI workaround - template <> - struct minimum_traversal_category_in_iterator_tuple - { - typedef int type; - }; -#endif - - // We need to call tuple_meta_accumulate with mpl::and_ as the - // accumulating functor. To this end, we need to wrap it into - // a struct that has exactly two arguments (that is, template - // parameters) and not five, like mpl::and_ does. - // - template - struct and_with_two_args - : mpl::and_ - { - }; - -# ifdef BOOST_MPL_NO_FULL_LAMBDA_SUPPORT - // Hack because BOOST_MPL_AUX_LAMBDA_SUPPORT doesn't seem to work - // out well. In this case I think it's an MPL bug - template<> - struct and_with_two_args - { - template - struct apply : mpl::and_ - {}; - }; -# endif - - /////////////////////////////////////////////////////////////////// - // - // Class zip_iterator_base - // - // Builds and exposes the iterator facade type from which the zip - // iterator will be derived. - // - template - struct zip_iterator_base - { - private: - // Reference type is the type of the tuple obtained from the - // iterators' reference types. - typedef typename - detail::tuple_of_references::type reference; - - // Value type is the same as reference type. - typedef reference value_type; - - // Difference type is the first iterator's difference type - typedef typename iterator_traits< - typename tuples::element<0, IteratorTuple>::type - >::difference_type difference_type; - - // Traversal catetgory is the minimum traversal category in the - // iterator tuple. - typedef typename - detail::minimum_traversal_category_in_iterator_tuple< - IteratorTuple - >::type traversal_category; - public: - - // The iterator facade type from which the zip iterator will - // be derived. - typedef iterator_facade< - zip_iterator, - value_type, - traversal_category, - reference, - difference_type - > type; - }; - - template <> - struct zip_iterator_base - { - typedef int type; - }; - } - - ///////////////////////////////////////////////////////////////////// - // - // zip_iterator class definition - // - template - class zip_iterator : - public detail::zip_iterator_base::type - { - - // Typedef super_t as our base class. - typedef typename - detail::zip_iterator_base::type super_t; - - // iterator_core_access is the iterator's best friend. - friend class iterator_core_access; - - public: - - // Construction - // ============ - - // Default constructor - zip_iterator() { } - - // Constructor from iterator tuple - zip_iterator(IteratorTuple iterator_tuple) - : m_iterator_tuple(iterator_tuple) - { } - - // Copy constructor - template - zip_iterator( - const zip_iterator& other, - typename enable_if_convertible< - OtherIteratorTuple, - IteratorTuple - >::type* = 0 - ) : m_iterator_tuple(other.get_iterator_tuple()) - {} - - // Get method for the iterator tuple. - const IteratorTuple& get_iterator_tuple() const - { return m_iterator_tuple; } - - private: - - // Implementation of Iterator Operations - // ===================================== - - // Dereferencing returns a tuple built from the dereferenced - // iterators in the iterator tuple. - typename super_t::reference dereference() const - { - return detail::tuple_impl_specific::tuple_transform( - get_iterator_tuple(), - detail::dereference_iterator() - ); - } - - // Two zip iterators are equal if all iterators in the iterator - // tuple are equal. NOTE: It should be possible to implement this - // as - // - // return get_iterator_tuple() == other.get_iterator_tuple(); - // - // but equality of tuples currently (7/2003) does not compile - // under several compilers. No point in bringing in a bunch - // of #ifdefs here. - // - template - bool equal(const zip_iterator& other) const - { - return detail::tuple_impl_specific::tuple_equal( - get_iterator_tuple(), - other.get_iterator_tuple() - ); - } - - // Advancing a zip iterator means to advance all iterators in the - // iterator tuple. - void advance(typename super_t::difference_type n) - { - detail::tuple_impl_specific::tuple_for_each( - m_iterator_tuple, - detail::advance_iterator(n) - ); - } - // Incrementing a zip iterator means to increment all iterators in - // the iterator tuple. - void increment() - { - detail::tuple_impl_specific::tuple_for_each( - m_iterator_tuple, - detail::increment_iterator() - ); - } - - // Decrementing a zip iterator means to decrement all iterators in - // the iterator tuple. - void decrement() - { - detail::tuple_impl_specific::tuple_for_each( - m_iterator_tuple, - detail::decrement_iterator() - ); - } - - // Distance is calculated using the first iterator in the tuple. - template - typename super_t::difference_type distance_to( - const zip_iterator& other - ) const - { - return boost::tuples::get<0>(other.get_iterator_tuple()) - - boost::tuples::get<0>(this->get_iterator_tuple()); - } - - // Data Members - // ============ - - // The iterator tuple. - IteratorTuple m_iterator_tuple; - - }; - - // Make function for zip iterator - // - template - zip_iterator - make_zip_iterator(IteratorTuple t) - { return zip_iterator(t); } - -} - -#endif diff --git a/include/boost/iterator_adaptors.hpp b/include/boost/iterator_adaptors.hpp deleted file mode 100644 index 6d876e7..0000000 --- a/include/boost/iterator_adaptors.hpp +++ /dev/null @@ -1,13 +0,0 @@ -// 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 - -#endif // BOOST_ITERATOR_ADAPTOR_13062003HK_HPP diff --git a/include/boost/pending/detail/int_iterator.hpp b/include/boost/pending/detail/int_iterator.hpp deleted file mode 100644 index 2d96185..0000000 --- a/include/boost/pending/detail/int_iterator.hpp +++ /dev/null @@ -1,75 +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. - -#ifndef BOOST_INT_ITERATOR_H -#define BOOST_INT_ITERATOR_H - -#include -#if !defined BOOST_MSVC -#include -#endif -#include -//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 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 -inline int_iterator -operator+(IntT n, int_iterator 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 */ diff --git a/include/boost/pending/integer_range.hpp b/include/boost/pending/integer_range.hpp deleted file mode 100644 index 81ecf4d..0000000 --- a/include/boost/pending/integer_range.hpp +++ /dev/null @@ -1,59 +0,0 @@ -// (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 -#include - -namespace boost { - -//============================================================================= -// Counting Iterator and Integer Range Class - -template -struct integer_range { - typedef counting_iterator 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 -inline integer_range -make_integer_range(IntegerType first, IntegerType last) -{ - return integer_range(first, last); -} - -} // namespace boost - -#endif // BOOST_INTEGER_RANGE_HPP_ diff --git a/include/boost/pending/iterator_adaptors.hpp b/include/boost/pending/iterator_adaptors.hpp deleted file mode 100644 index 4a3159b..0000000 --- a/include/boost/pending/iterator_adaptors.hpp +++ /dev/null @@ -1,7 +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 diff --git a/include/boost/pending/iterator_tests.hpp b/include/boost/pending/iterator_tests.hpp deleted file mode 100644 index 5be7b0f..0000000 --- a/include/boost/pending/iterator_tests.hpp +++ /dev/null @@ -1,269 +0,0 @@ -// 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 -# include -# include -# include -# include // for detail::dummy_constructor -# include -# include - -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 -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::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 -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 -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 struct lvalue_test -{ - template static void check(Iterator) - { -# ifndef BOOST_NO_STD_ITERATOR_TRAITS - typedef typename std::iterator_traits::reference reference; - typedef typename std::iterator_traits::value_type value_type; -# else - typedef typename Iterator::reference reference; - typedef typename Iterator::value_type value_type; -# endif - BOOST_STATIC_ASSERT(boost::is_reference::value); - BOOST_STATIC_ASSERT((boost::is_same::value - || boost::is_same::value - )); - } -}; - -# ifdef BOOST_NO_STD_ITERATOR_TRAITS -template <> struct lvalue_test { - template static void check(T) {} -}; -#endif - -template -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::value)>::check(i); -#endif -} - -// Preconditions: *i == v1, *++i == v2 -template -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 struct undefined; - -// Preconditions: [i,i+N) is a valid range -template -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::value_type value_type; - - for (c = 0; c < N-1; ++c) { - assert(i == j + c); - assert(*i == vals[c]); - assert(*i == boost::implicit_cast(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(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 -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 diff --git a/include/boost/shared_container_iterator.hpp b/include/boost/shared_container_iterator.hpp deleted file mode 100644 index 7d8ecd3..0000000 --- a/include/boost/shared_container_iterator.hpp +++ /dev/null @@ -1,62 +0,0 @@ -// (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 - -namespace boost { - -template -class shared_container_iterator : public iterator_adaptor< - shared_container_iterator, - typename Container::iterator> { - - typedef iterator_adaptor< - shared_container_iterator, - typename Container::iterator> super_t; - - typedef typename Container::iterator iterator_t; - typedef boost::shared_ptr 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 -shared_container_iterator -make_shared_container_iterator(typename Container::iterator iter, - boost::shared_ptr const& container) { - typedef shared_container_iterator iterator; - return iterator(iter,container); -} - - - -template -std::pair< - shared_container_iterator, - shared_container_iterator > -make_shared_container_range(boost::shared_ptr 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 diff --git a/test/Jamfile b/test/Jamfile deleted file mode 100644 index 38399b1..0000000 --- a/test/Jamfile +++ /dev/null @@ -1,60 +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 - : : : - - # stlport's debug mode generates long symbols which overwhelm - # vc6 - <*>release - ] - - # These tests should work for just about everything. - [ compile is_lvalue_iterator.cpp ] - [ compile is_readable_iterator.cpp ] - [ compile pointee.cpp ] - - [ run unit_tests.cpp ] - [ run concept_tests.cpp ] - [ run iterator_adaptor_cc.cpp ] - [ run iterator_adaptor_test.cpp ] - [ compile iterator_archetype_cc.cpp ] - [ compile-fail iterator_archetype_default_ctor.cpp ] - [ run transform_iterator_test.cpp ] - [ run indirect_iterator_test.cpp ] - [ compile indirect_iterator_member_types.cpp ] - [ run filter_iterator_test.cpp ] - [ run reverse_iterator_test.cpp ] - [ run counting_iterator_test.cpp ] - [ run interoperable.cpp ] - [ run permutation_iterator_test.cpp : : : # 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 ] - -; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 deleted file mode 100644 index 4cdb206..0000000 --- a/test/Jamfile.v2 +++ /dev/null @@ -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 : : : # 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 ] - -; diff --git a/test/concept_tests.cpp b/test/concept_tests.cpp deleted file mode 100644 index 1a1f254..0000000 --- a/test/concept_tests.cpp +++ /dev/null @@ -1,87 +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 -#include -#include - -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 -{ - 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::type tc; - boost::random_access_traversal_tag derived = tc; - (void)derived; - - boost::function_requires< - boost_concepts::WritableLvalueIteratorConcept >(); - boost::function_requires< - boost_concepts::RandomAccessTraversalConcept >(); - - boost::function_requires< - boost_concepts::ReadableLvalueIteratorConcept >(); - boost::function_requires< - boost_concepts::RandomAccessTraversalConcept >(); - - boost::function_requires< - boost_concepts::WritableLvalueIteratorConcept >(); - boost::function_requires< - boost_concepts::RandomAccessTraversalConcept >(); - - boost::function_requires< - boost_concepts::WritableLvalueIteratorConcept >(); - boost::function_requires< - boost_concepts::RandomAccessTraversalConcept >(); - - boost::function_requires< - boost_concepts::InteroperableIteratorConcept >(); - - return 0; -} diff --git a/test/counting_iterator_test.cpp b/test/counting_iterator_test.cpp deleted file mode 100644 index 73f69f9..0000000 --- a/test/counting_iterator_test.cpp +++ /dev/null @@ -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 - -#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 += n). -#endif - -#ifdef BOOST_MSVC -# pragma warning(disable:4786) // identifier truncated in debug info -#endif - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#ifndef __BORLANDC__ -# include -#endif -#include -#include -#include -#ifndef BOOST_NO_SLIST -# include -#endif - - -#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS -template -struct signed_assert_nonnegative -{ - static void test(T x) { assert(x >= 0); } -}; - -template -struct unsigned_assert_nonnegative -{ - static void test(T x) {} -}; - -template -struct assert_nonnegative - : boost::mpl::if_c< - std::numeric_limits::is_signed - , signed_assert_nonnegative - , unsigned_assert_nonnegative - >::type -{ -}; -#endif - -// Special tests for RandomAccess CountingIterators. -template -void category_test( - CountingIterator start, - CountingIterator finish, - Value, - std::random_access_iterator_tag) -{ - typedef typename - boost::detail::iterator_traits::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::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 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 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 -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 -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 -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 -void test(Incrementable start, Incrementable finish) -{ - test_aux(boost::make_counting_iterator(start), boost::make_counting_iterator(finish), start); -} - -template -void test_integer(Integer* = 0) // default arg works around MSVC bug -{ - Integer start = 0; - Integer finish = 120; - test(start, finish); -} - -template -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 iterator; - test_aux(iterator(start), iterator(finish), start); -} - -template -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(); - test_integer(); - test_integer(); - test_integer(); - test_integer(); - test_integer(); - test_integer(); - test_integer(); - test_integer(); - test_integer(); -#if defined(BOOST_HAS_LONG_LONG) - test_integer(); - test_integer(); -#endif - - // Test user-defined type. - - test_integer3(); - test_integer(); - test_integer(); - - // Some tests on container iterators, to prove we handle a few different categories - test_container >(); - test_container >(); -# ifndef BOOST_NO_SLIST - test_container >(); -# 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; -} diff --git a/test/filter_iterator_test.cpp b/test/filter_iterator_test.cpp deleted file mode 100644 index dbee3d7..0000000 --- a/test/filter_iterator_test.cpp +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright David Abrahams 2003, Jeremy Siek 2004. - -// 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 -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -using boost::dummyT; - -struct one_or_four -{ - bool operator()(dummyT x) const - { - return x.foo() == 1 || x.foo() == 4; - } -}; - -template struct undefined; - -template struct see_type; - -// Test filter iterator -int main() -{ - // Concept checks - // Adapting old-style iterators - { - typedef boost::filter_iterator > Iter; - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::SinglePassIteratorConcept >(); - } - { - typedef boost::filter_iterator > Iter; - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost::OutputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::SinglePassIteratorConcept >(); - } - { - typedef boost::filter_iterator > Iter; - boost::function_requires< boost::ForwardIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::ForwardTraversalConcept >(); - } - { - typedef boost::filter_iterator > Iter; - boost::function_requires< boost::Mutable_ForwardIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::ForwardTraversalConcept >(); - } - // Adapting new-style iterators - { - typedef boost::iterator_archetype< - const dummyT - , boost::iterator_archetypes::readable_iterator_t - , boost::single_pass_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::SinglePassIteratorConcept >(); - } - { - typedef boost::iterator_archetype< - dummyT - , boost::iterator_archetypes::readable_writable_iterator_t - , boost::single_pass_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost::OutputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::SinglePassIteratorConcept >(); - } - { - typedef boost::iterator_archetype< - const dummyT - , boost::iterator_archetypes::readable_iterator_t - , boost::forward_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::ForwardTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - dummyT - , boost::iterator_archetypes::readable_writable_iterator_t - , boost::forward_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::ForwardTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - const dummyT - , boost::iterator_archetypes::readable_lvalue_iterator_t - , boost::forward_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost::ForwardIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableLvalueIteratorConcept >(); - boost::function_requires< boost_concepts::ForwardTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - dummyT - , boost::iterator_archetypes::writable_lvalue_iterator_t - , boost::forward_traversal_tag - > BaseIter; - typedef boost::filter_iterator Iter; - boost::function_requires< boost::Mutable_ForwardIteratorConcept >(); - boost::function_requires< boost_concepts::WritableLvalueIteratorConcept >(); - boost::function_requires< boost_concepts::ForwardTraversalConcept >(); - } - - // Run-time tests - - 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 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::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 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 boost::exit_success; -} diff --git a/test/indirect_iterator_member_types.cpp b/test/indirect_iterator_member_types.cpp deleted file mode 100644 index b4013ad..0000000 --- a/test/indirect_iterator_member_types.cpp +++ /dev/null @@ -1,89 +0,0 @@ -// (C) Copyright Jeremy Siek 2004. 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 -// 03 Jan 2004 Jeremy Siek -// First draft. - - -#include -#include - -#include -#include -#include "static_assert_same.hpp" -#include - -struct zow { }; - -struct my_ptr { - typedef zow const element_type; -// typedef const zow& reference; -// typedef const zow* pointer; -// typedef void difference_type; -// typedef boost::no_traversal_tag iterator_category; -}; - -BOOST_TT_BROKEN_COMPILER_SPEC(my_ptr) -BOOST_TT_BROKEN_COMPILER_SPEC(zow) - -// Borland 5.6.4 and earlier drop const all over the place, so this -// test will fail in the lines marked with (**) - -int main() -{ - { - typedef boost::indirect_iterator Iter; - STATIC_ASSERT_SAME(Iter::value_type, int); - STATIC_ASSERT_SAME(Iter::reference, int&); - STATIC_ASSERT_SAME(Iter::pointer, int*); - STATIC_ASSERT_SAME(Iter::difference_type, std::ptrdiff_t); - - BOOST_STATIC_ASSERT((boost::is_convertible::value)); - BOOST_STATIC_ASSERT((boost::is_convertible::type, - boost::random_access_traversal_tag>::value)); - } - { - typedef boost::indirect_iterator Iter; - STATIC_ASSERT_SAME(Iter::value_type, int); - STATIC_ASSERT_SAME(Iter::reference, const int&); - STATIC_ASSERT_SAME(Iter::pointer, const int*); // (**) - } - { - typedef boost::indirect_iterator Iter; - STATIC_ASSERT_SAME(Iter::value_type, int); - STATIC_ASSERT_SAME(Iter::reference, int&); - STATIC_ASSERT_SAME(Iter::pointer, int*); - } - { - typedef boost::indirect_iterator Iter; - STATIC_ASSERT_SAME(Iter::value_type, int); - STATIC_ASSERT_SAME(Iter::reference, const int&); - STATIC_ASSERT_SAME(Iter::pointer, const int*); // (**) - } - { - typedef boost::indirect_iterator Iter; - STATIC_ASSERT_SAME(Iter::value_type, zow); - STATIC_ASSERT_SAME(Iter::reference, const zow&); // (**) - STATIC_ASSERT_SAME(Iter::pointer, const zow*); // (**) - - STATIC_ASSERT_SAME(Iter::difference_type, std::ptrdiff_t); - - BOOST_STATIC_ASSERT((boost::is_convertible::value)); - BOOST_STATIC_ASSERT((boost::is_convertible::type, - boost::random_access_traversal_tag>::value)); - } - { - typedef boost::indirect_iterator Iter; - STATIC_ASSERT_SAME(Iter::value_type, int); - STATIC_ASSERT_SAME(Iter::reference, long&); - STATIC_ASSERT_SAME(Iter::pointer, int*); - STATIC_ASSERT_SAME(Iter::difference_type, short); - } - return 0; -} diff --git a/test/indirect_iterator_test.cpp b/test/indirect_iterator_test.cpp deleted file mode 100644 index 781c226..0000000 --- a/test/indirect_iterator_test.cpp +++ /dev/null @@ -1,220 +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 -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#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 - - -template struct see_type; -template struct see_val; - -struct my_iterator_tag : public std::random_access_iterator_tag { }; - -using boost::dummyT; -BOOST_TT_BROKEN_COMPILER_SPEC(boost::shared_ptr) - -typedef std::vector storage; -typedef std::vector pointer_ra_container; -typedef std::set iterator_set; - -template -struct indirect_iterator_pair_generator -{ - typedef boost::indirect_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 indirect_ra_container; - - indirect_ra_container::iterator db(ptr_ra_container.begin()); - indirect_ra_container::iterator de(ptr_ra_container.end()); - assert(static_cast(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 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())); -} - -// element_type detector; defaults to true so the test passes when -// has_xxx isn't implemented -BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_element_type, element_type, true) - -int -main() -{ - dummyT array[] = { dummyT(0), dummyT(1), dummyT(2), - dummyT(3), dummyT(4), dummyT(5) }; - const int N = sizeof(array)/sizeof(dummyT); - -# if BOOST_WORKAROUND(BOOST_MSVC, == 1200) - boost::shared_ptr zz((dummyT*)0); // Why? I don't know, but it suppresses a bad instantiation. -# endif - - typedef std::vector > shared_t; - shared_t shared; - - // Concept checks - { - typedef boost::indirect_iterator iter_t; - - BOOST_STATIC_ASSERT( - has_element_type< - boost::detail::iterator_traits::value_type - >::value - ); - - typedef boost::indirect_iterator< - shared_t::iterator - , boost::iterator_value::type const - > c_iter_t; - -# ifndef NO_MUTABLE_CONST_RA_ITERATOR_INTEROPERABILITY - boost::function_requires< boost_concepts::InteroperableIteratorConcept >(); -# endif - } - - // Test indirect_iterator_generator - { - for (int jj = 0; jj < N; ++jj) - shared.push_back(boost::shared_ptr(new dummyT(jj))); - - dummyT* ptr[N]; - for (int k = 0; k < N; ++k) - ptr[k] = array + k; - - typedef boost::indirect_iterator indirect_iterator; - - typedef boost::indirect_iterator - const_indirect_iterator; - - indirect_iterator i(ptr); - boost::random_access_iterator_test(i, N, array); - - boost::random_access_iterator_test( - boost::indirect_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; -} diff --git a/test/interoperable.cpp b/test/interoperable.cpp deleted file mode 100755 index c228b9c..0000000 --- a/test/interoperable.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// 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) - -#include -#include -#include - -struct mutable_it : boost::iterator_adaptor -{ - typedef boost::iterator_adaptor super_t; - - mutable_it(); - explicit mutable_it(int* p) : super_t(p) {} - - bool equal(mutable_it const& rhs) const - { - return this->base() == rhs.base(); - } -}; - -struct constant_it : boost::iterator_adaptor -{ - typedef boost::iterator_adaptor super_t; - - constant_it(); - explicit constant_it(int* p) : super_t(p) {} - constant_it(mutable_it const& x) : super_t(x.base()) {} - - bool equal(constant_it const& rhs) const - { - return this->base() == rhs.base(); - } -}; - -int main() -{ - int data[] = { 49, 77 }; - - mutable_it i(data); - constant_it j(data + 1); - assert(i < j); - assert(j > i); - assert(i <= j); - assert(j >= i); - assert(j - i == 1); - assert(i - j == -1); - - constant_it k = i; - - assert(!(i < k)); - assert(!(k > i)); - assert(i <= k); - assert(k >= i); - assert(k - i == 0); - assert(i - k == 0); - - return 0; -} diff --git a/test/interoperable_fail.cpp b/test/interoperable_fail.cpp deleted file mode 100644 index d3d869d..0000000 --- a/test/interoperable_fail.cpp +++ /dev/null @@ -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 -#include -#include -#include -#include - -int main() -{ - { - typedef boost::reverse_iterator::iterator> rev_iter; - typedef boost::indirect_iterator::iterator> ind_iter; - - ind_iter() == rev_iter(); - } - - return boost::exit_success; -} diff --git a/test/is_convertible_fail.cpp b/test/is_convertible_fail.cpp deleted file mode 100644 index 7d3c9b1..0000000 --- a/test/is_convertible_fail.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int main() -{ - typedef boost::reverse_iterator rev_iter1; - typedef boost::reverse_iterator rev_iter2; - - return boost::is_convertible::value - ? boost::exit_failure : boost::exit_success; -} diff --git a/test/is_lvalue_iterator.cpp b/test/is_lvalue_iterator.cpp deleted file mode 100755 index fdace52..0000000 --- a/test/is_lvalue_iterator.cpp +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include -#include - -// Last, for BOOST_NO_LVALUE_RETURN_DETECTION -#include - -struct v -{ - v(); - ~v(); -}; - -BOOST_TT_BROKEN_COMPILER_SPEC(v) - -struct value_iterator : boost::iterator -{ - v operator*() const; -}; - -struct noncopyable_iterator : boost::iterator -{ - boost::noncopyable const& operator*() const; -}; - -template -struct proxy_iterator - : boost::iterator -{ - typedef T value_type; - -#if BOOST_WORKAROUND(__GNUC__, == 2) - typedef boost::iterator 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 -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 -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::proxy) -BOOST_TT_BROKEN_COMPILER_SPEC(proxy_iterator::proxy) - -int main() -{ - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator::iterator>::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator::const_iterator>::value); - BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator > >::value); - BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator >::value); -#ifndef BOOST_NO_LVALUE_RETURN_DETECTION - BOOST_STATIC_ASSERT(!boost::is_lvalue_iterator::value); -#endif - // Make sure inaccessible copy constructor doesn't prevent - // reference binding - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator::value); - - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - - - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator >::value); - - - - BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator::value); - BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator::iterator>::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator::const_iterator>::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator > >::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator >::value); -#ifndef BOOST_NO_LVALUE_RETURN_DETECTION - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator::value); -#endif - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator::value); - - BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator >::value); -#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) - BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator >::value); -#endif - BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator >::value); - - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator >::value); - BOOST_STATIC_ASSERT(!boost::is_non_const_lvalue_iterator >::value); - - return 0; -} diff --git a/test/is_readable_iterator.cpp b/test/is_readable_iterator.cpp deleted file mode 100755 index 15ed099..0000000 --- a/test/is_readable_iterator.cpp +++ /dev/null @@ -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 -#include -#include -#include -#include -#include -#include -#include - -// Last, for BOOST_NO_LVALUE_RETURN_DETECTION -#include - -struct v -{ - v(); - ~v(); -}; - -BOOST_TT_BROKEN_COMPILER_SPEC(v) - -struct value_iterator : boost::iterator -{ - v operator*() const; -}; - -struct noncopyable_iterator : boost::iterator -{ - boost::noncopyable const& operator*() const; -}; - -struct proxy_iterator : boost::iterator -{ -#if BOOST_WORKAROUND(__GNUC__, == 2) - typedef boost::iterator 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 -{ -#if BOOST_WORKAROUND(__GNUC__, == 2) - typedef boost::iterator 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::value); - BOOST_STATIC_ASSERT(boost::is_readable_iterator::value); - BOOST_STATIC_ASSERT(boost::is_readable_iterator::iterator>::value); - BOOST_STATIC_ASSERT(boost::is_readable_iterator::const_iterator>::value); - BOOST_STATIC_ASSERT(!boost::is_readable_iterator > >::value); - BOOST_STATIC_ASSERT(!boost::is_readable_iterator >::value); - BOOST_STATIC_ASSERT(boost::is_readable_iterator::value); - BOOST_STATIC_ASSERT(!boost::is_readable_iterator::value); - BOOST_STATIC_ASSERT(boost::is_readable_iterator::value); - - // Make sure inaccessible copy constructor doesn't prevent - // readability - BOOST_STATIC_ASSERT(boost::is_readable_iterator::value); - - return 0; -} diff --git a/test/iterator_adaptor_cc.cpp b/test/iterator_adaptor_cc.cpp deleted file mode 100644 index b02c824..0000000 --- a/test/iterator_adaptor_cc.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include -#include -#include - -int main() -{ - { - typedef boost::reverse_iterator rev_iter; - typedef boost::reverse_iterator c_rev_iter; - - boost::function_requires< boost_concepts::WritableLvalueIteratorConcept >(); - boost::function_requires< boost_concepts::RandomAccessTraversalConcept >(); - boost::function_requires< boost::RandomAccessIteratorConcept >(); - boost::function_requires< boost_concepts::InteroperableIteratorConcept >(); - } - { - typedef boost::reverse_iterator::iterator> rev_iter; - typedef boost::reverse_iterator::const_iterator> c_rev_iter; - - boost::function_requires< boost_concepts::ReadableLvalueIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - boost::function_requires< boost::BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::InteroperableIteratorConcept >(); - } - - return boost::exit_success; -} diff --git a/test/iterator_adaptor_test.cpp b/test/iterator_adaptor_test.cpp deleted file mode 100644 index ca39a87..0000000 --- a/test/iterator_adaptor_test.cpp +++ /dev/null @@ -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 -#include - -#include -#include -#include - -#include -#if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407) -# include -# include -#endif -#include - -# include - -#include -#include -#include -#include -#include - -#include "static_assert_same.hpp" - -#include - -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 -struct select1st_ - : public std::unary_function -{ - 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 storage; -typedef std::deque pointer_deque; -typedef std::set iterator_set; - -template struct foo; - -void blah(int) { } - -struct my_gen -{ - typedef int result_type; - my_gen() : n(0) { } - int operator()() { return ++n; } - int n; -}; - -template -struct ptr_iterator - : boost::iterator_adaptor< - ptr_iterator - , 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 - , 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 - ptr_iterator( - const ptr_iterator& x - , typename boost::enable_if_convertible::type* = 0 - ) - : super_t(x.base()) - {} -}; - -// Non-functional iterator for category modification checking -template -struct modify_traversal - : boost::iterator_adaptor< - modify_traversal - , Iter - , boost::use_default - , Traversal - > -{}; - -template -struct fwd_iterator - : boost::iterator_adaptor< - fwd_iterator - , boost::forward_iterator_archetype - > -{ -private: - typedef boost::iterator_adaptor< - fwd_iterator - , boost::forward_iterator_archetype - > super_t; - -public: - fwd_iterator() { } - fwd_iterator(boost::forward_iterator_archetype d) : super_t(d) { } -}; - -template -struct in_iterator - : boost::iterator_adaptor< - in_iterator - , boost::input_iterator_archetype_no_proxy - > -{ -private: - typedef boost::iterator_adaptor< - in_iterator - , boost::input_iterator_archetype_no_proxy - > super_t; - -public: - in_iterator() { } - in_iterator(boost::input_iterator_archetype_no_proxy d) : super_t(d) { } -}; - -template -struct constant_iterator - : boost::iterator_adaptor< - constant_iterator - , Iter - , typename std::iterator_traits::value_type const - > -{ - typedef boost::iterator_adaptor< - constant_iterator - , Iter - , typename std::iterator_traits::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 -struct traversal3 -{ - static typename boost::iterator_category_to_traversal::type x; - BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(traversal2(x))); - typedef char (&type)[value]; -}; - -template -typename traversal3::type traversal(Cat); - -template -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::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 i(array); - boost::random_access_iterator_test(i, N, array); - - ptr_iterator 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 Iter1; - // don't use std::iterator_traits here to avoid VC++ problems - test = static_assert_same::value; - test = static_assert_same::value; - test = static_assert_same::value; - test = static_assert_same::value; -#if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407) - BOOST_STATIC_ASSERT((boost::is_convertible::value)); -#endif - } - - { - // Test computation of default when the Value is const - typedef ptr_iterator Iter1; - test = static_assert_same::value; - test = static_assert_same::value; - -#if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407) - BOOST_STATIC_ASSERT(boost::is_readable_iterator::value); -# ifndef BOOST_NO_LVALUE_RETURN_DETECTION - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator::value); -# endif -#endif - -#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) // borland drops constness - test = static_assert_same::value; -#endif - } - - { - // Test constant iterator idiom - typedef ptr_iterator BaseIter; - typedef constant_iterator Iter; - - test = static_assert_same::value; - test = static_assert_same::value; -#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) // borland drops constness - test = static_assert_same::value; -#endif - -#ifndef BOOST_NO_LVALUE_RETURN_DETECTION - BOOST_STATIC_ASSERT(boost::is_non_const_lvalue_iterator::value); - BOOST_STATIC_ASSERT(boost::is_lvalue_iterator::value); -#endif - - typedef modify_traversal IncrementableIter; - - static_assert_traversal(); - static_assert_traversal(); - } - - // Test the iterator_adaptor - { - ptr_iterator i(array); - boost::random_access_iterator_test(i, N, array); - - ptr_iterator 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 forward_iter; - - typedef fwd_iterator 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_no_proxy input_iter; - typedef in_iterator 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; -} diff --git a/test/iterator_archetype_cc.cpp b/test/iterator_archetype_cc.cpp deleted file mode 100644 index d5409ce..0000000 --- a/test/iterator_archetype_cc.cpp +++ /dev/null @@ -1,60 +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 -#include -#include -#include -#include - -int main() -{ - { - typedef boost::iterator_archetype< - int - , boost::iterator_archetypes::readable_iterator_t - , boost::random_access_traversal_tag - > iter; - - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::RandomAccessTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - int - , boost::iterator_archetypes::readable_writable_iterator_t - , boost::random_access_traversal_tag - > iter; - - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::RandomAccessTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - const int // I don't like adding const to Value. It is redundant. -JGS - , boost::iterator_archetypes::readable_lvalue_iterator_t - , boost::random_access_traversal_tag - > iter; - - boost::function_requires< boost_concepts::ReadableLvalueIteratorConcept >(); - boost::function_requires< boost_concepts::RandomAccessTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - int - , boost::iterator_archetypes::writable_lvalue_iterator_t - , boost::random_access_traversal_tag - > iter; - - boost::function_requires< boost_concepts::WritableLvalueIteratorConcept >(); - boost::function_requires< boost_concepts::RandomAccessTraversalConcept >(); - } - - return boost::exit_success; -} - diff --git a/test/iterator_archetype_default_ctor.cpp b/test/iterator_archetype_default_ctor.cpp deleted file mode 100755 index fd10b35..0000000 --- a/test/iterator_archetype_default_ctor.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// -// Copyright Thomas Witt 2004. 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 - - -int main() -{ - typedef boost::iterator_archetype< - int - , boost::iterator_archetypes::readable_iterator_t - , boost::single_pass_traversal_tag - > iter; - - // single_pass_traversal iterators are not required to be - // default constructible - iter it; -} diff --git a/test/permutation_iterator_test.cpp b/test/permutation_iterator_test.cpp deleted file mode 100644 index ad23300..0000000 --- a/test/permutation_iterator_test.cpp +++ /dev/null @@ -1,85 +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 -#include - -#include -#include - -#include -#include - -#include - - -void permutation_test() -{ - // Example taken from documentation of old permutation_iterator. - typedef std::vector< double > 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, ++++it ) - { - index_type::iterator i_it2 = indices.begin(); - std::advance( i_it2, i1 ); - BOOST_CHECK( *it == elements[ *i_it2 ] ); - } - - it = begin; - std::advance(it, index_size); - for( index_type::iterator i_it3 = indices.end(); it != begin; ) - { - BOOST_CHECK( *--it == elements[ *--i_it3 ] ); - } - - it = begin; - std::advance(it, 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; -} diff --git a/test/pointee.cpp b/test/pointee.cpp deleted file mode 100755 index b39fce1..0000000 --- a/test/pointee.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// 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) - -#include -#include -#include "static_assert_same.hpp" -#include -#include - -template -struct proxy_ptr -{ - typedef T element_type; - struct proxy - { - operator Ref() const; - }; - proxy operator*() const; -}; - -template -struct proxy_ref_ptr : proxy_ptr -{ -}; - -template -struct proxy_value_ptr : proxy_ptr -{ - typedef typename boost::add_const::type element_type; -}; - -struct X { - template X(T const&); - template operator T&() const; -}; - -BOOST_TT_BROKEN_COMPILER_SPEC(X) - -int main() -{ - STATIC_ASSERT_SAME(boost::pointee >::type, int); - STATIC_ASSERT_SAME(boost::pointee >::type, X); - - STATIC_ASSERT_SAME(boost::pointee >::type, int const); - STATIC_ASSERT_SAME(boost::pointee >::type, X const); - - STATIC_ASSERT_SAME(boost::pointee >::type, int const); - STATIC_ASSERT_SAME(boost::pointee >::type, X const); - - STATIC_ASSERT_SAME(boost::pointee >::type, int const); - STATIC_ASSERT_SAME(boost::pointee >::type, X const); - - STATIC_ASSERT_SAME(boost::pointee::type, int); - STATIC_ASSERT_SAME(boost::pointee::type, int const); - - STATIC_ASSERT_SAME(boost::pointee::type, X); - STATIC_ASSERT_SAME(boost::pointee::type, X const); - - STATIC_ASSERT_SAME(boost::pointee >::type, int); - STATIC_ASSERT_SAME(boost::pointee >::type, X); - - STATIC_ASSERT_SAME(boost::pointee >::type, int const); - STATIC_ASSERT_SAME(boost::pointee >::type, X const); - - STATIC_ASSERT_SAME(boost::pointee::iterator >::type, int); - STATIC_ASSERT_SAME(boost::pointee::iterator >::type, X); - - STATIC_ASSERT_SAME(boost::pointee::const_iterator >::type, int const); - STATIC_ASSERT_SAME(boost::pointee::const_iterator >::type, X const); - return 0; -} diff --git a/test/reverse_iterator_test.cpp b/test/reverse_iterator_test.cpp deleted file mode 100644 index 85ea467..0000000 --- a/test/reverse_iterator_test.cpp +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright Thomas Witt 2003, Jeremy Siek 2004. - -// 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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); - - // Concept checks - // Adapting old-style iterators - { - typedef boost::reverse_iterator > Iter; - boost::function_requires< boost::BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableLvalueIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - { - typedef boost::reverse_iterator > Iter; - boost::function_requires< boost::Mutable_BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::WritableLvalueIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - // Adapting new-style iterators - { - typedef boost::iterator_archetype< - const dummyT - , boost::iterator_archetypes::readable_iterator_t - , boost::bidirectional_traversal_tag - > Iter; - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - dummyT - , boost::iterator_archetypes::writable_iterator_t - , boost::bidirectional_traversal_tag - > Iter; - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - dummyT - , boost::iterator_archetypes::readable_writable_iterator_t - , boost::bidirectional_traversal_tag - > Iter; - boost::function_requires< boost::InputIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableIteratorConcept >(); - boost::function_requires< boost_concepts::WritableIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - const dummyT - , boost::iterator_archetypes::readable_lvalue_iterator_t - , boost::bidirectional_traversal_tag - > Iter; - boost::function_requires< boost::BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::ReadableLvalueIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - { - typedef boost::iterator_archetype< - dummyT - , boost::iterator_archetypes::writable_lvalue_iterator_t - , boost::bidirectional_traversal_tag - > Iter; - boost::function_requires< boost::BidirectionalIteratorConcept >(); - boost::function_requires< boost_concepts::WritableLvalueIteratorConcept >(); - boost::function_requires< boost_concepts::BidirectionalTraversalConcept >(); - } - - // Test reverse_iterator - { - dummyT reversed[N]; - std::copy(array, array + N, reversed); - std::reverse(reversed, reversed + N); - - typedef boost::reverse_iterator 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_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 again, with traits fully deducible on all platforms - { - std::deque reversed_container; - std::reverse_copy(array, array + N, std::back_inserter(reversed_container)); - const std::deque::iterator reversed = reversed_container.begin(); - - - typedef boost::reverse_iterator< - std::deque::iterator> reverse_iterator; - typedef boost::reverse_iterator< - std::deque::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::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::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(__GNUC__, == 3) && BOOST_WORKAROUND(__GNUC_MINOR__, <= 1)) \ - && !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 - } - - std::cout << "test successful " << std::endl; - return boost::exit_success; -} diff --git a/test/static_assert_same.hpp b/test/static_assert_same.hpp deleted file mode 100644 index 0b4b04c..0000000 --- a/test/static_assert_same.hpp +++ /dev/null @@ -1,40 +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 -# include - -#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -template -struct static_assert_same_base; - -template -struct static_assert_same_base -{ - enum { value = 1 }; -}; - -template -struct static_assert_same : static_assert_same_base {}; - -#else -# include -# include -# include - -template -struct static_assert_same - : boost::mpl::if_,boost::mpl::true_,void>::type -{}; -#endif - -#define STATIC_ASSERT_SAME( T1,T2 ) \ - enum { BOOST_JOIN(boost_static_assert_enum_, __LINE__) \ - = static_assert_same::value } - -#endif // STATIC_ASSERT_SAME_DWA2003530_HPP diff --git a/test/transform_iterator_test.cpp b/test/transform_iterator_test.cpp deleted file mode 100644 index 6c02a26..0000000 --- a/test/transform_iterator_test.cpp +++ /dev/null @@ -1,251 +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 -#include -#include -#include -#include -#include -#include -#include -#include - - -#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION -namespace boost { namespace detail -{ - template<> struct function_object_result - { - 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 const_select_first -{ - typedef int const& result_type; - - int const& operator()(std::pairconst& p) const - { - return p.first; - } -}; - -struct select_first - : const_select_first // derivation to allow conversions -{ - typedef int& result_type; - - int& operator()(std::pair& p) const - { - return p.first; - } -}; - -struct select_second -{ - typedef int& result_type; - - int& operator()(std::pair& p) const - { - return p.second; - } -}; - -struct value_select_first -{ - typedef int result_type; - - int operator()(std::pairconst& 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 iter_t; - typedef boost::transform_iterator c_iter_t; - - boost::function_requires< boost_concepts::InteroperableIteratorConcept >(); - } - - // 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 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 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 iter_t; - BOOST_STATIC_ASSERT((boost::is_same::value)); - BOOST_STATIC_ASSERT((boost::is_same::value)); - } - - { - typedef boost::transform_iterator iter_t; - BOOST_STATIC_ASSERT((boost::is_same::value)); - BOOST_STATIC_ASSERT((boost::is_same::value)); - } - - { - typedef boost::transform_iterator iter_t; - BOOST_STATIC_ASSERT((boost::is_same::value)); - BOOST_STATIC_ASSERT((boost::is_same::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 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); - - boost::const_nonconst_iterator_test( - ++boost::make_transform_iterator((pair_t*)values, select_first()) - , boost::make_transform_iterator((pair_t*)values, const_select_first()) - ); - } - - std::cout << "test successful " << std::endl; - return 0; -} diff --git a/test/unit_tests.cpp b/test/unit_tests.cpp deleted file mode 100644 index c4077eb..0000000 --- a/test/unit_tests.cpp +++ /dev/null @@ -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 -#include - -#include "static_assert_same.hpp" - -#include - -#include - -struct X { int a; }; - -BOOST_TT_BROKEN_COMPILER_SPEC(X) - -struct Xiter : boost::iterator_adaptor -{ - Xiter(); - Xiter(X* p) : boost::iterator_adaptor(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 -struct static_assert_min_cat - : static_assert_same< - typename boost::detail::minimum_category::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; -} - diff --git a/test/zip_iterator_test.cpp b/test/zip_iterator_test.cpp deleted file mode 100755 index 274f7ac..0000000 --- a/test/zip_iterator_test.cpp +++ /dev/null @@ -1,911 +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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -template -struct pure_traversal - : boost::detail::pure_traversal_tag< - typename boost::iterator_traversal::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 mytuple; - mytuple t1; - boost::tuples::get<0>(t1) = 42; - boost::tuples::get<1>(t1) = 42.1; - - if( 2 == boost::tuples::length::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 s; - s.insert(42); - s.insert(43); - s.insert(44); - - typedef boost::transform_iterator< - std::binder1st >, - std::set::iterator - > - add_seven_iterator; - - typedef boost::transform_iterator< - std::binder1st >, - std::set::const_iterator - > - const_add_seven_iterator; - - add_seven_iterator set_run(s.begin(), std::bind1st(std::plus(), 7)); - add_seven_iterator set_end(s.end(), std::bind1st(std::plus(), 7)); - - const_add_seven_iterator const_set_run(s.begin(), std::bind1st(std::plus(), 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 vect1(3); - vect1[0] = 42.; - vect1[1] = 43.; - vect1[2] = 44.; - - std::set intset; - intset.insert(52); - intset.insert(53); - intset.insert(54); - // - - boost::zip_iterator< - boost::tuples::tuple< - std::set::iterator - , std::vector::iterator - > - > - zip_it_mixed( - boost::make_tuple( - intset.begin() - , vect1.begin() - ) - ); - - boost::tuples::tuple val_tuple( - *zip_it_mixed); - - boost::tuples::tuple 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 li1; - li1.push_back(1); - std::set se1; - se1.insert(2); - std::vector ve1; - ve1.push_back(3); - // - std::list li2; - li2.push_back(4); - std::set se2; - se2.insert(5); - std::vector ve2; - ve2.push_back(6); - // - std::list li3; - li3.push_back(7); - std::set se3; - se3.insert(8); - std::vector ve3; - ve3.push_back(9); - // - std::list li4; - li4.push_back(10); - std::set se4; - se4.insert(11); - std::vector ve4; - ve4.push_back(12); - - // typedefs for cons lists of iterators. - typedef boost::tuples::cons< - std::set::iterator, - boost::tuples::tuple< - std::vector::iterator, - std::list::iterator, - std::set::iterator, - std::vector::iterator, - std::list::iterator, - std::set::iterator, - std::vector::iterator, - std::list::iterator, - std::set::iterator, - std::vector::const_iterator - >::inherited - > cons_11_its_type; - // - typedef boost::tuples::cons< - std::list::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 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 vect2(3); - vect2[0] = 2.2; - vect2[1] = 3.3; - vect2[2] = 4.4; - - boost::zip_iterator< - boost::tuples::tuple< - std::vector::const_iterator, - std::vector::const_iterator - > - > - zip_it_begin( - boost::make_tuple( - vect1.begin(), - vect2.begin() - ) - ); - - boost::zip_iterator< - boost::tuples::tuple< - std::vector::const_iterator, - std::vector::const_iterator - > - > - zip_it_run( - boost::make_tuple( - vect1.begin(), - vect2.begin() - ) - ); - - boost::zip_iterator< - boost::tuples::tuple< - std::vector::const_iterator, - std::vector::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::const_iterator, - std::vector::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 > - 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::const_iterator, - std::vector::const_iterator - > - > - zip_it_const( - boost::make_tuple( - intset.begin(), - vect2.begin() - ) - ); - // - boost::zip_iterator< - boost::tuples::tuple< - std::set::iterator, - std::vector::const_iterator - > - > - zip_it_half_const( - boost::make_tuple( - intset.begin(), - vect2.begin() - ) - ); - // - boost::zip_iterator< - boost::tuples::tuple< - std::set::iterator, - std::vector::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::type - , boost::bidirectional_traversal_tag - >::value; - - bool bBigItIsRandomAccessIterator = boost::is_convertible< - boost::iterator_traversal::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::const_iterator, - std::vector::const_iterator - > - > all_vects_type; - - bool bAllVectsIsRandomAccessIterator = boost::is_convertible< - boost::iterator_traversal::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(num_successful_tests) - << "\nNumber of failed tests: " << static_cast(num_failed_tests) - << std::endl; - - return num_failed_tests; -} -