Re: Proposal: additional signature for mem_fn
terminator(jam) ha scritto:
I should apologize for not grasping the idea at first post.But now if
I am not wrong the problem is about forwarding - calling another
function on current parameters instead of copies- in which case IMHO
we need some keyword with appropariate symantecs instead of a low
level library function('register_callback').
The machinery to achieve perfect forwarding is already there in the
draft of C++0x, we don't need anything more than that. For example, to
call a function without making copies, you will be able to write:
template <class... Args>
void g(Args&&... args)
{
f(std::forward<Args>(args)...);
}
What I want is just a way to bind the first parameter of a given
functional. That's all. The only standard options we currently have are:
1) use std::bind1st, but it works only for functions that take exactly
two parameters
2) use std::bind, but it requires you to explicitly provide a
placeholder for each parameter except the first one (which also means
you must know the exact number of parameters in advance)
I find both of them unsatisfactory. I just saw another thread suggesting
to add some function like std::bind_nth<N>() (it's called apply_to_xxx
in the thread, but it looks a good candidate for templatization). This
might actually solve the issue. However, what I'm proposing here is a
much limited solution, specific for pointer-to-member-function only,
where the first parameter has a special meaning (the "this" pointer).
Beside the usefulness in representing "bound member functions" (a
concept available in other languages), this solution may be prone to
possible compiler optimizations. For example, we know that a
pointer-to-member-function may have a complex memory representation due
to fact that it must take into account virtuality and multiple
inheritance. However, as we are going to specify both the
pointer-to-member-function *and* the object at the same time, the
compiler might be able (through some implementation-dependent kind of
magic, of course) to use a more compact memory representation.
Ganesh
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]