473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

std::find requiring operator!=

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?
Jul 22 '05 #1
3 1795
Old Wolf wrote in news:84**************************@posting.google.c om
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.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2
Old Wolf wrote:
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.

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #3
Rob Williscroft wrote in news:Xns9593241315AB5ukcoREMOVEfreenetrtw@
130.133.1.4 in comp.lang.c++:
*i == value.


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

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: zhou | last post by:
Hi there, We have a compiler specific issue which requires us to force template instantiation. This works fine. The problem comes when I try using std:find() on vector. Since vector has no member...
3
by: Peter Meier | last post by:
Hello, I have a question. I have the following construct: std::vector < std::vector < std::vector< AsMarkerMatchMatrix >> > m_matchMatrices; If I run a std::find on that I sometimes get the...
1
by: Adam Teasdale Hartshorne | last post by:
I would be extremely grateful if somebody could tell me what as I getting wrong with this little bit of code to find the index of a particular element in a std::vector std::vector<int>...
18
by: ma740988 | last post by:
Trying to get more acclimated with the use of function objects. As part of my test, consider: # include <vector> # include <iostream> # include <algorithm> #include <stdexcept> #include...
7
by: Bit byte | last post by:
I have the ff code: list<string> *m_alive_list ; list<string>::iterator my_iter; my_iter = find(m_alive_list->begin(), m_alive_list->end, string(inbox) ; Compiler barfs on 2nd line with this...
8
by: brekehan | last post by:
If I have a class MyClass { ...bunch o data and methods int x; }; and a stl container of MyClass objects Is there a way to use std::find to get all the elements whose member x
4
by: Anonymous | last post by:
I ahve a vector of doubles taht I need to extract values from. I was just about to use the STL find() algo, but I have a couple of questions: first: can you specify the tolerance threshold to...
3
by: Martin T. | last post by:
Hello. I tried to overload the operator<< for implicit printing of wchar_t string on a char stream. Normally using it on a ostream will succeed as std::operator<<<std::char_traits<char> will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.