473,549 Members | 3,109 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1806
Old Wolf wrote in news:84******** *************** ***@posting.goo gle.com
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:Xns9593241 315AB5ukcoREMOV Efreenetrtw@
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
12804
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 function find() and I have to use std::find(). The linker fails on unsatisified symbols in find(). I think this is because find() is a template...
3
14177
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 iterator to be some strange number like -124224256, although I know there should not be a match. Usually the iterator points to NULL, if there is...
1
2199
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> allVertices ; getTriangleVertices(t, allVertices) ; //Fills the allVertices vector getTriangleVertices(t, allVertices) ; print("All Vertices",...
18
7176
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 <bitset> using std::vector;
7
3688
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 error msg: error C2665: 'std::find' : none of the 3 overloads can convert parameter 1 from type 'std::list<_Ty>::iterator'
8
8622
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
5519
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 match on doubles? second: if yes, how may this be done (i.e. how many one specify the tolerance threshold for comparing doubles?)
3
4231
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 be called. However, I am using the boost::format library that internally makes use of a string stream to store the formatted string. There:
0
7520
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7718
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7809
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6041
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.