diff --git a/cpplinq.hpp b/cpplinq.hpp index 3f9bcaa..3d5ed4c 100644 --- a/cpplinq.hpp +++ b/cpplinq.hpp @@ -534,36 +534,44 @@ namespace cpplinq container_type&& container ) : container (std::move (container)) - , current (container.begin ()) - , upcoming (container.begin ()) - , end (container.end ()) { + upcoming = current = this->container.begin(); + end = this->container.end(); } CPPLINQ_INLINEMETHOD from_copy_range ( container_type const & container ) : container (container) - , current (container.begin ()) - , upcoming (container.begin ()) - , end (container.end ()) { + upcoming = current = this->container.begin(); + end = this->container.end(); } CPPLINQ_INLINEMETHOD from_copy_range (from_copy_range const & v) : container (v.container) - , current (v.current) - , upcoming (v.upcoming) - , end (v.end) { + iterator_type s_b = v.container.begin(); + auto d_c = std::distance(s_b, v.current); + auto d_u = std::distance(v.current, v.upcoming); // upcoming is never before current. + current = container.begin(); + std::advance(current, d_c); + upcoming = current; + std::advance(upcoming, d_u); + end = container.end(); // end must re-create from new container. } CPPLINQ_INLINEMETHOD from_copy_range (from_copy_range && v) CPPLINQ_NOEXCEPT - : container (std::move (v.container)) - , current (std::move (v.current)) - , upcoming (std::move (v.upcoming)) - , end (std::move (v.end)) { + iterator_type s_b = v.container.begin(); + auto d_c = std::distance(s_b, v.current); + auto d_u = std::distance(v.current, v.upcoming); // upcoming is never before current. + container = std::move(v.container); + current = container.begin(); + std::advance(current, d_c); + upcoming = current; + std::advance(upcoming, d_u); + end = container.end(); // end must re-create from new container. } template