diff --git a/doc/new-iter-concepts.html b/doc/new-iter-concepts.html index 12cabb2..5c21289 100755 --- a/doc/new-iter-concepts.html +++ b/doc/new-iter-concepts.html @@ -3,204 +3,13 @@ - + New Iterator Concepts - + - +
@@ -218,7 +27,7 @@ ul.auto-toc { Systems Lab, University of Hanover Institute for Transport Railway Operation and Construction Date: -2003-11-22 +2003-12-01 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 @@ -248,40 +57,39 @@ of iterators that are used in practice.
@@ -299,7 +107,7 @@ 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.

- +
@@ -367,14 +175,13 @@ traversal from the need for a true reference return type.

Impact on the Standard

-
-

Proposed Changes for TR1

-

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.

+

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.

@@ -382,23 +189,22 @@ made it). -DWA --> 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 --> -

The algorithms in the standard library 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.

Note that as currently specified, istreambuf_iterator doesn't meet the Readable Iterator requirements because its value_type is not convertible to its reference type. We believe this to be a defect in the standard; it should be fixed by changing its reference type from value_type& to value_type const&.

-
-

Possible (but not proposed) Changes to the Working Paper

+

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

+

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 @@ -460,14 +266,14 @@ Bidirectional Iterator (2) -> Bidirectional Traversal Iterator and Writable I

-

Deprecations

+

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>

+

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 @@ -476,7 +282,7 @@ Iterator.

-

Design

+

Design

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

    @@ -511,64 +317,19 @@ given in the following diagram.

    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. -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<Iter>::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 <unsigned int access_bits, class TraversalTag>
    -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 <class Iterator> struct is_readable  { typedef ... type; };
    -template <class Iterator> struct is_writable { typedef ... type; };
    -template <class Iterator> struct is_swappable { typedef ... type; };
    -template <class Iterator> struct traversal_category { typedef ... type; };
    -
    -

    We do not include a helper class is_lvalue_iterator because that -can easily be deduced by checking whether -iterator_traits<Iterator>::reference is a real reference.

    -

    The most 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 +associated with the first tag is a refinement of the second tag. Our +design reuses iterator_traits<Iter>::iterator_category as the +access mechanism for the traversal tag. If an iterator wishes to meet +the requirements of both a new iterator concept and an old iterator +concept, it can use an iterator category type that inherits from both +the the old iterator tag and the new traversal tag.

    +

    We do not provide tags for the purposes of dispatching based on the +access concepts. There are two reasons: we could not find a way to +automatically infer the right access tags for old-style iterators and +the need for dispatching based on the access concepts is not as great.

    +

    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 @@ -578,23 +339,23 @@ only required to return something convertible to the i[n] = t (for a Writable Iterator).

-

Proposed Text

+

Proposed Text

-

Addition to [lib.iterator.requirements]

+

Addition to [lib.iterator.requirements]

-

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

+

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]

+

Readable Iterators [lib.readable.iterators]

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.

-
+
@@ -643,13 +404,13 @@ to (*a).m
-

Writable Iterators [lib.writable.iterators]

+

Writable Iterators [lib.writable.iterators]

A class or built-in type X models the Writable Iterator concept if the following expressions are valid and respect the stated semantics. In addition, a model of Writable Iterator must include in its documentation the set of value types that it allows for output.

- +
@@ -674,11 +435,11 @@ value types of X
-

Swappable Iterators [lib.swappable.iterators]

+

Swappable Iterators [lib.swappable.iterators]

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

- +
@@ -706,10 +467,10 @@ exchanged
-

Lvalue Iterators [lib.lvalue.iterators]

+

Lvalue Iterators [lib.lvalue.iterators]

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

-
+
@@ -736,17 +497,17 @@ cv-qualification
-

Iterator Traversal Concepts [lib.iterator.traversal]

+

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]

+

Incrementable Iterators [lib.incrementable.iterators]

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

-
+
@@ -785,11 +546,11 @@ semantics.

-

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

+

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.

- +
@@ -831,11 +592,11 @@ relation over its domain
-

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

+

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

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

- +
@@ -878,11 +639,11 @@ the distance between iterators
-

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

+

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

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

- +
@@ -930,13 +691,13 @@ implies r ==
-

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

+

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.

-
+
@@ -1044,7 +805,7 @@ ordering relation
-

Addition to [lib.iterator.synopsis]

+

Addition to [lib.iterator.synopsis]

 // lib.iterator.traits, traits and tags
 template <class Iterator> struct is_readable_iterator;
@@ -1058,7 +819,7 @@ struct random_access_traversal_tag : bidirectional_traversal_tag { };
 
-

Addition to [lib.iterator.traits]

+

Addition to [lib.iterator.traits]

The is_readable_iterator and iterator_traversal class templates satisfy the UnaryTypeTrait requirements.

Given an iterator type X, is_readable_iterator<X>::value @@ -1087,7 +848,7 @@ traversal-category(X) =

-

Footnotes

+

Footnotes

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

@@ -1100,11 +861,5 @@ LocalWords: incrementable xxx min prev inplace png oldeqnew AccessTag struct LocalWords: TraversalTag typename lvalues DWA Hmm JGS mis enum -->
- -