Quote:>The function mem_fun gives me the first problem: How can I call a const
>member functions without a ugly cast? All the mem_fun types are declared
>calling non const member functions!
No. There are four overloaded mem_fun functions.
The first two mem_fun's take non-const and const member functions of zero
arguments, and return mem_fun_t and const_mem_fun_t objects respectively.
The operator() of these two objects take one argument, namely a pointer
to a non-const or const object.
The second two mem_fun's take non-const and const member functions of one
argument, and return mem_fun1_t and const_mem1_fun_t objects respectively.
The operator() of these two objects take two arguments, namely a pointer
to a non-const or const object, as well as the argument of the original
member function.
Then there are four overloaded mem_fun_ref functions.
There are no functions mem_fun1 and mem_fun1_ref in the standard,
although some implementations still carry them, as a remembrance of
times when dinosours ruled the earth :).
Quote:>Second, How can I combine two predicates to one? There are binder
>predicates, that bind values to arguments, but I see no possibilty to
>combine my mem_fun_t (or _ref) with some eqal_to predicate.
>Do I have to code this for myself or am I missing something?
Here is one example:
First, here is a class. Pay attention to the public get functions
name() and size().
class Type
{
public:
Type(char const * name, size_t size)
: d_name(name), d_size(size) { }
char const * name() const { return d_name; }
size_t size() const { return d_size; }
private:
char const *const d_name;
const size_t d_size;
};
Now here is the body of some function
typedef std::deque<Type>::iterator Iter;
using std::compose1;
using std::bind2nd;
using std::mem_fun_ref;
typedef std::equal_to<size_t> equal;
const Iter pos=std::find_if(
d_types.begin(), d_types.end(),
compose1(bind2nd(equal(),size),mem_fun_ref(&Type::size))
);
if (pos==d_types.end()) { ... } // not found
The find_if statement finds the first element in the array d_types
(an array of Type objects) that which has its size field, given
by Type::size(), equal to the local variable 'size'.
Whether you want to write code like this is another matter.
--
----------------------------------
----------------------------------
[ about comp.lang.c++.moderated. First time posters: do this! ]