std::find requiring operator!=

O

Old Wolf

In the documentation for std::find, it says:

find returns the first iterator i in the range [first, last)
for which the following condition holds:
*i == value.

However in my compiler's headers the implementation is:

template <class InputIterator, class T>
InputIterator find (InputIterator first, InputIterator last, const T& value)
{
while (first != last && *first != value)
++first;
return first;
}

So operator!= is required and operator== isn't. Is this conforming?
 
R

Rob Williscroft

Old Wolf wrote in in comp.lang.c++:
In the documentation for std::find, it says:

find returns the first iterator i in the range [first, last)
for which the following condition holds:
*i == value.

However in my compiler's headers the implementation is:

template <class InputIterator, class T>
InputIterator find (InputIterator first, InputIterator last, const
T& value) {
while (first != last && *first != value)
++first;
return first;
}

So operator!= is required and operator== isn't. Is this conforming?

Iterators / Input Iterators 24.1.1/2

In Table 72, the term the domain of == is used in the ordinary
mathematical sense to denote the set of values over which == is
(required to be) defined. This set can change over time. Each algorithm
places additional requirements on the domain of == for the iterator
values it uses. These requirements can be inferred from the uses that
algorithm makes of == and !=. [Example: the call find(a,b,x) is defined
only if the value of a has the property p defined as follows: b has
property p and a value i has property p if (*i==x) or if (*i!=x and ++i
has property p). ]

The relevent two entries from table 72 (a and b are Input Iterators):

+-------+---------------------+-------------------------------+
|a == b | convertible to bool | == is an equivalence relation |
| | | over itsdomain. |
+-------+---------------------+-------------------------------+
|a != b |convertible to bool | bool(a==b) != bool(a!=b) over |
| | | the domain of == |
+-------+---------------------+-------------------------------+

IOW, It says for an Input Iterator a != b is !bool( a == b ) without
actually requiring that its implemented in that way.

Rob.
 
A

Andrey Tarasevich

Old said:
In the documentation for std::find, it says:

find returns the first iterator i in the range [first, last)
for which the following condition holds:
*i == value.

However in my compiler's headers the implementation is:

template <class InputIterator, class T>
InputIterator find (InputIterator first, InputIterator last, const T& value)
{
while (first != last && *first != value)
++first;
return first;
}

So operator!= is required and operator== isn't. Is this conforming?

I don't think it is. The standard specification clearly states that '=='
must be used.
 
R

Rob Williscroft

Rob Williscroft wrote in 130.133.1.4 in comp.lang.c++:

Clearly I completly missed the point, please disregard my previous post.

Rob.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top