diff --git a/development/libs/iterator/iterator_concepts.gif b/development/libs/iterator/iterator_concepts.gif new file mode 100644 index 0000000..762c055 Binary files /dev/null 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 new file mode 100644 index 0000000..05c2258 --- /dev/null +++ b/development/libs/iterator/iterator_concepts.htm @@ -0,0 +1,606 @@ + + + + +Iterator Concepts + +C++ Boost + +
+ +

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.

+ +One set of concepts handles the return type semantics: + + +The other set of concepts handles iterator traversal: + + + +

+
+ + + +
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::Output Iterator refines boost::Single-Pass Iterator and +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.
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.
+  }
+
+ + +

Associated Types

+ + + + + + + + + + + + + + + +
Value typeboost::iterator_traits<X>::value_type + The type of the value obtained by dereferencing a LvalueIterator +
Return Categoryboost::iterator_traits<X>::return_category + A type convertible to boost::readable_iterator_tag +
+ +

Refinement of

+ +Assignable, +Equality Comparable, +Default Constructible + +

Valid expressions

+ + + + + + + + + + + + + + + +
NameExpressionType requirementsReturn type
Dereference*x Convertible to T.
Member accessx->mT is a type with a member named 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 Categoryboost::iterator_traits<X>::return_category + A type convertible to boost::writable_iterator_tag +
+ + + +

Refinement of

+ +Assignable, +Equality Comparable, +Default Constructible + +

Valid expressions

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

+ +


+ +

+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

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
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 + const T&. +
POinter typeboost::iterator_traits<X>::pointer + The pointer to the value type, which must be const T*. +
Return Categoryboost::iterator_traits<X>::return_category + A type convertible to boost::constant_lvalue_iterator_tag +
+ + +

Valid expressions

+ + + + + + + + + + + + + + + +
NameExpressionType requirementsReturn type
Dereference*x const T&
Member accessx->mT is a type with a member named m. +   +
+ + +

+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 and +Writable Iterator. + + + +

Associated Types

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Value typeboost::iterator_traits<X>::value_type + The type of the value obtained by dereferencing a Mutable Lvalue Iterator. +
Reference typeboost::iterator_traits<X>::reference + The return type of operator*(), which is + T&. +
Pointer typeboost::iterator_traits<X>::pointer + The pointer to the value type, which is T*. +
Return Categoryboost::iterator_traits<X>::return_category + A type convertible to boost::mutable_lvalue_iterator_tag +
+ + +

Valid expressions

+ + + + + + + + + + + + + + + +
NameExpressionType requirementsReturn type
Dereference*x  T&
Member accessx->mT is a type with a member named m. +   +
+ +

+


+ +

+Single-Pass Iterator +

+ +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 +
+ +

Valid expressions

+ + + + + + + + + + + + + + +
NameExpressionType requirementsReturn 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 +
+ +

+


+ +

+Bidirectional Iterator +

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

Refinement of

+ +Forward Iterator + +

Associated types

+ + + + + + + +
Traversal Categoryboost::iterator_traits<X>::traversal_category + A type convertible to boost::bidirectional_iterator_tag +
+ +

Valid expressions

+ + + + + + + + + + + + +
NameExpressionType requirementsReturn type
Predecrement--i X&
Postdecrementi-- X
+ +

+


+ +

+Random Access Iterator +

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

Refinement of

+ +Bidirectional Iterator + +

Associated types

+ + + + + + + +
Traversal Categoryboost::iterator_traits<X>::traversal_category + A type convertible to boost::random_access_iterator_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 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
+ + +
+ +
+ + +
Copyright © 2000 +Jeremy Siek, Univ.of Notre Dame (jsiek@lsc.nd.edu) +
+ + +