When I uncomment the conditional expression, the program will fail to compile under visual c++ 2008.
#include <iostream>
#include <boost/bind.hpp>
#include <boost/thread.hpp>
typedef boost::function<void(int, int)> vii_t;
typedef boost::function<void(int)> vi_t;
void foo(int a, int b){}
void bar(int a){}
int main(int argc, char* argv[])
{
//vi_t test= true ? boost::bind(foo, _1, 100) : boost::bind(bar, _1);
vi_t test1 = boost::bind(foo, _1, 100);
vi_t test2 = boost::bind(bar, _1);
//test(1);
test1(1);
test2(1);
return 0;
}
In the expression c ? x : y
x and y must be of the same type, or one must be convertible to the other. That common type is the type of the whole expression.
Presumably, boost::bind
with different number of parameters return different types that are not convertible to each other. That they both might be convertible to vi_t
doesn't help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With