Problems with if_then_else_return in boost::lambda library
Hi, If I have a vector of strings vector<string> v; v.push_back("One"); v.push_back("Two"); v.push_back("Three"); v.push_back("Four"); v.push_back("Five"); and define arithmetic action plus like this: namespace boost { namespace lambda { struct plain_return_type_2<arithmetic_action<plus_action>, std::string, std::string> { typedef std::string type; }; } } then the following code works just fine: cout << accumulate(v.begin()+1, v.end(), v.front(), _1 + string(", ") + _2) << endl; and the following also works wonderfully: int i = 1; cout << accumulate(v.begin()+1, v.end(), v.front(), _1 + bind(constructor<string>(), var(i)++, ' ') + _2) << endl; Now, if I want to use if_then_else_return as shown below, it fails miserably, producing a huge error message: cout << accumulate(v.begin(), v.end(), string(), if_then_else_return(_1 == string(), _1, _1 + bind(constructor<string>(), var(i)++, ' ') + _2)) << endl; Now for the questions: What is the proper way to use if_then_else_return? Why do I need to define a separate arithmetic action for strings, even though they are a common library type? Is there a way to say the most intuitive: cout << accumulate(v.begin()+1, v.end(), v.front(), _1 + ", " + _2) << endl; Is there way to do more intuitive: cout << accumulate(v.begin()+1, v.end(), v.front(), _1 + string(i++, ' ') + _2) << endl; Thank you for your help. Robert Ioffe [Non-text portions of this message have been removed]
participants (1)
-
Ioffe, Robert