diff --git a/doc/counting_iterator.html b/doc/counting_iterator.html index cc6303d..6f9e8b4 100644 --- a/doc/counting_iterator.html +++ b/doc/counting_iterator.html @@ -3,240 +3,13 @@ - + Counting Iterator - +
@@ -435,11 +208,5 @@ indirectly printing out the numbers from 0 to 7
- - diff --git a/doc/counting_iterator_eg.rst b/doc/counting_iterator_eg.rst index 98d27ec..a5e6baa 100644 --- a/doc/counting_iterator_eg.rst +++ b/doc/counting_iterator_eg.rst @@ -1,6 +1,6 @@ Example -------- +....... This example fills an array with numbers and a second array with pointers into the first array, using ``counting_iterator`` for both diff --git a/doc/counting_iterator_ref.rst b/doc/counting_iterator_ref.rst index 42d283a..4d5b46d 100644 --- a/doc/counting_iterator_ref.rst +++ b/doc/counting_iterator_ref.rst @@ -22,7 +22,7 @@ the cases when the ``Incrementable`` type is a numeric type.] ``counting_iterator`` requirements ----------------------------------- +.................................. The ``Incrementable`` type must be Default Constructible, Copy Constructible, and Assignable. The default distance is @@ -30,7 +30,7 @@ an implementation defined signed integral type. ``counting_iterator`` models ----------------------------- +............................ ``counting_iterator`` models Readable Lvalue Iterator. @@ -59,7 +59,7 @@ required:: ``counting_iterator`` operations --------------------------------- +................................ ``counting_iterator();`` diff --git a/doc/facade-and-adaptor.html b/doc/facade-and-adaptor.html index 7db6b6b..c724be1 100755 --- a/doc/facade-and-adaptor.html +++ b/doc/facade-and-adaptor.html @@ -3,239 +3,12 @@ - + Iterator Facade and Adaptor - +
@@ -332,36 +105,34 @@ by adapting other iterators.
  • Reverse iterator -
  • reverse_iterator requirements
  • reverse_iterator models
  • reverse_iterator operations
  • -
  • Transform iterator
  • +
  • Transform iterator
  • Motivation

    @@ -1655,21 +1428,20 @@ private: };
    -
    -

    reverse_iterator requirements

    +

    reverse_iterator requirements

    The base Iterator must be a model of Bidirectional Traversal Iterator and Readable Iterator.

    -

    reverse_iterator models

    +

    reverse_iterator models

    reverse_iterator models Bidirectional Traversal Iterator and Readable Iterator. In addition, reverse_iterator models the same standard iterator access concepts that the Iterator argument models.

    -

    reverse_iterator operations

    +

    reverse_iterator operations

    reverse_iterator();

    @@ -1720,7 +1492,7 @@ reverse_iterator(
     Iterator tmp = current;
    -return *--tmp;
    +return *..tmp;
     

    reverse_iterator& operator++();

    @@ -1734,6 +1506,7 @@ return *--tmp;
    +

    Transform iterator

    The transform iterator adapts an iterator by applying some function @@ -1772,9 +1545,8 @@ private: };

    -
    -

    transform_iterator requirements

    +

    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 @@ -1783,7 +1555,7 @@ where the type of f(*i) must b

    The type Iterator must at least model Readable Iterator.

    -

    transform_iterator models

    +

    transform_iterator models

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

    @@ -1801,7 +1573,7 @@ concept that is modeled by Iterator The value_type is remove_cv<remove_reference<reference> >::type.

    -

    transform_iterator operations

    +

    transform_iterator operations

    transform_iterator();

    @@ -1878,6 +1650,7 @@ transform_iterator(
    +

    Filter iterator

    The filter iterator adaptor creates a view of an iterator range in @@ -1921,9 +1694,8 @@ class filter_iterator corresponding to each standard concept modeled by filter_iterator, as described in the models section.

    -
    -

    filter_iterator requirements

    +

    filter_iterator requirements

    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 @@ -1934,7 +1706,7 @@ Iterator and Single Pass Iterator or it shall meet the requirements of Input Iterator.

    -

    filter_iterator models

    +

    filter_iterator models

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

    @@ -2003,7 +1775,7 @@ following tables.

    -

    filter_iterator operations

    +

    filter_iterator operations

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

    @@ -2106,6 +1878,7 @@ or f(**this) ==
    +

    Counting iterator

    counting_iterator adapts an arithmetic type, such as int, by @@ -2135,15 +1908,14 @@ class counting_iterator the cases when the Incrementable type is a numeric type.]

    -
    -

    counting_iterator requirements

    +

    counting_iterator requirements

    The Incrementable type must be Default Constructible, Copy Constructible, and Assignable. The default distance is an implementation defined signed integral type.

    -

    counting_iterator models

    +

    counting_iterator models

    counting_iterator models Readable Lvalue Iterator.

    Furthermore, if you wish to create a counting iterator that is a Forward Traversal Iterator, then the following expressions must be valid:

    @@ -2168,7 +1940,7 @@ i < j
    -

    counting_iterator operations

    +

    counting_iterator operations

    counting_iterator();

    @@ -2225,6 +1997,7 @@ constructed from x.
    +

    Function output iterator

    The function output iterator adaptor makes it easier to create custom @@ -2261,9 +2034,8 @@ public: };

    -
    -

    function_output_iterator requirements

    +

    function_output_iterator requirements

    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. @@ -2271,7 +2043,7 @@ The resulting function_output_iterator

    -

    function_output_iterator operations

    +

    function_output_iterator operations

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

    @@ -2312,7 +2084,7 @@ a copy of the unary function f
    -

    function_output_iterator::output_proxy operations

    +

    function_output_iterator::output_proxy operations

    output_proxy(UnaryFunction& f);

    @@ -2346,11 +2118,6 @@ LocalWords: OtherIncrementable Coplien --> - - diff --git a/doc/filter_iterator.html b/doc/filter_iterator.html index 47f0f6d..0aa7457 100644 --- a/doc/filter_iterator.html +++ b/doc/filter_iterator.html @@ -3,240 +3,13 @@ - +Filter Iterator - +
    @@ -307,8 +80,13 @@ class filter_iterator ); Predicate predicate() const; Iterator end() const; + Iterator base() const; reference operator*() const; filter_iterator& operator++(); +private: + Predicate m_pred; // exposition + Iterator m_iter; // exposition + Iterator m_end; // exposition };

    The iterator_category member is a type convertible to the tags @@ -406,9 +184,8 @@ operations.

    - +
    Requires:Predicate and Iterator must be Default Constructible.
    Returns:a filter_iterator whose -predicate is a default constructed Predicate and -whose end is a default constructed Iterator.
    Returns:a filter_iterator whose``m_pred``, m_iter, and m_end +members are a default constructed.
    @@ -417,8 +194,10 @@ whose end is a default constru -Returns:A filter_iterator at the first position in the range [x,end) -such that f(*this->base()) == true or else at position end. +Returns: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. @@ -429,13 +208,9 @@ such that f(*this->base()) Requires:Predicate must be Default Constructible. -Returns:A filter_iterator at the first position in the range [x,end) -such that f(*this->base()) == true, where f is a default -constructed Predicate, or else at position end. - -Returns:A filter_iterator at position x that filters -according to a default constructed Predicate -and that will not increment past end. +Returns: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. @@ -452,8 +227,7 @@ filter_iterator( Requires:OtherIterator is implicitly convertible to Iterator. -Returns:A filter iterator at the same position as iterator t -whose predicate and end are copies of t.predicate and t.end() . +Returns:A filter iterator whose members are copied from t. @@ -462,7 +236,7 @@ whose predicate and end are copies of t.pr -Returns:A copy of the predicate object used to construct *this. +Returns:m_pred @@ -471,7 +245,16 @@ whose predicate and end are copies of t.pr -Returns:A copy of the object end used to construct *this. +Returns:m_end + + + +

    Iterator base() const;

    + +++ +
    Returns:m_iterator
    @@ -480,7 +263,7 @@ whose predicate and end are copies of t.pr -Returns:*(this->base()) +Returns:*m_iter @@ -489,9 +272,9 @@ whose predicate and end are copies of t.pr -Effects:Increments *this and then continues to -increment *this until either this->base() == this->end() -or f(**this) == true. +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 @@ -591,11 +374,5 @@ int main()
    - - diff --git a/doc/filter_iterator_eg.rst b/doc/filter_iterator_eg.rst index 6b3f4af..9b19db3 100644 --- a/doc/filter_iterator_eg.rst +++ b/doc/filter_iterator_eg.rst @@ -1,6 +1,6 @@ Example -------- +....... This example uses ``filter_iterator`` and then ``make_filter_iterator`` to output only the positive integers from an diff --git a/doc/filter_iterator_ref.rst b/doc/filter_iterator_ref.rst index 5321053..c668555 100644 --- a/doc/filter_iterator_ref.rst +++ b/doc/filter_iterator_ref.rst @@ -20,8 +20,13 @@ ); Predicate predicate() const; Iterator end() const; + Iterator base() const; reference operator*() const; filter_iterator& operator++(); + private: + Predicate m_pred; // exposition + Iterator m_iter; // exposition + Iterator m_end; // exposition }; @@ -32,7 +37,7 @@ as described in the models section. ``filter_iterator`` requirements --------------------------------- +................................ The ``Predicate`` argument must be Assignable, Copy Constructible, and the expression ``p(x)`` must be valid where ``p`` is an object of type @@ -47,7 +52,7 @@ Input Iterator. ``filter_iterator`` models --------------------------- +.......................... The concepts that ``filter_iterator`` models are dependent on what concepts the ``Iterator`` argument models, as specified in the @@ -83,7 +88,7 @@ following tables. ``filter_iterator`` operations ------------------------------- +.............................. In addition to those operations required by the concepts that ``filter_iterator`` models, ``filter_iterator`` provides the following @@ -93,28 +98,25 @@ operations. ``filter_iterator();`` :Requires: ``Predicate`` and ``Iterator`` must be Default Constructible. -:Returns: a ``filter_iterator`` whose - predicate is a default constructed ``Predicate`` and - whose ``end`` is a default constructed ``Iterator``. +:Returns: 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());`` -:Returns: A ``filter_iterator`` at the first position in the range ``[x,end)`` - such that ``f(*this->base()) == true`` or else at position ``end``. +:Returns: 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. -:Returns: A ``filter_iterator`` at the first position in the range ``[x,end)`` - such that ``f(*this->base()) == true``, where ``f`` is a default - constructed ``Predicate``, or else at position ``end``. - - -:Returns: A ``filter_iterator`` at position ``x`` that filters - according to a default constructed ``Predicate`` - and that will not increment past ``end``. +:Returns: 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. :: @@ -126,29 +128,33 @@ operations. );`` :Requires: ``OtherIterator`` is implicitly convertible to ``Iterator``. -:Returns: A filter iterator at the same position as iterator ``t`` - whose predicate and end are copies of ``t.predicate`` and ``t.end()`` . +:Returns: A filter iterator whose members are copied from ``t``. ``Predicate predicate() const;`` -:Returns: A copy of the predicate object used to construct ``*this``. +:Returns: ``m_pred`` ``Iterator end() const;`` -:Returns: A copy of the object ``end`` used to construct ``*this``. +:Returns: ``m_end`` + + +``Iterator base() const;`` + +:Returns: ``m_iterator`` ``reference operator*() const;`` -:Returns: ``*(this->base())`` +:Returns: ``*m_iter`` ``filter_iterator& operator++();`` -:Effects: Increments ``*this`` and then continues to - increment ``*this`` until either ``this->base() == this->end()`` - or ``f(**this) == true``. +: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`` \ No newline at end of file diff --git a/doc/function_output_iterator.html b/doc/function_output_iterator.html index d1fedc3..9349fb0 100644 --- a/doc/function_output_iterator.html +++ b/doc/function_output_iterator.html @@ -3,240 +3,13 @@ - + Function Output Iterator - +
    @@ -381,12 +155,41 @@ return *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 index d1740fb..918ec79 100644 --- a/doc/function_output_iterator.rst +++ b/doc/function_output_iterator.rst @@ -21,3 +21,4 @@ .. 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_eg.rst b/doc/function_output_iterator_eg.rst new file mode 100644 index 0000000..eb635df --- /dev/null +++ b/doc/function_output_iterator_eg.rst @@ -0,0 +1,35 @@ +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 index bee8a60..25b70a5 100644 --- a/doc/function_output_iterator_ref.rst +++ b/doc/function_output_iterator_ref.rst @@ -25,7 +25,7 @@ ``function_output_iterator`` requirements ------------------------------------------ +......................................... The ``UnaryFunction`` must be Assignable, Copy Constructible, and the expression ``f(x)`` must be valid, where ``f`` is an object of type @@ -35,7 +35,7 @@ and Incrementable Iterator concepts. ``function_output_iterator`` operations ---------------------------------------- +....................................... ``explicit function_output_iterator(const UnaryFunction& f = UnaryFunction());`` @@ -60,7 +60,7 @@ and Incrementable Iterator concepts. ``function_output_iterator::output_proxy`` operations ------------------------------------------------------ +..................................................... ``output_proxy(UnaryFunction& f);`` diff --git a/doc/indirect_iterator.html b/doc/indirect_iterator.html index 5dc64c1..cf57bd8 100644 --- a/doc/indirect_iterator.html +++ b/doc/indirect_iterator.html @@ -3,240 +3,13 @@ - + Indirect Iterator - +
    @@ -280,6 +53,7 @@ iterators over smart pointers, which the impl handles. -JGS -->
  • indirect_iterator requirements
  • indirect_iterator models
  • indirect_iterator operations
  • +
  • Example
  • @@ -312,6 +86,10 @@ class indirect_iterator
             > const& y
           , typename enable_if_convertible<Iterator2, Iterator>::type* = 0 // exposition
         );
    +
    +    Iterator base() const;
    +private:
    +   Iterator m_iterator; // exposition
     };
     

    The member types of indirect_iterator are defined according to the @@ -384,7 +162,7 @@ the Iterator argument.

    Requires:Iterator must be Default Constructible. Returns:An instance of indirect_iterator with -a default-constructed iterator_adaptor subobject. +a default-constructed m_iterator. @@ -394,7 +172,7 @@ a default-constructed iterator_adaptor Returns:An instance of indirect_iterator with -the iterator_adaptor subobject copy constructed from x. +m_iterator copy constructed from x. @@ -417,17 +195,72 @@ indirect_iterator( Requires:Iterator2 is implicitly convertible to Iterator. Returns:An instance of indirect_iterator whose -iterator_adaptor subobject is constructed from y.base(). +m_iterator subobject is constructed from y.base(). + + + +

    Iterator base() const;

    + +++ +
    Returns:m_iterator
    +
    +

    Example

    +
    +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,
    +
    - - diff --git a/doc/indirect_iterator.rst b/doc/indirect_iterator.rst index 3ea8dcb..4e12086 100644 --- a/doc/indirect_iterator.rst +++ b/doc/indirect_iterator.rst @@ -21,3 +21,4 @@ .. contents:: Table of Contents .. include:: indirect_iterator_ref.rst +.. include:: indirect_iterator_eg.rst diff --git a/doc/indirect_iterator_eg.rst b/doc/indirect_iterator_eg.rst new file mode 100644 index 0000000..347aa95 --- /dev/null +++ b/doc/indirect_iterator_eg.rst @@ -0,0 +1,54 @@ +Example +....... + + +:: + + 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, diff --git a/doc/indirect_iterator_ref.rst b/doc/indirect_iterator_ref.rst index 21f90d9..48072c8 100644 --- a/doc/indirect_iterator_ref.rst +++ b/doc/indirect_iterator_ref.rst @@ -29,6 +29,10 @@ > const& y , typename enable_if_convertible::type* = 0 // exposition ); + + Iterator base() const; + private: + Iterator m_iterator; // exposition }; @@ -108,13 +112,13 @@ the ``Iterator`` argument. :Requires: ``Iterator`` must be Default Constructible. :Returns: An instance of ``indirect_iterator`` with - a default-constructed ``iterator_adaptor`` subobject. + a default-constructed ``m_iterator``. ``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``. :: @@ -131,6 +135,9 @@ the ``Iterator`` argument. :Requires: ``Iterator2`` is implicitly convertible to ``Iterator``. :Returns: An instance of ``indirect_iterator`` whose - ``iterator_adaptor`` subobject is constructed from ``y.base()``. + ``m_iterator`` subobject is constructed from ``y.base()``. +``Iterator base() const;`` + +:Returns: ``m_iterator`` diff --git a/doc/permutation_iterator.html b/doc/permutation_iterator.html index 5852cd5..a2f631c 100644 --- a/doc/permutation_iterator.html +++ b/doc/permutation_iterator.html @@ -3,240 +3,13 @@ - + Permutation Iterator - + - +
    @@ -253,7 +26,7 @@ ul.auto-toc { Boost Consulting, Indiana University Open Systems Lab Date: -2003-09-14 +2004-01-12 Copyright: Copyright Toon Knapen, David Abrahams, Roland Richter, and Jeremy Siek 2003. All rights reserved @@ -278,6 +51,7 @@ in a potentially different order.

  • permutation_iterator operations
  • +
  • Example
  • @@ -306,15 +80,11 @@ past-the-end iterator to the indices.

    template< class ElementIterator , class IndexIterator , class ValueT = use_default - , unsigned access = use_default_access - , class Traversal = use_default + , class CategoryT = use_default , class ReferenceT = use_default , class DifferenceT = use_default > class permutation_iterator - : public iterator_adaptor<...> { - typedef iterator_adaptor<...> - friend class iterator_core_access; public: permutation_iterator(); explicit permutation_iterator(ElementIterator x, IndexIterator y); @@ -325,7 +95,14 @@ public: , typename enable_if_convertible<OEIter, ElementIterator>::type* = 0 , typename enable_if_convertible<OIIter, IndexIterator>::type* = 0 ); + ElementIterator base() const; +private: + ElementIterator m_iterator; // exposition }; + +template <class ElementIterator, class IndexIterator> +permutation_iterator<ElementIterator, IndexIterator> +make_permutation_iterator( ElementIterator e, IndexIterator i);

    permutation_iterator requirements

    @@ -343,14 +120,96 @@ same concept as the IndexIterator. Thus for instance, although the permutation iterator provides operator+=(distance), this operation will take linear time in case the IndexIterator is a model of ForwardIterator instead of amortized constant time.

    +
    +template <class ElementIterator, class IndexIterator>
    +permutation_iterator<ElementIterator, IndexIterator> 
    +make_permutation_iterator(ElementIterator e, IndexIterator i);
    +
    + +++ + + + +
    Returns:An instance of permutation_iterator<ElementIterator, IndexIterator> +that views the range of elements starting at e` in the order given +by ``i.
    +

    ElementIterator base() const;

    + +++ + + + +
    Returns:m_iterator
    +
    +

    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 
    +
    - - diff --git a/doc/permutation_iterator_ref.rst b/doc/permutation_iterator_ref.rst index 4f73a31..1beaabb 100644 --- a/doc/permutation_iterator_ref.rst +++ b/doc/permutation_iterator_ref.rst @@ -18,6 +18,9 @@ , typename enable_if_convertible::type* = 0 , typename enable_if_convertible::type* = 0 ); + ElementIterator base() const; + private: + ElementIterator m_iterator; // exposition }; template @@ -63,4 +66,9 @@ __ http://www.sgi.com/tech/stl/RandomAccessIterator.html :Returns: An instance of ``permutation_iterator`` that views the range of elements starting at ``e` in the order given - by ``i``. \ No newline at end of file + by ``i``. + + +``ElementIterator base() const;`` + +:Returns: ``m_iterator`` \ No newline at end of file diff --git a/doc/reverse_iterator.html b/doc/reverse_iterator.html index 46a933c..fed8ba7 100644 --- a/doc/reverse_iterator.html +++ b/doc/reverse_iterator.html @@ -3,240 +3,13 @@ - + Reverse Iterator - +
    @@ -274,12 +47,14 @@ invoking operator--() moves th

    reverse_iterator synopsis

    @@ -296,27 +71,27 @@ public: reverse_iterator<OtherIterator> const& r , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0 // exposition ); + Iterator base() const; reference operator*() const; reverse_iterator& operator++(); private: - Iterator current; // exposition + Iterator m_iterator; // exposition }; -
    -

    reverse_iterator requirements

    +

    reverse_iterator requirements

    The base Iterator must be a model of Bidirectional Traversal Iterator and Readable Iterator.

    -

    reverse_iterator models

    +

    reverse_iterator models

    reverse_iterator models Bidirectional Traversal Iterator and Readable Iterator. In addition, reverse_iterator models the same standard iterator access concepts that the Iterator argument models.

    -

    reverse_iterator operations

    +

    reverse_iterator operations

    reverse_iterator();

    @@ -324,7 +99,7 @@ argument models.

    - @@ -335,7 +110,7 @@ default constructed. +m_iterator constructed from x.
    Requires:Iterator must be Default Constructible.
    Returns:An instance of reverse_iterator with current +
    Returns:An instance of reverse_iterator with m_iterator default constructed.
    Returns:An instance of reverse_iterator with a -current constructed from x.
    @@ -356,6 +131,15 @@ reverse_iterator( +

    Iterator base() const;

    + +++ + + + +
    Returns:m_iterator

    reference operator*() const;

    @@ -366,15 +150,15 @@ reverse_iterator(
    -Iterator tmp = current;
    -return *--tmp;
    +Iterator tmp = m_iterator;
    +return *..tmp;
     

    reverse_iterator& operator++();

    - + @@ -396,7 +180,7 @@ with a current constructed fro
    Effects:--current
    Effects:--m_iterator
    Returns:*this
    -

    Example

    +

    Example

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

    @@ -429,11 +213,6 @@ sequence in double-reversed (normal) order:     hello world!
     
    - - diff --git a/doc/reverse_iterator_eg.rst b/doc/reverse_iterator_eg.rst index eee8f66..ab8dd90 100644 --- a/doc/reverse_iterator_eg.rst +++ b/doc/reverse_iterator_eg.rst @@ -1,6 +1,6 @@ Example -------- +....... The following example prints an array of characters in reverse order using ``reverse_iterator``. diff --git a/doc/reverse_iterator_ref.rst b/doc/reverse_iterator_ref.rst index 8846cc9..0e9b35b 100644 --- a/doc/reverse_iterator_ref.rst +++ b/doc/reverse_iterator_ref.rst @@ -12,22 +12,23 @@ reverse_iterator const& r , typename enable_if_convertible::type* = 0 // exposition ); + Iterator base() const; reference operator*() const; reverse_iterator& operator++(); private: - Iterator current; // exposition + Iterator m_iterator; // exposition }; ``reverse_iterator`` requirements ---------------------------------- +................................. The base ``Iterator`` must be a model of Bidirectional Traversal Iterator and Readable Iterator. ``reverse_iterator`` models ---------------------------- +........................... ``reverse_iterator`` models Bidirectional Traversal Iterator and Readable Iterator. In addition, ``reverse_iterator`` models the same @@ -37,18 +38,18 @@ argument models. ``reverse_iterator`` operations -------------------------------- +............................... ``reverse_iterator();`` :Requires: ``Iterator`` must be Default Constructible. -:Returns: An instance of ``reverse_iterator`` with ``current`` +:Returns: An instance of ``reverse_iterator`` with ``m_iterator`` default constructed. ``explicit reverse_iterator(Iterator x);`` :Returns: An instance of ``reverse_iterator`` with a - ``current`` constructed from ``x``. + ``m_iterator`` constructed from ``x``. :: @@ -63,17 +64,24 @@ argument models. :Returns: An instance of ``reverse_iterator`` that is a copy of ``r``. + + +``Iterator base() const;`` + +:Returns: ``m_iterator`` + + ``reference operator*() const;`` :Effects: :: - Iterator tmp = current; - return *--tmp; + Iterator tmp = m_iterator; + return *..tmp; ``reverse_iterator& operator++();`` -:Effects: ``--current`` +:Effects: ``--m_iterator`` :Returns: ``*this`` diff --git a/doc/transform_iterator_ref.rst b/doc/transform_iterator_ref.rst index 08a52ef..247378a 100644 --- a/doc/transform_iterator_ref.rst +++ b/doc/transform_iterator_ref.rst @@ -30,7 +30,7 @@ ``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 @@ -42,7 +42,7 @@ The type ``Iterator`` must at least model Readable Iterator. ``transform_iterator`` models ------------------------------ +............................. The resulting ``transform_iterator`` models the most refined of the following options that is also modeled by ``Iterator``. @@ -64,7 +64,7 @@ The ``value_type`` is ``remove_cv >::type``. ``transform_iterator`` operations ---------------------------------- +................................. ``transform_iterator();`` diff --git a/example/function_output_iterator_example.cpp b/example/function_output_iterator_example.cpp new file mode 100644 index 0000000..de0feae --- /dev/null +++ b/example/function_output_iterator_example.cpp @@ -0,0 +1,48 @@ +// (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 new file mode 100644 index 0000000..1ff98e6 --- /dev/null +++ b/example/indirect_iterator_example.cpp @@ -0,0 +1,59 @@ +// (C) Copyright Jeremy Siek 2000. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +#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; +}