I'm writing a unit test for a custom container type. I want to make sure it contains the right number of elements.
int count = 0;
for (const auto &el : region) {
++count;
}
// Check that count is the right number
Because this code does not do anything with 'el', I get a compiler warning about an unused variable. How can one write a range-based for loop without declaring a "variable alias" like 'el'?
An old-fashioned for-loop that explicitly uses iterators would obviously solve this problem, but I'm just curious to know if it can be done with range-based for.
Aucun commentaire:
Enregistrer un commentaire