I came across a difference in behavior for Boost.Function between g++
4.2 and 4.3, and I was wondering whether my usage was incorrect. I'm using
default parameters in much the same way as the sample test.cc below. It
compiles on 4.2, and does not on 4.3. I think I can see why perhaps it
shouldn't have worked, but I'm just looking for a security blanket. If my
usage is wrong, it might be worth a mention in the docs, since (to me) either
answer is non-intuitive.
g++-4.2 4.2.4 (4.2.4-3ubuntu4)
g++-4.3 4.3.2 (4.3.2-1ubuntu11)
boost 1.35 (1.35.0-8ubuntu1)
cat << EOF > test.cc
#include <iostream>
#include
struct add1 {
int operator()(int x, int y = 1) const { return x + y; }
};
int add2(int x, int y = 1) { return x + y; }
int main()
{
boost::function adder1 = add1();
boost::function adder2 = add2; // compile error here
std::cout << adder1(1) << adder2(1) << std::endl;
return 0;
}
EOF
mike@hyperion:~> g++-4.2 -Wall -Wextra test.cc -o test && ./test
22
mike@hyperion:~> g++-4.3 -Wall -Wextra test.cc -o test && ./test
/usr/include/boost/function/function_template.hpp: In static member
function 'static R
boost::detail::function::function_invoker1::invoke(boost::detail::function::function_buffer&, T0) [with
FunctionPtr = int (*)(int, int), R = int, T0 = int]':
/usr/include/boost/function/function_template.hpp:787: instantiated
from 'void boost::function1::assign_to(const
Functor&) [with Functor = int (*)(int, int), R = int, T0 = int,
Allocator = std::allocator<void>]'
/usr/include/boost/function/function_template.hpp:624: instantiated
from 'boost::function1::function1(Functor, typename
boost::enable_if_c::type)
[with Functor = int (*)(int, int), R = int, T0 = int, Allocator =
std::allocator<void>]'
/usr/include/boost/function/function_template.hpp:886: instantiated
from 'boost::function::function(Functor, typename
boost::enable_if_c::type)
[with Functor = int (*)(int, int), R = int, T0 = int, Allocator =
std::allocator<void>]'
test.cc:13: instantiated from here
/usr/include/boost/function/function_template.hpp:100: error: too few
arguments to function