
On Thu, Apr 30, 2009 at 12:26 PM, Gennadiy Rozental
Artyom
writes: Hi,
Is there any way to set default argument values with Boost::Function? On VS2008 SP1 I tried:
boost::function< void( unsigned i = 1 ) > increment;
I do not think you can do it, but you can bind the value when you create the instance.
For note, the reason this cannot be done is because C++ function types do not include overload information. Overloads are syntactic 'prettiness' handled by the compiler so if you have a function like this void myFunc(float f, int i=3); and you call it like myFunc(3.14);, it replaces that call with myFunc(3.14, 3);. Hence, it is a callsite change, not type information, and boost/std::Function only builds based on the function type. However, you can have things selectively pass variables as necessary as someone said in the most recent post.