Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why couldnt we have moving iterators?

C++11 introduced a "move" algorithm that behaves like the "copy" algorithm except that it... moves the data instead of copying it. I'm wondering why the commitee didnt update the copy algorithm to use forward instead (or probably in addition to that).

A vector provides an iterator of T& A const vector provides an iterator of const T& Is there a reason why a vector&& couldnt provide an iterator of T&&? That would allow to move elements from say a list to a vector by using vector's constructor...

Is that a bad idea?

like image 253
anonymous Avatar asked Feb 22 '13 16:02

anonymous


People also ask

What is a move iterator?

move_iterator is an iterator adaptor with the same behavior as the underlying iterator except that its dereference operator implicitly converts the value returned by the underlying iterator's dereference operator to a rvalue reference: boost::move(*underlying_iterator) It is a read-once iterator, but can have up to ...

Does std :: move invalidate iterators?

std::move does nothing on its own. The move assignment definitely invalidates iterators on both sides, though.

What is the point of iterators?

The primary purpose of an iterator is to allow a user to process every element of a container while isolating the user from the internal structure of the container. This allows the container to store elements in any manner it wishes while allowing the user to treat it as if it were a simple sequence or list.

What is iterator ADT?

2.1 The iterator as an ADT Interface There is no single data type in C++ for iterators. Instead, “iterator” is a pattern that we adopt. Each different type of std container will provide it's own class that implements this pattern.


1 Answers

We have those already. Use std::make_move_iterator to create a move iterator.

like image 105
Kerrek SB Avatar answered Sep 21 '22 22:09

Kerrek SB