void test()
{
string s = " ,";
if (boost::trim_if(s, boost::is_any_of(" ,")), s.empty())
{
cout << "empty";
}
else
{
cout << s << endl;
}
}
According to this How does the Comma Operator work, the expression is supposed to equal to boost::trim_if() which returns void. But it can work now, so it executes boost::trim_if() and s.empty(). Can I rely on this kind of expression?
You maybe say I should write code like this:
boost::trim_if(s, boost::is_any_of(" ,"));
if (s.empty())
{
cout << "empty";
}
But I'm in a condition that our old code is
string s;
if(FAILED(GetStringFromAPI(s)) || s.empty() )
{
}
I want to just modify one line
if(FAILED(GetStringFromAPI(s)) || (boost::trim_if(...), s.empty()) )
{
}