C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

std::find requiring operator!=

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Old Wolf
Guest





PostPosted: Sun Oct 31, 2004 3:14 am    Post subject: std::find requiring operator!= Reply with quote



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?
Back to top
Rob Williscroft
Guest





PostPosted: Sun Oct 31, 2004 3:33 am    Post subject: Re: std::find requiring operator!= Reply with quote



Old Wolf wrote in news:843a4f78.0410301914.7a7266d4 (AT) posting (DOT) google.com
in comp.lang.c++:

Quote:
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 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):

+-------+---------------------+-------------------------------+
Quote:
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.
--
http://www.victim-prime.dsl.pipex.com/

Back to top
Andrey Tarasevich
Guest





PostPosted: Mon Nov 01, 2004 5:37 am    Post subject: Re: std::find requiring operator!= Reply with quote



Old Wolf wrote:
Quote:
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 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.

--
Best regards,
Andrey Tarasevich


Back to top
Rob Williscroft
Guest





PostPosted: Mon Nov 01, 2004 6:06 am    Post subject: Re: std::find requiring operator!= Reply with quote

Rob Williscroft wrote in news:Xns9593241315AB5ukcoREMOVEfreenetrtw@
130.133.1.4 in comp.lang.c++:

Quote:
*i == value.

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

Rob.
--
http://www.victim-prime.dsl.pipex.com/

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.