Boost logo

Boost :

From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2007-09-03 07:19:53


Hi Tobias!

On 9/3/07, Tobias Schwinger <tschwinger_at_[hidden]> wrote:
> Hi Dean,
>
>
> Dean Michael Berris wrote:
>
> > Though it is interesting -- I've been playing around with the idea of
> > an overloaded type-safe dispatcher for some time, but I never got to
> > thinking of a way to accomplish it in a clean manner. Basically
> > something that will allow the following:
>
> <code>
>
> Seems like a job for 'fusion::map'...
>

Yes, it definitely looks like that to me. Time to brush up on fusion
again, seems I have been out of that template metaprogramming world
for quite a while now...

> > Perhaps it might be doable, even with the current code I already have
> > there but Real Life (TM) and not enough interest (or utility) from the
> > community really bars me from doing much about it. Maybe when Real
> > Life (TM) lets up, I might come around to allowing this.
>
> A very interesting thing related to your work would be to have
> "Interfaces with Reflection"
>
> http://tinyurl.com/58koc (see "Future Directions")
>
> . That library is not making any noticeable progress since quite some
> time now. What is there might still be too complicated at places, but
> the ideas in it are very hot. I bet you'll get good feedback from the
> community for bringing something like that up for review...
>

This is definitely interesting... I'll try to take a dive in, but
basically one thing missing from my current dispatcher implementation
is the ability to register functions of different signatures to which
a separate type can be "self-registered" to. I'm likening this to
something like:

struct foo_type {
  template <class dispatcher_type>
  explicit foo_type (dispatcher_type & dispatcher_) {
    dispatcher_["one"] = boost::bind(&foo_type::one, this, _1);
    dispatcher_["one"] = boost::bind(&foo_type::one, this, _1, _2);
  };
  void one(int) { };
  void one(int, int) { };
};

// ... somewhere in main
dispatcher< signatures<void(int), void(int, int)>, string > d;
foo_type instance(d);
find<void(int, int)>(instance)["one"](1, 1);
find<void(int)>(instance)["one"](1);

There might be a less cryptic way, but that's what I'm looking to
implement soon -- which should be pretty close to Interfaces with
Reflection. Interesting indeed.

>
> Another thing that you might find interesting: You know the Fusion
> functional module, don't you?
>

I can't say I know it very well (yet), but I'm definitely going to go
try and look at this really soon.

> It sorta emulates variadic templates and RValue references in C++98
> (where Fusion Sequences are analog to the 'va_list' with C varargs) and
> allows calling functions / function objects with Tuples for their
> argument lists. It makes generic callback (and "callforth") facilities
> very easy to implement, as shown by the cookbook recipe implementing
> 'bind' in less than 150 LOC and with neither repetitive code nor
> preprocessor metaprogramming:
>
> http://tinyurl.com/ywlhdq
>

Nice!

This is definitely interesting. I'm going to have a hand at
"fusion-izing" the dispatcher implementation pretty soon.

Thanks for the pointers, I'll definitely look into these.

-- 
Dean Michael C. Berris
http://cplusplus-soup.blogspot.com/
mikhailberis AT gmail DOT com
+63 928 7291459

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk