Boost logo

Boost Users :

Subject: Re: [Boost-users] Default argument values with boost::function
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-04-30 15:22:17


On Thu, Apr 30, 2009 at 12:26 PM, Gennadiy Rozental <rogeeff_at_[hidden]> wrote:
> Artyom <sneg.vx <at> googlemail.com> 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.


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