On Tue, Feb 23, 2010 at 11:59 AM, Igor R <boost.lists@gmail.com> wrote:
> To be able to choose one of them at runtime :-) ... I'm looking for something similar to boost::function<>, but which doesn't erase all type information.

Lets assume you've got 2 different functions with the same signature:
void f1(int i, double d);
void f2(int i, double d);

What do you loose by putting them into boost::function<void(int, double)>?

You lose the ability 

a) To use a function *object* which contains state
b) To use different pre & post call logic depending on which function is selected.  

Using a variant, you can imagine it ultimately boiling down to a large "behind the scenes" if-then-else block that selects which object is to be invoked.  However, instead of simply doing the invoke, variant gives you the flexibility of specifying arbitrary code to run both before and after the invocation.

Also, boost::function<> has quite a high overhead compared to variant.  

Zach