Just out of curiosity, why doesn't C++ find() accept a binary
predicate so users can do equality comparisons other than the ==
operator? In this case, the use of find() will be similar to sort(),
and probably we can do away with find_if(). Like most things in C++, I
know there must be a good reason for this, I just cannot figure out
what that is at the moment. Thank you. 4 1851
On Aug 31, 12:33 pm, indrawati.ya... @gmail.com wrote:
Just out of curiosity, why doesn't C++ find() accept a binary
predicate so users can do equality comparisons other than the ==
operator? In this case, the use of find() will be similar to sort(),
and probably we can do away with find_if(). Like most things in C++, I
know there must be a good reason for this, I just cannot figure out
what that is at the moment. Thank you.
The type of the object that the find algorithm compares should be one
that can be compared by using the operator ==
In case you want to use find algo for an object of your class you
could overload the operator == for that class.
Thanks and regards
SJ in************* @gmail.com a écrit :
Just out of curiosity, why doesn't C++ find() accept a binary
predicate so users can do equality comparisons other than the ==
operator? In this case, the use of find() will be similar to sort(),
and probably we can do away with find_if(). Like most things in C++, I
know there must be a good reason for this, I just cannot figure out
what that is at the moment. Thank you.
It must be a semantic reason.
In the case of find the semantic is an equivalence relation.
If you wanted to use another operator (which must be an inequality
operator), it would in fact become a predicate (i.e. "returns true if
the condition is satisfied, false if it is not") which means find_if
applies.
Michael so***********@g mail.com a écrit :
On Aug 31, 12:33 pm, indrawati.ya... @gmail.com wrote:
>Just out of curiosity, why doesn't C++ find() accept a binary predicate so users can do equality comparisons other than the == operator? In this case, the use of find() will be similar to sort(), and probably we can do away with find_if(). Like most things in C++, I know there must be a good reason for this, I just cannot figure out what that is at the moment. Thank you.
The type of the object that the find algorithm compares should be one
that can be compared by using the operator ==
In case you want to use find algo for an object of your class you
could overload the operator == for that class.
If the values are of the same type (or can be cast on the same type),
the following is more straightforward :
find_if(v.begin (),v.end(),bind 2nd(less<type>( ),value));
Michael in************* @gmail.com wrote:
:: Just out of curiosity, why doesn't C++ find() accept a binary
:: predicate so users can do equality comparisons other than the ==
:: operator? In this case, the use of find() will be similar to
:: sort(), and probably we can do away with find_if(). Like most
:: things in C++, I know there must be a good reason for this, I just
:: cannot figure out what that is at the moment. Thank you.
The different sort() templates have different number of parameters, so
the compiler can tell them apart.
A find() with a value and a find() with a functor would have the same
number of parameters, so the compiler cannot see which one you want to
call. Thus another name - find_if.
Bo Persson This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Praveen |
last post by:
In the ISPF editor I am using, for a particullar PO Dataset I am
getting the result of FIND statement narrowed down to the colums
48-56. i.e. if I give "FIND 'TO' ALL", the result I am getting as
"CHARS 'TO' - found 239 times within columns 48 to 56".
Please guide me as to how to make this PDS back to normal so that the
FIND command processes the whole 1 TO 80.
Thank you for the valuable time.
|
by: Jim Holder |
last post by:
I tried building libpcap and tcpdump from my Red Hat 7 RPMs. The
tcpdump make couldn't find ioccom.h and sockio.h.
When a header file is missing, how do you find it?
Thanks.
|
by: Busin |
last post by:
bool arr;
arr = true;
For the element arr, is there any fastest algorithm to fast find the two
elements on both side of "n" and both elements are cloest to "23"?
Thanks!
|
by: Tony Girgenti |
last post by:
Hello.
I'm developing and testing a web application using VS.NET 2003, VB, .NET
Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1 on a WIN XP Pro, SP2
computer. I'm using a web form.
For a datagrid control, i used the Caption property. It displays fine on
the datagrid and allows me to run the program.
But, when i view the HTML for the web form, it shows this error at the
|
by: =?Utf-8?B?Q2hyaXM=?= |
last post by:
Hi,
How can I implement regex to find complete or partial words or a group of
words. Similar to the "Find" in MS Word. I need to scan text files eg
look for "test"
or "this is a test"
or
"this is a te"
Thanks
| |
by: ak |
last post by:
Recently at an interview i was asked the following question :
Assuming the function lookupName is defined, what's wrong with this
code (hint: 2 bugs)?
const char *getName(const char *c) {
std::string name = lookupName(c);
if (name == NULL)
return "Anonymous";
|
by: emily224 |
last post by:
Hello,
I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer must be embedded somewhere in the source code, and I would like to know if anyone knows where to find the correct answer.
I would greatly appreciate it!!
Thanks!!
<!--put the preloads file here as it must load before the website class...
|
by: emily224 |
last post by:
Hello,
I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer must be embedded somewhere in the source code, and I would like to know if anyone knows where to find the correct answer.
I would greatly appreciate it!!
Thanks!!
|
by: raylopez99 |
last post by:
I suspect the answer to this question is that it's impossible, but how
do I make the below code work, at the point where it breaks (marked
below). See error CS0411
This is the complete code. Copy and paste it into VS2008 for a
Windows Forms application.
With some effort I can do the job with a user defined function, but my
question is whether I can do it using the built in library function
"Array.Find" and a predicate that takes...
|
by: Christian Meier |
last post by:
Hello Newsgroup
I have a question about the find function of std::set.
When I have a "std::set<int*>", why can't I call the find() function with an
"const int*"? I know that my key type is different from the type of the
parameter I give to the find function but can't the find() function be
written in a way where this would work? Normally, "int*" can be compared
with "const int*" without problems...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |