Boost logo

Boost Users :

Subject: Re: [Boost-users] Dynamic function call question
From: Alan M. Carroll (amc_at_[hidden])
Date: 2009-02-26 12:56:34


I have done a similar thing in the past, although it's not really a Boost thing and not quite as general. What it did was let you register functions with a tag and with arbitrary return types and arguments*. The dispatcher would take a tag and the variant vector and see if the types matched. If so, the registered function would be called otherwise the request would be bonged. The basic concept is that when you register the function, you create an adapter function that takes the vector of variants, casts them to the specific types required by the function, then calls the function. The adapter is what is stored in the table and Boost.Function is handy for that.

* Limited in number by a compile time constant for the usual reasons.

P.S. It also used a type system and encoding very similar to JSON (before JSON existed) but I was told by my corporate masters that it was a silly idea. Ah well.

At 10:56 AM 2/26/2009, you wrote:
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
         boundary="----_=_NextPart_001_01C99833.3D44D906"

Hello,
 
I've been trying to design a function dispatch system and I was wondering if the following is possible with the current boost libraries...
 
I currently parse json data into an vector of variants, I would like to be able to take those variants and invoke an arbitrary boost function object with a consistent return type.
 
Is it possible to determine the function argument types, get the typed value from the proper index in the array of variants, and call the function with arguments?
 
This sounds like something the boost fusion library might be able to do, but I can't find any example code using the library to see if this is the right fit for the capabilities of the library or if what I'm looking to do is not possible without tons of boiler plate.
 
Any insight would be greatly appreciated,

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net