I was just saw code like this
/* whatever */ foo(std::string const& s) {
// stuff
auto L = s.length();
int i{/* init based on L */};
while (i < L) {
// do other stuff and maybe
++i;
}
}
and I was going to suggest that one can avoid defining L
and write
/* init based on s.length() */
and (i < s.length())
instead of /* init based on L */
and (i < L)
.
But who's really telling me that s.length()
doesn't change unpredictably because the argument corresponding to the s
parameter is changed by another concurrent thread?