Consider following code:
typedef istream_iterator<char> char_itr ;
char_itr eos;
string ll("some text here");
istringstream line_in(ll);
char_itr start(line_in);
move_iterator<char_itr> mstart(start); // !!!
move_iterator<char_itr> meos(eos);
vector<char> vc(mstart, meos);
Above code will not compile because of line (!!!):
error C2440: 'return' : cannot convert from 'const char' to 'char &&'
But if you replace mstart
and meos
with start
and eos
, respectively (regular iterators), the code will compile. Why I can't make move_iterators
?
EDIT:
For those wondering why I would like to move a character from a stream/string. Actual problem involves more complex data type than char
which copying from a string should be avoided. char
was used just for the sake of simplicity, to present the mechanism causing error.