hi,
I have just been working with boost::bind
and boost::function
and noticed the following behaviour (which I thought was a bit odd). You can bind a function with fewer parameters than required by the boost::function type! It appears as though any additional parameters are simply ignored and just fall away.
So why is this behaviour correct? My expectation would be that a compile error should be raised stating the incompatibility.
See below for working code example that shows the issue
#include "boost/bind.hpp"
#include "boost/function.hpp"
namespace
{
int binder(const char& testChar,
const int& testInt,
const std::string& testString)
{
return 3;
}
}
int main(int c, char** argv)
{
boost::function<int(const char&,
const int&,
const std::string&,
const float&,
const std::string&,
const int&)> test;
test = boost::bind(&::binder, _1, _2, _3);
std::cout << test('c', 1, "something", 1.f, "more", 10) << std::endl;
}