Binary Functor Predicate w/ different parameters

S

Shawn McGrath

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<T> ST;
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.
 
D

Daniel T.

Shawn said:
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<T> ST;
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
 
D

Daniel T.

Shawn McGrath said:
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<T> ST;
inline bool operator()(const ST &v, const std::string &n)

Should be:
inline bool operator()(const ST &v, const std::string &n) const
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top