473,387 Members | 1,545 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,387 software developers and data experts.

trouble with std::find_if()

Hi,

this is cut from a larger program.

<code>

#include <algorithm>
#include <vector>
typedef unsigned int SapId;

class Sap
{
public:
explicit Sap(SapId id): id_(id)
{}

SapId ident () const
{ return id_; }

private:
SapId id_;
};
typedef std::vector<Sap*SapList;

SapList sap_list_;
class SapIdMatchPredicate
{
public:
SapIdMatchPredicate(SapId id): id_(id)
{}

bool operator() (const Sap& sap) const
{ return sap.ident() == id_; }

private:
const SapId id_;
};

SapList::iterator find (const SapId sap_id)
{
SapIdMatchPredicate sap_id_match (sap_id);
return std::find_if (sap_list_.begin(), sap_list_.end(),
sap_id_match);
}

int main (void)
{
SapList::iterator i;
i = find (1234); return 0;
}

</code>

I've presumably done something wrong with the functor. I get
compilation errors

'()' : cannot convert parameter 1 from 'class Sap *' to 'const
class Sap &'
term does not evaluate to a function
the erroneous line is deep in algorithm.h
--
Nick Keighley

The rabbit snarled and hefted his submachine gun angrily.
Ears back and teeth visible, he hissed at the cyborg.
Charles Stross "Singularity Sky"
Jul 2 '08 #1
1 1464
On 2 Jul, 14:11, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:

AhA!

I found the problem (see OP for details):-
<snip>
typedef std::vector<Sap*SapList; <--- Sap*

SapList sap_list_;

class SapIdMatchPredicate
{
public:
* * SapIdMatchPredicate(SapId id): id_(id)
* * {}

* * bool operator() (const Sap& sap) const <--- Sap&
* * { * *return sap.ident() == id_; * *}

private:
* * const SapId id_;

};
<snip>

if it's a vector of Sap* I need to compare Sap* not Sap&
--
Nick Keighley


Jul 2 '08 #2

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

Similar topics

14
by: mikets | last post by:
Hi there, I found out that very often I use the following construct: for (it = myvec.begin(); it != myvec.end(); ++it) { if (it->name() == "myname") break; } Certainly, the container the...
3
by: marco_segurini | last post by:
Hi, when the following code is executed bool Test1(); bool Test2(); .... if (Test1() || Test2()) { ... } ....
1
by: Saeed Amrollahi | last post by:
Dear All C++ Programmers Hello I am Saeed Amrollahi. I am a software engineer in Tehran Sewerage Company. I try to use std::map and map::find member function. I use Visual Studio .NET. my...
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...
3
by: devel | last post by:
Hello, Could someone tell me why the find_if statement applied to my multimap dictionnary is doesn't compile? Does this algorithm doesn't work on a multimap? I don't understand why the...
3
by: Misiu | last post by:
Hello everybody, How to avoid using struct IsDataType for comparison for find_if algorithm but use something like that what is now commented out in the code below? Regards, Misiu ...
10
by: JDT | last post by:
Hi, The following find_if works fine to me except that I want the internal individual comparison performed backward (from m+5, m+4, ..., to m). I can use reverse() to reverse the array first...
7
by: Anonymous | last post by:
I have map variable that maps ids (unsigned int) to objects. Each object has a Name() method. I want to use std::find_if to fetch the object that name matches. I defined my predicate like...
5
by: eiji.anonremail | last post by:
I would like to search in a vector depending on "a" or "a and b" without the overhead of creating a Foo object or another predicate class. Is that possible? Using a member function pointer or a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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...

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.