diff --git a/development/libs/iterator/iterator_concepts.fig b/development/libs/iterator/iterator_concepts.fig index 3c51b23..0723053 100644 --- a/development/libs/iterator/iterator_concepts.fig +++ b/development/libs/iterator/iterator_concepts.fig @@ -7,20 +7,16 @@ Letter Single -2 1200 2 -6 825 1575 3825 4500 +6 750 2100 3750 4125 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 2400 1725 1800 + 1650 3825 1650 3225 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 4200 1725 3600 -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 3300 1725 2700 -4 0 0 100 0 19 18 0.0000 4 255 2370 825 1800 SinglePassIterator\001 -4 0 0 100 0 19 18 0.0000 4 195 1995 825 2700 ForwardIterator\001 -4 0 0 100 0 19 18 0.0000 4 195 2565 825 3600 BidirectionalIterator\001 -4 0 0 100 0 19 18 0.0000 4 195 2955 825 4500 RandomAccessIterator\001 + 1650 2925 1650 2325 +4 0 0 100 0 19 18 0.0000 4 210 1995 750 2325 ForwardIterator\001 +4 0 0 100 0 19 18 0.0000 4 210 2580 750 3225 BidirectionalIterator\001 +4 0 0 100 0 19 18 0.0000 4 210 2940 750 4125 RandomAccessIterator\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 @@ -31,7 +27,11 @@ Single 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 -4 0 0 100 0 19 18 0.0000 4 195 1995 6600 2400 WritableIterator\001 -4 0 0 100 0 19 18 0.0000 4 195 2130 3900 2400 ReadableIterator\001 -4 0 0 50 0 19 18 0.0000 4 195 2805 5700 3300 MutableLvalueIterator\001 -4 0 0 50 0 19 18 0.0000 4 195 2955 3900 3900 ConstantLvalueIterator\001 +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 210 2970 3900 3900 ConstantLvalueIterator\001 +4 0 0 50 0 19 18 0.0000 4 270 2355 9075 2400 SwappableIterator\001 diff --git a/development/libs/iterator/iterator_concepts.gif b/development/libs/iterator/iterator_concepts.gif index 762c055..29c38c9 100644 Binary files a/development/libs/iterator/iterator_concepts.gif and b/development/libs/iterator/iterator_concepts.gif differ diff --git a/development/libs/iterator/iterator_concepts.htm b/development/libs/iterator/iterator_concepts.htm index 0848ab5..f2f8dcd 100644 --- a/development/libs/iterator/iterator_concepts.htm +++ b/development/libs/iterator/iterator_concepts.htm @@ -43,53 +43,68 @@
+

Iterator Concepts

-

The standard iterator concepts (the iterator requirements defined -in the C++ Standard) have a flaw. They glom together two separate -issues into a single set of concepts. The two issues are iterator -traversal and dereference return type semantics. These two issues are -inherently orthogonal and therefore ought to be represented by two -separate sets of concepts. The concepts described here do just -that.

+

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 refines boost::Single-Pass Iterator and -boost::ReadableIterator. +std::Input Iterator implies boost::ReadableIterator.

-std::Output Iterator refines boost::Single-Pass Iterator and -boost::Writable Iterator. +std::Output Iterator implies boost::Writable Iterator.

std::Forward Iterator refines boost::Forward Iterator and @@ -106,106 +121,99 @@ boost::Constant Lvalue Iterator or boost::Mutable Lvalue Iterator.

Notation

- - - - - - - - - - - - - - - + + + + + + + + + + + + + + +
XThe iterator type.
TThe value type of X.
x, yAn object of type X.
tAn object of type T.
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. For example, derefencing may return a temporary object and -therefore it would be a mistake to bind the result to a reference. -Also, an attempt to assign a value to the result will most likely -cause an error. - -
-  template <class Readable Iterator>
-  void foo(Readable Iterator x)
-  {
-    typedef std::iterator_traits<Readable Iterator>::value_type T;
-    T t = *x;  // Read a value. This is OK.
-    T& s = *x; // Bind to a reference. This is a bad idea.
-    *x = t;    // Try to assign. This is a really bad idea.
-  }
-
- +iterator.

Associated Types

- - - - + + + + - - - - + + + + + + + + + +
Value typeboost::iterator_traits<X>::value_type - The type of the value obtained by dereferencing a LvalueIterator -
Value typestd::iterator_traits<X>::value_typeThe type of the objects pointed to by the iterator.
Return Categoryboost::iterator_traits<X>::return_category - A type convertible to boost::readable_iterator_tag -
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

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

Valid expressions

- - - - - - - - - - - - + + + + + + + + + + + +
NameExpressionType requirementsReturn type
Dereference*x Convertible to T.
Member accessx->mT is a type with a member named m. -   -
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. @@ -226,12 +234,12 @@ conversions on a. - - - - + + + +
Return Categoryboost::iterator_traits<X>::return_category - A type convertible to boost::writable_iterator_tag -
Return Categorystd::return_category<X>::type + A type convertible to std::writable_iterator_tag +
@@ -240,30 +248,100 @@ conversions on a.

Refinement of

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

Valid expressions

- + - - - - - - + + + + + +
NameExpressionReturn type
Dereference assignment*x = aunspecified
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 @@ -275,72 +353,72 @@ iterator.

Refinement of

-Readable Iterator +Readable Iterator

Associated Types

- - - - - - - - - - + + + + - - - - - - - + + + +
Value typeboost::iterator_traits<X>::value_type - The type of the value obtained by dereferencing a Constant Lvalue Iterator. -
Reference typeboost::iterator_traits<X>::reference - The return type of operator*(), which must be +
Reference typestd::iterator_traits<X>::reference + The return type of dereferencing the iterator, which must be const T&. -
POinter typeboost::iterator_traits<X>::pointer + -
Return Categoryboost::iterator_traits<X>::return_category - A type convertible to boost::constant_lvalue_iterator_tag -
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 @@ -350,8 +428,9 @@ pointers and references previously obtained from that iterator.

Refinement of

-Readable Iterator and -Writable Iterator. +Readable Iterator, +Writable Iterator, +and Swappable Iterator. @@ -359,241 +438,219 @@ pointers and references previously obtained from that iterator. - - - - + + + + - - - - - - - - - - - - - + + + +
Value typeboost::iterator_traits<X>::value_type - The type of the value obtained by dereferencing a Mutable Lvalue Iterator. -
Reference typestd::iterator_traits<X>::referenceThe return type of dereferencing the iterator, which must be + T&.
Reference typeboost::iterator_traits<X>::reference - The return type of operator*(), which is - T&. -
Pointer typeboost::iterator_traits<X>::pointer + -
Return Categoryboost::iterator_traits<X>::return_category - A type convertible to boost::mutable_lvalue_iterator_tag -
Return Categorystd::return_category<X>::type + A type convertible to std::mutable_lvalue_iterator_tag +
- + +


+ -

-Single-Pass Iterator -

+

+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 -A Single-Pass Iterator is an iterator that can be incremented to -traverse through a sequence of objects, but the sequence can only be -traversed a single time.

Associated types

- - - - - - - - - + + + + -
Difference typeboost::iterator_traits<X>::difference_type - A signed integral type used to represent the distance from one - iterator to another, or the number of elements in a range. -
Traversal Categoryboost::iterator_traits<X>::traversal_category - A type convertible to boost::single_pass_iterator_tag -
Difference Typestd::iterator_traits<X>::difference_type + A signed integral type used for representing distances + between iterators that point into the same range. +
+ + Traversal Category + std::traversal_category<X>::type + + A type convertible to std::forward_traversal_tag + + +

Valid expressions

- + - - - - - - - - - -
NameExpressionType requirements Return type
Preincrement++i X&
Postincrement(void)i++  
- -

-


- -

-Forward Iterator -

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

Refinement of

- -Single-Pass Iterator - -

Associated types

- - - - - - + + + + + + + +
Traversal Categoryboost::iterator_traits<X>::traversal_category - A type convertible to boost::forward_iterator_tag -
Preincrement++i X&
Postincrementi++ convertible to const X&


+ -

-Bidirectional Iterator -

+

+Bidirectional Traversal Iterator +

An iterator that can be incremented and decremented.

Refinement of

-Forward Iterator +Forward Traversal Iterator

Associated types

- - - - + + + +
Traversal Categoryboost::iterator_traits<X>::traversal_category - A type convertible to boost::bidirectional_iterator_tag -
Traversal Categorystd::traversal_category<X>::type + A type convertible to std::bidirectional_traversal_tag +

Valid expressions

- + - - - - - - + + + + + +
NameExpressionType requirements Return type
Predecrement--i X&
Postdecrementi-- X
Predecrement--i X&
Postdecrementi-- convertible to const X&


+ -

-Random Access Iterator -

+

+Random Access Traversal Iterator +

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

Refinement of

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

Associated types

- - - - + + + +
Traversal Categoryboost::iterator_traits<X>::traversal_category - A type convertible to boost::random_access_iterator_tag -
Traversal Categorystd::traversal_category<X>::type + A type convertible to std::random_access_traversal_tag +

Valid expressions

- + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + +
NameExpressionType requirements
NameExpressionType requirements Return type
Iterator additioni += n X&
Iterator additioni + n or n + i X
Iterator subtractioni -= n X&
Iterator subtractioni - n X
Differencei - j boost::iterator_traits<X>::difference_type
Element operatori[n]X must be a model of - Readable Iterator. The same return type as *i.
Element assignmenti[n] = tX must be a model of - Writable Iterator.unspecified
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
- -
+