You can build a vector with an iterator range, for example:
std::vector<std::string> vec(std::istream_iterator<std::string>{std::cin}, std::istream_iterator<std::string>{});
But I can also compile and run the code using the syntax of standard C ++ 11 simulation (note the handcuffs), for example:
std::vector<std::string> vec{std::istream_iterator<std::string>{std::cin}, std::istream_iterator<std::string>{}};
What's going on here?
I know that a constructor that has a list of initializers takes precedence over other forms of construction. Doesn't the compiler allow the constructor to accept a list of initializers containing 2 std::istream_iterator ? This should be an error, since std::istream_iterator cannot be converted to the std::string vector value type, right?
source share