Nice way to portably "assign within conditional expressions" without
warnings (or pragmas)?
I have a piece of code like this:
bool finished = false;
for (Iterator i = begin; i != end || (finished = !finished); finished ? i
: ++i)
{
    // (body)
}
The goal is to execute the body for all iterators including end().
I get "assignment within conditional expression" warnings from compilers
like Visual C++.
What's the simplest way to avoid these warnings?
I don't want to turn them off (they're helpful) and I don't want to insert
#pragmas (they're not portable between compilers).
I just want to write something short that will tell the typical compiler,
"yes, I intend to assign here".
The simplest solution I've found is to make a function (e.g. assign) and
call that instead, but I'm wondering if there is any way that would also
avoid defining a new function just for this.
 
No comments:
Post a Comment