forked from boostorg/concept_check
removed mention of Trivial Iterator
[SVN r23231]
This commit is contained in:
@@ -35,46 +35,41 @@ component. If the program compiles then one can be sure that the
|
|||||||
concepts cover the component.
|
concepts cover the component.
|
||||||
|
|
||||||
The following code shows the archetype class for the <a
|
The following code shows the archetype class for the <a
|
||||||
href="http://www.sgi.com/tech/stl/trivial.html">TrivialIterator</a>
|
href="http://www.sgi.com/tech/stl/InputIterator.html">Input
|
||||||
concept. Some care must be taken to ensure that the archetype is an
|
Iterator</a> concept. Some care must be taken to ensure that the
|
||||||
exact match to the concept. For example, the concept states that the
|
archetype is an exact match to the concept. For example, the concept
|
||||||
return type of <tt>operator*()</tt> must be convertible to the value
|
states that the return type of <tt>operator*()</tt> must be
|
||||||
type. It does not state the more stringent requirement that the return
|
convertible to the value type. It does not state the more stringent
|
||||||
type be <tt>T&</tt> or <tt>const T&</tt>. That means it would be a
|
requirement that the return type be <tt>T&</tt> or <tt>const
|
||||||
mistake to use <tt>T&</tt> or <tt>const T&</tt> for the return type
|
T&</tt>. That means it would be a mistake to use <tt>T&</tt>
|
||||||
of the archetype class. The correct approach is to create an
|
or <tt>const T&</tt> for the return type of the archetype
|
||||||
artificial return type that is convertible to <tt>T</tt>, as we have
|
class. The correct approach is to create an artificial return type
|
||||||
done here with <tt>input_proxy</tt>. The validity of the archetype
|
that is convertible to <tt>T</tt>, as we have done here with
|
||||||
class test is completely dependent on it being an exact match with the
|
<tt>reference</tt>. The validity of the archetype class test is
|
||||||
concept, which must be verified by careful (manual) inspection.
|
completely dependent on it being an exact match with the concept,
|
||||||
|
which must be verified by careful (manual) inspection.
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
template <class T>
|
template <class T>
|
||||||
struct input_proxy {
|
class input_iterator_archetype
|
||||||
operator const T&() {
|
|
||||||
return static_object<T>::get(); // Get a reference without constructing
|
|
||||||
}
|
|
||||||
};
|
|
||||||
template <class T>
|
|
||||||
class trivial_iterator_archetype
|
|
||||||
{
|
{
|
||||||
typedef trivial_iterator_archetype self;
|
private:
|
||||||
|
typedef input_iterator_archetype self;
|
||||||
public:
|
public:
|
||||||
trivial_iterator_archetype() { }
|
typedef std::input_iterator_tag iterator_category;
|
||||||
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 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; }
|
||||||
};
|
};
|
||||||
}
|
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
Generic algorithms are often tested by being instantiated with a
|
Generic algorithms are often tested by being instantiated with a
|
||||||
|
Reference in New Issue
Block a user