An analogue of boost.function with multiple signatures

Hello, I'd like to have an object similar to boost::function, but with multiple function signatures. Eg. something like that multifunction<std::string(std::string), float(float), unsigned(unsigned)> mf; mf=_1 + _1; // I mean boost::lambda::_1 mf("ab"); // should be "abab" mf((UINT_MAX/2)+1); // should be 0 mf((UINT_MAX/2)+1.0); // should be UINT_MAX+1.0 Would it be possible/feasible to change boost::function to allow this (as opposed to implementing it separately from boost::function)? Was something like this even proposed before (I vaguely recall something, but couldn't google anything useful, so I may be wrong)? Regards Jiri Palecek

Hello Jiøí, you can find two implementations of multi functions in the boost vault msf-1.2.2.zip by Marco Costalba and overload-mrcec/overload-0.3.0.zip by me About the last one you can read a tutorial here: http://docs.google.com/Doc?id=dfxvjncs_1x6456m Some remark: (1) I don't know if they can interoperate with boost::lamba, you should give it a try. Using my implementation you can get what you're interested in with the following code: struct doubler { template< typename T> T operator() (const T& x) { return x + x; } }; boost::overload< std::string (std::string), float (float), unsigned (unsigned) > mf; mf.set(doubler); mf("ab"); mf((UINT_MAX/2)+1); mf((UINT_MAX/2)+1.0); (2) they are not extensions of boost function but separate libraries. Kind regards, Marco On Fri, 06 Mar 2009 00:44:23 +0100, Jiøí Paleèek <jpalecek@web.de> wrote:
Hello,
I'd like to have an object similar to boost::function, but with multiple function signatures. Eg. something like that
multifunction<std::string(std::string), float(float), unsigned(unsigned)> mf; mf=_1 + _1; // I mean boost::lambda::_1 mf("ab"); // should be "abab" mf((UINT_MAX/2)+1); // should be 0 mf((UINT_MAX/2)+1.0); // should be UINT_MAX+1.0
Would it be possible/feasible to change boost::function to allow this (as opposed to implementing it separately from boost::function)? Was something like this even proposed before (I vaguely recall something, but couldn't google anything useful, so I may be wrong)?
Regards Jiri Palecek
-- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

On Fri, 06 Mar 2009 01:35:14 +0100, Marco <mrcekets@gmail.com> wrote:
Using my implementation you can get what you're interested in with the following code:
struct doubler { template< typename T> T operator() (const T& x) { return x + x; } };
boost::overload< std::string (std::string), float (float), unsigned (unsigned) > mf; mf.set(doubler); mf("ab"); mf((UINT_MAX/2)+1); mf((UINT_MAX/2)+1.0);
Sorry mf.set(doubler) is wrong, clearly. I mean: doubler dbl; mf.set(dbl); - Marco Cecchetti -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
participants (2)
-
Ji�� Pale�ek
-
Marco