From a29797eadce581234cd10d933901d3f64c59f42c Mon Sep 17 00:00:00 2001 From: Jeremy Siek Date: Mon, 28 Jun 2004 13:26:05 +0000 Subject: [PATCH] removed mention of Trivial Iterator [SVN r23231] --- concept_covering.htm | 63 ++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/concept_covering.htm b/concept_covering.htm index db7a419..15bc8d2 100644 --- a/concept_covering.htm +++ b/concept_covering.htm @@ -35,46 +35,41 @@ component. If the program compiles then one can be sure that the concepts cover the component. The following code shows the archetype class for the TrivialIterator -concept. Some care must be taken to ensure that the archetype is an -exact match to the concept. For example, the concept states that the -return type of operator*() must be convertible to the value -type. It does not state the more stringent requirement that the return -type be T& or const T&. That means it would be a -mistake to use T& or const T& for the return type -of the archetype class. The correct approach is to create an -artificial return type that is convertible to T, as we have -done here with input_proxy. The validity of the archetype -class test is completely dependent on it being an exact match with the -concept, which must be verified by careful (manual) inspection. +href="http://www.sgi.com/tech/stl/InputIterator.html">Input +Iterator concept. Some care must be taken to ensure that the +archetype is an exact match to the concept. For example, the concept +states that the return type of operator*() must be +convertible to the value type. It does not state the more stringent +requirement that the return type be T& or const +T&. That means it would be a mistake to use T& +or const T& for the return type of the archetype +class. The correct approach is to create an artificial return type +that is convertible to T, as we have done here with +reference. The validity of the archetype class test is +completely dependent on it being an exact match with the concept, +which must be verified by careful (manual) inspection.
   template <class T>
-  struct input_proxy {
-    operator const T&() {
-      return static_object<T>::get(); // Get a reference without constructing
-    }
-  };
-  template <class T>
-  class trivial_iterator_archetype
+  class input_iterator_archetype
   {
-    typedef trivial_iterator_archetype self;
+  private:
+    typedef input_iterator_archetype self;
   public:
-    trivial_iterator_archetype() { }
-    trivial_iterator_archetype(const self&) { }
-    self& operator=(const self&) { return *this;  }
-    friend bool operator==(const self&, const self&) { return true; }
-    friend bool operator!=(const self&, const self&) { return true; }
-    input_proxy<T> operator*() { return input_proxy<T>(); }
-  };
-
-  namespace std {
-    template <class T>
-    struct iterator_traits< trivial_iterator_archetype<T> >
-    {
-      typedef T value_type;
+    typedef std::input_iterator_tag iterator_category;
+    typedef T value_type;
+    struct reference {
+      operator const value_type&() const { return static_object<T>::get(); }
     };
-  }
+    typedef const T* pointer;
+    typedef std::ptrdiff_t difference_type;
+    self& operator=(const self&) { return *this;  }
+    bool operator==(const self&) const { return true; }
+    bool operator!=(const self&) const { return true; }
+    reference operator*() const { return reference(); }
+    self& operator++() { return *this; }
+    self operator++(int) { return *this; }
+  };
 
Generic algorithms are often tested by being instantiated with a