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

Binary Functor Predicate w/ different parameters

Can you use the standard binders (std::bind2nd) on a functor taking two
different parameter types?

Here's my code now:

template <typename T>
struct compareValString : public std::binary_function
<resources::ScopedType<T>, std::string, bool >
{
typedef typename resources::ScopedType<TST;
inline bool operator()(const ST &v, const std::string &n)
{
return false;
}
};

....

values.erase(std::remove_if(values.begin(), values.end(),
std::bind2nd(compareValString<ResourceType>(), *it)), values.end());

//it is an iterator for a vector of strings.

Dec 17 '06 #1
2 1676
Shawn McGrath wrote:
>
Can you use the standard binders (std::bind2nd) on a functor taking two
different parameter types?
Yes.
Here's my code now:

template <typename T>
struct compareValString : public std::binary_function
<resources::ScopedType<T>, std::string, bool >
{
typedef typename resources::ScopedType<TST;
inline bool operator()(const ST &v, const std::string &n)
{
return false;
}
};
The function should be const. As in:

bool operator()( const ST& v, const std::string& n ) const
...

values.erase(std::remove_if(values.begin(), values.end(),
std::bind2nd(compareValString<ResourceType>(), *it)), values.end());

//it is an iterator for a vector of strings.
Dec 17 '06 #2
"Shawn McGrath" <sh***********@gmail.comwrote:
Can you use the standard binders (std::bind2nd) on a functor taking two
different parameter types?
Yes.
Here's my code now:

template <typename T>
struct compareValString : public std::binary_function
<resources::ScopedType<T>, std::string, bool >
{
typedef typename resources::ScopedType<TST;
inline bool operator()(const ST &v, const std::string &n)
Should be:
inline bool operator()(const ST &v, const std::string &n) const
{
return false;
}
};

...

values.erase(std::remove_if(values.begin(), values.end(),
std::bind2nd(compareValString<ResourceType>(), *it)), values.end());

//it is an iterator for a vector of strings.
Dec 19 '06 #3

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

Similar topics

5
by: Alex Vinokur | last post by:
Functor-parameters in the for_each() and transform() algorithms are passed by value. Might it make sense to have also algorithms for_each2() and transform2() which pass Functor-parameters by...
0
by: CoolPint | last post by:
I am trying to write a generic heapsort (of course as a self-exercise) with Iterator interface: something like blow.... But I got into trouble finding out the Iterator to the Child node. If...
4
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a...
8
by: Amit | last post by:
Hello all. If I want to use an object both as a Functor and also, if I pass a function pointer, how can it be done ? For instance, I have something like this template< typename Iter, typename...
8
by: daniel.w.gelder | last post by:
Hello, I have been trying to write a functor template for a week now and I'm just having tons of trouble because I don't understand an issue that I guess is pretty basic to this task. ...
5
by: Peter Olcott | last post by:
I created an object that requires access to another objects data, yet have found no good way to pass this data as a parameter because the member function that requires this data must be a binary...
2
by: aaragon | last post by:
Hi guys, Is there a way to return a functor from a recursive call that takes different paths? Let's say that I have a tree structure like: root | first child ---- nextSibling ----nextSibling...
11
by: Dijkstra | last post by:
Hi folks! First, this is the code I'm using to expose the problem: ------------------------------------------------------------------ #include <functional> #include <string> #include...
3
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. ...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.