I'm first time with C++ and I have a question about storing the "count" in a variable and calling .size().
Why did I have this question? Because I have an internal contradiction!
In all other languages that I have used, be it php, typescript or python, I have always written the count to a variable before iteration, because in all these languages it is considered good practice, php for example:
$count = count($arr);
for($i = 0; $i < $count; $i++) ...
But! I've looked at different sources of various open source c++ projects and you guys who use c++ seem to always do like this:
for (std::size_t i = 0; i < bt.size() && i < BACKTRACE_HASHED_LENGTH; i++) {
h = h * 0x4372897893428797lu + reinterpret_cast<std::uintptr_t>(bt[i]);
}
So, is it okay for C++ to always use .size()? Or how do you do it?