I looked at the STL sources for std::move_iterator<Iterator> and found out that it returns Iterator::value_type&& . This leads to incorrect behavior when Iterator::reference is a r value and does not match Iterator::value_type& .
I have a class with a proxy object as reference (e.g. in std::vector<bool> ) which can implicitly use for value_type . A regular iterator simply casts this proxy (this requires input-iterator requirements), but std::move_iterator causes a cast to value_type with overhead and then returns a link to the created temporary object.
std::move_iterator still works with std::vector<bool> for some reason (probably due to the fact that bool is a simple type and dangling bool&& does not cause an error), but not with my class. It bothers me, and I donโt understand how to fix it, I think this is a mistake in the STL.
Here is the simplified part of the source for std::move_iterator from GCC 4.8.1:
template <typename Iterator> class move_iterator { public: typedef typename iterator_traits<Iterator>::value_type value_type; typedef value_type&& reference; reference operator*() const { return std::move(*it); } private: Iterator it; };
source share