Junior — Senior
Verification of range-based for correctness for a custom container
livecode
Task condition
It is necessary to determine whether the following code fragment will compile and work as expected. The IntContainer structure contains a std::vector<int> and is used in a range-based for loop. Question: will the expression for (const auto& element : container) compile and execute correctly?
struct IntContainer {
std::vector<int> vec;
};
void testRange() {
IntContainer container;
for (const auto& element : container) {
// ...
}
}