I have read on some stackoverflow questions that post or pre-incrementing a variable in a function call can result in undefined behavior.
Since in a vector, the array element access operator, operator[]()
is a function call, is the same true for the following code example?
double p_step = 1.0 / (double)_progress_bar_chars.size();
int ixx = 0;
for(double p = 0.0; p < 1.0; p += p_step)
_progress_bar_chars[ixx ++] = (p <= progress ? '=' : ' ');
Does the above code produce undefined behavior?
For reference:
std::vector<char> _progress_bar_chars;
_progress_bar_chars.resize(50);
double progress = 0.5;
Finally, does it matter that I use a std::vector here rather than a pure array or heap-allocated array?