|
Boost : |
From: Marco Costalba (mcostalba_at_[hidden])
Date: 2007-09-06 12:27:02
On 9/6/07, Dean Michael Berris <mikhailberis_at_[hidden]> wrote:
> On 9/6/07, Mathias Gaunard <mathias.gaunard_at_[hidden]> wrote:
> > Marco Costalba wrote:
> >
> > > What I would need is an implementation of the following algorithm:
> > >
> > > foreach(f in Set)
> > > if ( "f(v1,v2,..,vk)" is compilable )
> > > return f;
> >
> > function_traits, SFINAE, and verbose meta-programming.
> >
>
> This would work if you were using something like Boost.Fusion in the
> background where most of the processing is done at compile time.
> However I believe the OP was looking for a solution at runtime, which
> pretty hard to achieve if you're going to rely on RTTI.
>
Yes. Correct.
At compile time it's not a problem, also is not a problem to check for
the same signature parameter types at runtime.
The real problem is to support automatic conversions (int -> double,
derived* -> base*) at runtime.
> I'm looking for a similar solution, but more towards improving
> http://dispatcher.sourceforge.net/ to be able to support multiple
> function signatures in a single dispatcher instance. I think I've got
> a way to accomplish that with Boost.Fusion, but I doubt this same
> approach you propose will work for runtime determination.
>
> Unless I'm missing something, in which case please enlighten me.
>
I studied your dispatcher code. The "trick" is that it supports only
one signature per dispatcher. So that all the objects stored your maps
could be easily derived form a base class with a given and fixed
signature.
When you want to store objects with different signatures in a single
map you need (or at least I was not able to find something better ;-)
to use a common base class with no signature information
(StorableClass) and store pointers of that class, then you add
signature info subclassing that class with a class templetized on a
given signature (SignatureClass).
So you have a possible map:
map[(key1,p1) (key2,p2) (key3,p3) .... ]
where pointers
StorableClass *p1, *p2, *p3 are indeed pointers to objects of 3
different instances of a template<>SignatureClass
So pointers can coexist together also if the objects they point have
different signatures. In the "simple_factory.hpp" example, I posted in
a previous thread, a dynamic_cast at runtime is used to check the
signatures hidden behind p1,p2,p3 against a given one.
The real problem is that two SignatureClass objects with different signatures:
SignatureClass<int (int,int)> and SignatureClass<int (int,double)>
HAVE DIFFERENT TYPE!!! so that a dynamic_cast is unable to discover
that a set of values v1,v2 that could be used for the first one can be
feed also to the second one.
Hope is clear...at least a bit ;-)
Thanks
Marco
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk