A
Amit
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 Predicate>
class MyOperation: public std::binary_function<Iter, Iter,bool>
{
public:
bool operator() (const Iter &val1, const Itr &val2) const {
return Predicate()(val1, val2);
}
};
Now, if I want to add, function pointer support to this, where I could use
it in place of the Predicate, how would I do that ? I know I can declare a
function pointer within the class using something like
template< typename Iter, typename Predicate>
class MyOperation: public std::binary_function<Iter, Iter,bool>
{
typedef bool (*Fnptr)(typename Iter::value_type, typename
Iter::value_type)
public:
bool operator() (const Iter &val1, const Itr &val2) const {
return Predicate()(val1, val2);
}
};
But then, how do I initialize the Fnptr ? I guess a constructor would be
the one, but then I also want to use the Predicate, say something like a
less<int> on a set container.
Thanks.
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 Predicate>
class MyOperation: public std::binary_function<Iter, Iter,bool>
{
public:
bool operator() (const Iter &val1, const Itr &val2) const {
return Predicate()(val1, val2);
}
};
Now, if I want to add, function pointer support to this, where I could use
it in place of the Predicate, how would I do that ? I know I can declare a
function pointer within the class using something like
template< typename Iter, typename Predicate>
class MyOperation: public std::binary_function<Iter, Iter,bool>
{
typedef bool (*Fnptr)(typename Iter::value_type, typename
Iter::value_type)
public:
bool operator() (const Iter &val1, const Itr &val2) const {
return Predicate()(val1, val2);
}
};
But then, how do I initialize the Fnptr ? I guess a constructor would be
the one, but then I also want to use the Predicate, say something like a
less<int> on a set container.
Thanks.