Re: (variadic) templates and storing pointers to (arbitrary) member
functions
On 25 Jun., 08:54, Michael Haupt <mha...@gmail.com> wrote:
I've asked this on the gcc-help mailing list already but was
redirected to this group as the question seemed to be too C++
specific. So, apologies to all that have seen this already.
What I would like to do is create a map<s, f> mapping some symbol type
to functions (the latter are member functions of classes).
My problem is that I am stuck defining the correct type for f. It
should be able to represent member functions of arbitrary classes,
with arbitrary parameter lists.
How would you use such a map (and call the functions?)
iter_t it = map.find("my symbol");
if (it!=map.end()) {
it->second(); // <-- like this?
}
My understanding of the problem is that what I really want is a
partial instantiation of the template that still leaves the A...
unbound, creating a more generic type.
Is that possible at all?
No. Instead, try runtime polymorphism:
map<std::string,std::tr1::function<void()> > map;
You can initialize a function<> object with pretty much any kind of
functor object as long as the "signature is compatible". This includes
functors like bind1st(mem_fun(&T::foo),&t).
Cheers!
SG