I am very new to C ++ 11 and there is a problem with iterators and uniform initialization that I don't understand.
Consider the following example, which does not compile:
#include <iostream>
#include <vector>
int main() {
std::vector<int> t{1, 2, 3, 4, 5};
auto iter{t.begin()};
for (; iter != t.end(); ++iter) {
std::cout << *iter;
}
return 0;
}
In line 6, the vector is initialized using uniform initialization. On line 7, I'm trying to do the same with an iterator. This does not work. Changing line 7 to auto iter = t.begin()is OK. I know that I can simply use a range-based range for this, but the question arises: why does uniform initialization not work with iterators, but is it good with basic types, for example int i{0};?
source
share