Consider the following (a bit tricky) loop in C++:
using namespace std;
list<string> lst;
// Fill the list with some strings or keep it empty depending on something...
auto i = lst.begin(), e = lst.end();
string csv;
if(lst.size())
do
csv += *i;
while(++i != e && (csv += ", ", true));
The aim of it is to form the coma-separated string consisting of the initial list members. And it handle right the case of empty list. But I'm in doubt, if the second part of the while
condition may be optimised out by some (too) smart compiler. Is there any explanations in the standard on the cases like this one?
I understand that this "task" can be fulfilled via different ways, but I'm querying not about the CSV-string forming algorithm here.
Thank you.