473,397 Members | 2,033 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,397 software developers and data experts.

how to use non-static member function as comparision function infind_if?

Hi,
In using find_if() you need to name a comparision function which
normally is a static function, but sometimes it is really inconvinient
for this, let's take this example,

class MyClass{
vector<int> myVec;
void func();
};

When MyClass::func() needs to call find_if against myVec, I have to
decalre a static function for it, but myVec is not static, it can not be
referenced in static function, then I have to consider convert myVec to
static...

Looks like I miss something in between, there should be some way to do
this.

Thanks.

Jul 22 '05 #1
1 1712
In article <40***************@eed.com>, John Black <bl***@eed.com>
wrote:
Hi,
In using find_if() you need to name a comparision function which
normally is a static function, but sometimes it is really inconvinient
for this, let's take this example,

class MyClass{
vector<int> myVec;
void func();
};

When MyClass::func() needs to call find_if against myVec, I have to
decalre a static function for it, but myVec is not static, it can not be
referenced in static function, then I have to consider convert myVec to
static...

Looks like I miss something in between, there should be some way to do
this.

Thanks.


I'm not sure what you are having a prblem with here. find_if does not
need any static function to work, nor does it use a comparison function,
(rather it uses a predicate function.)

Let's say you need to find an item in myVec that is greater than 5:

struct MyClass {
vector<int> myVec;
void func() {
vector<int>::iterator it =
find_if( myVec.begin(), myVec.end(),
bind2nd( greater<int>(), 5 ) );
assert( it == myVec.end() || *it > 5 );
}
};

Or are you complaining because you want to use func as the predicate?

class MyClass {
vector<int> myVec;
bool func( int x ) {
return x > 5;
}
void check() {
vector<int>::iterator it =
find_if( myVec.begin(), myVec.end(),
bind1st( mem_fun( &MyClass::func ), this ) );
assert( it == myVec.end() || *it > 5 );
}
};

Maybe if you explained better what you are wanting to do?
Jul 22 '05 #2

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

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
4
by: bwmiller16 | last post by:
Guys - I'm doing a database consistency check for a client and I find that they're building unique indexes for performance/query reasons where they could be using non-unique indexes. Note...
4
by: Dave | last post by:
I need to add the ability to drag from a Windows Form and drop into a non dotNet application. For example, having a generated image in my app that I wish to drag out into explorer as a friendly way...
0
by: Christopher Attard | last post by:
Hi, I need to create a dialog like the 'Add Counters' dialog box in perfmon. I'm using the System.Diagnostics namespace class in .NET and I've managed to do it. The problem arises when I'm...
8
by: John Hazen | last post by:
I want to match one or two instances of a pattern in a string. According to the docs for the 're' module ( http://python.org/doc/current/lib/re-syntax.html ) the '?' qualifier is greedy by...
0
by: amitvps | last post by:
Secure Socket Layer is very important and useful for any web application but it brings some problems too with itself. Handling navigation between secure and non-secure pages is one of the cumbersome...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
12
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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...

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.