From 954044406161670af364eb5324cb6ac67556554c Mon Sep 17 00:00:00 2001
From: Dave Abrahams
-
-
-
-
-
The 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 +
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>) .
- +(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. ++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 +} ++
+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>::value_type ++
template < class Iterator @@ -1300,21 +1388,21 @@ following pseudo-code. We use the abbreviation V=iterator_traits<Iterator>::value_type.:if (Value is use_default) then - typedef iterator_traits<V>::value_type value_type; + 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 iterator_traits<V>::reference reference; + typedef indirect_reference<V>::type reference; else typedef Value& reference; else typedef Reference reference; -if (Value is use_default) then - typedef iterator_traits<V>::value_type* pointer; -else +if (Value is use_default) then + typedef pointee<V>::type* pointer; +else typedef Value* pointer; if (Difference is use_default) @@ -1325,7 +1413,7 @@ elseIf CategoryOrTraversal is not use_default then iterator_category is CategoryOrTraversal. Otherwise iterator_category is a type convertible to the tag determined by -the following algorithm. Let C be traveral_category<Iterator>::type.
+the following algorithm. Let C be traversal_category<Iterator>::type.if (reference is a reference to value_type) then if (C is convertible to random_access_traversal_tag) then @@ -1339,7 +1427,7 @@ else
The Iterator argument shall meet the requirements of Readable Iterator. The CategoryOrTraversal argument shall be one of the standard iterator tags or use_default. If CategoryOrTraversal @@ -1355,7 +1443,7 @@ is not use_default, as implied default for the value_type member.
If CategoryOrTraversal is a standard iterator tag, indirect_iterator is a model of the iterator concept corresponding to the tag, otherwise indirect_iterator satisfies the requirements @@ -1369,7 +1457,7 @@ the Iterator argument.
indirect_iterator models Lvalue Iterator.In addition to the operations required by the concepts modeled by indirect_iterator, indirect_iterator provides the following operations.
@@ -1461,11 +1549,11 @@ indirect_iterator(The reverse iterator adaptor iterates through the adapted iterator range in the opposite direction.
template <class Iterator>
class reverse_iterator
@@ -1502,11 +1590,11 @@ Lvalue Iterator, then iterator_categoryinput_iterator_tag.
Iterator must be a model of Bidirectional Traversal Iterator.
A specialization of reverse_iterator models the same standard traversal and access iterator concepts modeled by its Iterator argument. In addition, it models the old iterator concepts @@ -1544,7 +1632,7 @@ Random Access Traversal Iterator reverse_iterator<X> is interoperable with reverse_iterator<Y>.
In addition to the operations required by the concepts modeled by reverse_iterator, reverse_iterator provides the following operations.
@@ -1634,12 +1722,12 @@ return *--tmp;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.
template <class UnaryFunction,
@@ -1692,7 +1780,7 @@ model Readable Lvalue Iterator then iterat
convertible to input_iterator_tag.
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 @@ -1701,7 +1789,7 @@ where the type of f(*i) must b
The argument Iterator shall model Readable Iterator.
The resulting transform_iterator models the most refined of the following options that is also modeled by Iterator.
@@ -1748,7 +1836,7 @@ mutable iterator (as defined in the old iterator requirements). transform_iterator<F2, Y, R2, V2>.
In addition to the operations required by the concepts modeled by transform_iterator, transform_iterator provides the following operations.
@@ -1841,7 +1929,7 @@ transform_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 @@ -1853,7 +1941,11 @@ underlying range. A filter iterator is therefore constructed with pair of iterators indicating the range of elements in the unfiltered sequence to be traversed.
template <class Predicate, class Iterator> class filter_iterator @@ -1890,7 +1982,7 @@ Iterator then iterator_categorystd::input_iterator_tag.
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 @@ -1901,7 +1993,7 @@ Iterator and Single Pass Iterator or it shall meet the requirements of Input Iterator.
The concepts that filter_iterator models are dependent on which concepts the Iterator argument models, as specified in the following tables.
@@ -1973,7 +2065,7 @@ following tables. filter_iterator<P2, Y>.In addition to those operations required by the concepts that filter_iterator models, filter_iterator provides the following operations.
@@ -2084,12 +2176,12 @@ or m_pred(*m_iter) -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.
template <
class Incrementable
@@ -2132,7 +2224,7 @@ the cases when the Incrementable
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:
@@ -2158,7 +2250,7 @@ i < j;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. @@ -2175,7 +2267,7 @@ concepts modeled by Incrementable same traversal category and difference type.
In addition to the operations required by the concepts modeled by counting_iterator, counting_iterator provides the following operations.
@@ -2251,7 +2343,7 @@ operations.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 @@ -2260,7 +2352,7 @@ 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 { @@ -2282,16 +2374,16 @@ private:
UnaryFunction must be Assignable and Copy Constructible.
function_output_iterator is a model of the Writable and Incrementable Iterator concepts.
explicit function_output_iterator(const UnaryFunction& f = UnaryFunction());