Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost::bind can't work with conditional expression?

Tags:

c++

boost

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;
}
like image 389
user869210 Avatar asked Sep 17 '11 10:09

user869210


1 Answers

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.

like image 145
Bo Persson Avatar answered Sep 30 '22 16:09

Bo Persson