Is there any way to not "use" the loop variable in a range-based for loop, but also avoid compiler warnings about it being unused?
For context, I'm trying to do something like the following. I have "treat warnings as errors" enabled, and I'd rather not do a hack like forcing the variable to be "used" by pointlessly mentioning it somewhere.
size_t getSize(const std::forward_list &list)
{
size_t count = 0;
for (auto & : list) // compile error, but if i do "auto &i" here, MSVC
// complains (reasonably) that i is unused
{
++count;
}
return count;
}
I know there are other ways to do this, but let's say for argument's sake that I need to use a range-based for loop.