Odd behaviour with istream_iterator
I'm using gcc 3.3.5. This code:
std::set<std::string> t(std::istream_iterator<std::string>(std::cin),
std::istream_iterator<std::string>());
gives a strange error message:
error: cannot use `::' in parameter declaration
If I try it this way:
std::istream_iterator<std::string> is(std::cin);
std::istream_iterator<std::string> eof();
std::set<std::string> t(is, eof);
it also gives an error:
error: no matching function for call to `std::set<*snip*>::set(*snip*)'
Strangely enough, this:
std::set<std::string> t((std::istream_iterator<std::string>(std::cin)),
std::istream_iterator<std::string>());
compiles and works just fine. The only difference is the extra
parentheses around the first parameter. I can't get the second version
above to compile regardless of any amount of parentheses anywhere.
Even more strangely, if I add the extra parentheses around the
second parameter, like this:
std::set<std::string> t((std::istream_iterator<std::string>(std::cin)),
(std::istream_iterator<std::string>()));
it once again doesn't compile:
error: syntax error before `)' token
I don't understand this. What's going on?