g++ allows this construction of an istream_iterator from an ifstream instance:
std::ifstream ifstr("test.txt");
std::istream_iterator<std::string> iter1(ifstr);
...but it doesn't allow the same construction with an unnamed temporary:
std::istream_iterator<std::string> iter2(std::ifstream("test.txt"));
This gives:
error: no matching function for call to ‘std::istream_iterator, ptrdiff_t>::istream_iterator(std::ifstream)’
Does anyone know why this doesn't work? - thanks!