Showing posts with label iterators. Show all posts
Showing posts with label iterators. Show all posts

Thursday, March 27, 2025

raw_storage_iterator

Overview
The output iterator raw_storage_iterator makes it possible for standard algorithms to store results in uninitialized memory.

Details
Regular iterators operate on a certain type of objects, which have already been constructed. A raw_storage_iterator wraps one of these regular iterators into a special output iterator which constructs objects at the location being pointed before being written.
Whenever the algorithm writes an object of type T to the dereferenced iterator, the object is copy-constructed into the location in the uninitialized storage pointed to by the iterator. 

Syntax
The syntax is as below. 
template< class OutputIterator,
          class T>
class raw_storage_iterator;

NameDescription
OutputIteratorUnderlying iterator type.
TType of objects to be constructed on each element location.

Members
 It defines following types.
member typedefinition
iterator_categoryoutput_iterator_tag
value_typevoid
difference_typevoid
pointervoid
referencevoid

Operation
An raw_storage_iterator as an output iterator supports operators *, ++, and =. 

 Functionality
Constructors
NameDescription
raw_storage_iterator( OutputIt  it)
Initializes the iterator to point to the same value as it points.

Overloaded operators
NameDescription
raw_storage_iterator & operator*()  Does nothing. Returns a reference to the object.
  1. raw_storage_iterator & operator++()
  2. raw_storage_iterator & operator++(int)
 Advances the iterator.
  1. Pre-increment. Returns the updated iterator.
  2. Post-increment. Returns the old value of the iterator.
raw_storage_iterator & operator=
(
const T& value)
Constructs a new object of type T at the location pointed by the iterator and initializes
its value to a copy of the argument used as right-hand side of the operator.

Example:
    string numbers[] = {"one", "two", "three", "four"};
    size_t sz = sizeof(numbers);
    char *buf = new char[sizeof(string)*sz];
    string *sbuf = reinterpret_cast<string*>(buf);

    auto last = copy(begin(numbers), end(numbers), 
      raw_storage_iterator<string*, string>(sbuf));

    //prints one two three four 
    for (auto itr = sbuf; itr != sbuf+sz; ++itr)
        cout << *itr  << " ";

    for (auto itr = sbuf; itr != sbuf+sz; ++itr)
        itr->~string();
    
   delete[] buf;



Wednesday, October 23, 2024

ostreambuf_iterator

 
Overview
IOStream classes provides iterators for reading and writing from streams just like a containers. ostreambuf_iterator enables writing characters to the stream.

Details
ostream iterators are output iterators that write successive characters from an output stream (such as cout).

They are constructed from a basic_ostream object, to which they become associated, so that whenever an assignment operator (=) is used on the ostream_iterator (dereferenced or not) it inserts a new element into the stream.

Syntax
The syntax is as below. 
template< class CharT = char,
          class Traits = char_traits<CharT>
class ostreambuf_iterator;

NameDescription
charTCharacter type of the associated istream object.
traitsCharacter traits of the associated istream object.

Members
 It defines following types.
member typedefinition
iterator_categoryoutput_iterator_tag
value_typecharT
difference_typevoid
pointervoid
referencevoid

Operation
An ostreambuf_iterator  as an output iterator supports operators *, ++, and =. 

ostreambuf_iterator  is a single-pass  output iterator that writes successive  characters  into the basic_ostream object for which it was constructed, using operator<<. Optional delimiter string is written to the output stream after every write operation. The write operation is performed when the iterator (whether dereferenced or not) is assigned to. Incrementing the ostreambuf_iterator   is a no-op.

In other words, unlike in a list or a vector, the iterator solely depends on the current position of the stream iterator of the stream object. 

sentry object is not constructed and destructed once per character.

In a typical implementation, the only data members of ostreambuf_iterator   are a pointer to the associated basic_ostream object.

This can be clearly seen in the example below. 
wstring msg = L"Hello, Khri$ha!";
//same as wcout << msg;
copy (begin(msg), end(msg), ostreambuf_iterator<wchar_t>(wcout));



Functionality
Constructors
NameDescription
  1. ostream_iterator( ostream_type& s)
  2. ostream_iterator( streambuf_type *buf);
  1. Constructs from a stream
  2. Constructs from a streambuf;
Example:
//1
wstring msg = L"Hello, Khri$ha!";
//same as wcout << msg;
copy (begin(msg), end(msg), ostreambuf_iterator<wchar_t>(wcout));

//2
wstringstream ss;
//same as wstringstream ss(L"Hello, Khri$ha!")

copy (begin(msg), end(msg), ostreambuf_iterator<wchar_t>(ss.rdbuf()));
wcout << endl << ss.str();
ostreambuf_iterator (const ostreambuf_iterator& x)
copy constructor
Constructs an ostreambuf iterator, with the same ostreambuf reference.

Example:
ostreambuf_iterator<char> it(cout), it2(it);
//prints kr
*it='k';
it2='r';

Overloaded operators
NameExample
ostreambuf_iterator& operator*() 
Does nothing.

  1. ostreambuf_iterator& operator++()
  2. ostreambuf_iterator& operator++(int)
Does nothing.
ostreambuf_iterator& operator=(const T& value) Writes to the stream.

Example:
ostreambuf_iterator<char> it(cout);
//prints kr
*it='k';
it2='r';


istreambuf_iterator


Overview
IOStream classes provides iterators for reading and writing raw without formatting from streams just like a containers. istreambuf_iterator enables reading from the streams.

Details
istreambuf iterators are input iterators that read successive characters from an input stream (such as cin).

They are constructed from a basic_istream object, to which they become associated, so that whenever operator++ is used on the iterator, it extracts a character from the stream (using operator>>).

Syntax
The syntax is as below. 

template< class CharT = char,
          class Traits = char_traits<CharT>
class istreambuf_iterator;

NameDescription
charTCharacter type of the associated istream object.
traitsCharacter traits of the associated istream object.

Members
 It defines following types.
member typedefinition
iterator_categoryinput_iterator_tag
value_typecharT
difference_typeTraits::off_type
pointerconst charT*
referenceconst charT&

Operation
An istreambuf_iterator  as an input iterator supports operators *, ++,->, == , and !=. 
istreambuf_iterator is a single-pass input iterator that reads successive objects of type charT  from the basic_istream object (such as cin) for which it was constructed, by internally calling the appropriate operator >>. The actual read operation is performed when the iterator is incremented, not when it is dereferenced. The first object is read when the iterator is constructed. Dereferencing only returns a copy of the most recently read object.

In other words, unlike in a list or a vector, the iterator solely depends on the current position of the stream iterator of the stream object. 

The default-constructed istreambuf_iterator is known as the end-of-stream iterator. When a valid istreambuf_iterator  reaches the end of the underlying stream, it becomes equal to the end-of-stream iterator. 

istreambuf_iterator does not skip whitespace. Also a sentry object is not constructed while reading.

istreambuf_iterator  class also has a subclass called proxy which can be converted back to istreambuf_iterator. It's returned by post-increment operator.

This can be clearly seen in the example below. 
istringstream in{"Hello, world"};
istreambuf_iterator<char> it{in}, end;
//ss:"Hello, world"
string ss{it, end};
 
// single-pass
istringstream s{"abc"};
istreambuf_iterator<char> i1{s}, i2{s};
//prints a a
cout << *i1 << " " << *i2 << endl;

//prints b b
++i1;
cout << *i1 << " " << *i2 << endl;

//prints c c
++i2;  
cout << *i1 << " " << *i2 << endl;

Functionality
Constructors
NameDescription
istreambuf_iterator()Default Constructor. Creates end of stream iterator.

Example:
istream_iterator eos;
istream_iterator( istream_type& s)
istream_iterator( istream_type *s)

Initializes the iterator, stores the address of stream s, and performs the first read from the input stream to initialize the cached value data member.
Example:
istringstream ss{"abcd"};
istreambuf_iterator<char>  it(ss);
//prints a
cout << *it  << endl;
istream_iterator (const istream_iterator& x)
copy constructor
Constructs an istream iterator, with the same istream reference and current value.
Example:
istringstream ss{"abcd"};
istreambuf_iterator<char>  it(ss), it2(it++);
//prints ba
cout << *it  << *it2 << endl;

Overloaded operators
NameExample
reference operator*() 
Returns a reference to the element pointed by the iterator.
Internally, the function returns the value the object stores as its current element.
Example:
istringstream ss{"abcd"};
istreambuf_iterator<char>  it(ss);
//prints a
cout << *it  << endl;
  1. istream_iterator& operator++()
  2. istream_iterator& operator++(int)
Reads a value from the underlying stream (using its operator>>) and stores it into the iterator object. If the read fails (the underlying stream's fail() returns true), the iterator becomes the end-of-stream iterator.
Example:
istringstream ss{"abcd"};
istreambuf_iterator<char>  it(ss), it2;

it2 = it++;
//prints b a
cout << *it  << " " << *it2 << endl;

it=++it2;
//prints c c
cout << *it  << " " << *it2  << endl;

Tuesday, October 22, 2024

ostream_iterator

 
Overview
IOStream classes provides iterators for reading and writing from streams just like a containers. ostream_iterator enables writing objects to the stream.

Details
ostream iterators are output iterators that write successive elements from an output stream (such as cout).

They are constructed from a basic_ostream object, to which they become associated, so that whenever an assignment operator (=) is used on the ostream_iterator (dereferenced or not) it inserts a new element into the stream.

Optionally, a delimiter can be specified on construction. This delimiter is written to the stream after each element is inserted.

Syntax
The syntax is as below. 

template< class T,
          class CharT = char,
          class Traits = char_traits<CharT>
class ostream_iterator;

NameDescription
TRepresents Element type for the iterator: The type of elements written to the stream
charTCharacter type of the associated istream object.
traitsCharacter traits of the associated istream object.

Members
 It defines following types.
member typedefinition
iterator_categoryoutput_iterator_tag
value_typeT
difference_typevoid
pointervoid
referencevoid

Operation
An ostream_iterator  as an output iterator supports operators *, ++, and =. 

ostream_iterator  is a single-pass  output iterator that writes successive objects of type T into the basic_ostream object for which it was constructed, using operator<<. Optional delimiter string is written to the output stream after every write operation. The write operation is performed when the iterator (whether dereferenced or not) is assigned to. Incrementing the ostream_iterator   is a no-op.

In other words, unlike in a list or a vector, the iterator solely depends on the current position of the stream iterator of the stream object. 

sentry object is constructed and destructed once per character.

In a typical implementation, the only data members of ostream_iterator   are a pointer to the associated basic_ostream object and a pointer to the first character in the delimiter string.

This can be clearly seen in the example below. 
vector<int> v(10),v2;
//v:{10,11,12,13,14,15,16,17,18,19 }
iota(begin(v),end(v),10);

stringstream ss;
copy ( v.begin(), v.end(), ostream_iterator<int> (ss," ") );

//v2:{10,11,12,13,14,15,16,17,18,19 }
copy ( istream_iterator<int>(ss), istream_iterator<int>(), back_inserter(v2));

//prints 10 11 12 13 14 15 16 17 18 19 
copy ( v.begin(), v.end(), ostream_iterator<int> (cout," ") );

ostream_iterator<char> it(cout), it2(it);
//prints kr
*it='k';
it2='r';

Functionality
Constructors
NameDescription
ostream_iterator( ostream_type& s ,
const char_type* delimiter = nullptr)
Constructs the iterator with stream as the associated stream, by storing the address of stream.
1) Uses delim as the delimiter.
2) Uses a null pointer as the delimiter.
If delimiter is specified, and is not a null pointer, it is inserted after every element is inserted in the stream.

Example:

vector<int> v(10);
//v:{10,11,12,13,14,15,16,17,18,19 }
iota(begin(v),end(v),10);

//prints 10,11,12,13,14,15,16,17,18,19
copy ( v.begin(), v.end(), ostream_iterator<int> (cout,",") );
ostream_iterator (const ostream_iterator& x)
copy constructor
Constructs an ostream iterator, with the same ostream reference.

Example:
ostream_iterator<char> it(cout), it2(it);
//prints kr
*it='k';
it2='r';

Overloaded operators
NameExample
ostream_iterator& operator*() 
Does nothing.

  1. ostream_iterator& operator++()
  2. ostream_iterator& operator++(int)
Does nothing.
ostream_iterator& operator=(const T& value) Writes to the stream.

Example:
ostream_iterator<char> it(cout);
//prints kr
*it='k';
it2='r';


Sunday, October 20, 2024

istream iterator

Overview
IOStream classes provides iterators for reading and writing from streams just like a containers. istream_iterator enables reading objects from the stream.

Details
istream iterators are input iterators that read successive elements from an input stream (such as cin).

They are constructed from a basic_istream object, to which they become associated, so that whenever operator++ is used on the iterator, it extracts an element from the stream (using operator>>).

Syntax
The syntax is as below. 

template< class T,
          class CharT = char,
          class Traits = char_traits<CharT>,
          class Distance = ptrdiff_t >
class istream_iterator;

NameDescription
TRepresents Element type for the iterator: The type of elements extracted from the stream
charTCharacter type of the associated istream object.
traitsCharacter traits of the associated istream object.
DistanceRepresent the difference between two iterators.

Members
 It defines following types.
member typedefinition
iterator_categoryinput_iterator_tag
value_typeT
difference_typeDistance
pointerconst T*
referenceconst T&

Operation
An istream_iterator  as an input iterator supports operators *, ++,->, == , and !=. 

istream_iterator is a single-pass input iterator that reads successive objects of type T from the basic_istream object (such as cin) for which it was constructed, by internally calling the appropriate operator >>. The actual read operation is performed when the iterator is incremented, not when it is dereferenced. The first object is read when the iterator is constructed. Dereferencing only returns a copy of the most recently read object.

In other words, unlike in a list or a vector, the iterator solely depends on the current position of the stream iterator of the stream object. 

The default-constructed istream_iterator is known as the end-of-stream iterator. When a valid istream_iterator  reaches the end of the underlying stream, it becomes equal to the end-of-stream iterator. 

When reading characters, istream_iterator skips whitespace by default. Also a sentry object is constructed and destructed once per character.

A typical implementation of istream_iterator holds two data members: a pointer to the associated istream_iterator object and the most recently read value of type T.

This can be clearly seen in the example below. 
istringstream ss{"20   30   30"};

//Calculates sum of the numbers from the stream. skips white space
//prints 80
cout << accumulate (
    istream_iterator<int>(ss),
    istream_iterator<int>(), //EOS
    0) << endl << endl;

//iterator and stream object behavior
istringstream ss2{"abcd"};

//prints 0
cout << ss2.tellg()  << endl;

istream_iterator<char>  it(ss2), it2(it);
//prints a a 1
cout << *it  << " " << *it2 << " "  << ss2.tellg() << endl;

++it;
//prints b a 2
cout << *it  << " " << *it2 << " "  << ss2.tellg() << endl;

//prints c
char c;
ss2 >> c;
cout << c << endl;

//prints b d 3
cout << *it  << " " << *it2 << " "  << ss2.tellg() << endl;
    
++it2;
//prints b d 4
cout << *it  << " " << *it2 << " "  << ss2.tellg() << endl;

Functionality
Constructors
NameDescription
istream_iterator()Default Constructor. Creates end of stream iterator.

Example:
istream_iterator eos;
istream_iterator( istream_type& s)Initializes the iterator, stores the address of stream s, and performs the first read from the input stream to initialize the cached value data member.
Example:
istringstream ss{"abcd"};
istream_iterator<char>  it(ss);
//prints a
cout << *it  << endl;
istream_iterator (const istream_iterator& x)
copy constructor
Constructs an istream iterator, with the same istream reference and current value.
Example:
istringstream ss{"abcd"};
istream_iterator<char>  it(ss), it2(it++);
//prints ba
cout << *it  << *it2 << endl;

Overloaded operators
NameExample
reference operator*() 
Returns a reference to the element pointed by the iterator.
Internally, the function returns the value the object stores as its current element.
Example:
istringstream ss{"abcd"};
istream_iterator<char>  it(ss);
//prints a
cout << *it  << endl;
  1. istream_iterator& operator++()
  2. istream_iterator& operator++(int)
Reads a value from the underlying stream (using its operator>>) and stores it into the iterator object. If the read fails (the underlying stream's fail() returns true), the iterator becomes the end-of-stream iterator.
Example:
istringstream ss{"abcd"};
istream_iterator<char>  it(ss), it2;

it2 = it++;
//prints b a
cout << *it  << " " << *it2 << endl;

it=++it2;
//prints c c
cout << *it  << " " << *it2  << endl;
pointer operator->() Returns reference to the member of the class.

Example:
struct rect
{
    int  h,w;
};

istream& operator>>(istream& is,  rect& r)
{
    is >> r.h;
    is >> r.w;
    return is;
}

rect r;
istringstream ss("4 5");

istream_iterator<rect>  it(ss);

//prints 4 5
cout << it->h << " " << it->w;



Thursday, October 17, 2024

move_iterator adaptor

Overview
move_iterator behaves like a normal iterator except dereferenced element converted  into a rvalue as if  move() is called on it.

Details
A copy of the original iterator (the base iterator) is kept internally and used to reflect the operations performed on the move_iterator. A copy of the base iterator with the current state can be obtained at any time by calling member base.

Syntax
The syntax is as below. Template parameter Iter represents the original iterator for which move_iterator is created. Iter can be bidirectional iterator or a random-access iterator
template < class Iter > 
class  reverse iterator;

Members
 It defines following types.
member typedefinition
iterator_typeIter
iterator_categoryiterator_traits<Iter>::iterator_category
value_typeiterator_traits<Iter>::value_type
difference_typeiterator_traits<Iter>::difference_type
pointeriterator_traits<Iter>::pointer
referencevalue_type&&

Operation
move_iterator behaves like a regular iterator except dereferencing converts the element to a rvalue.
This can be clearly seen in the example below. 
vector<string> v{"one","two","three"},v2;

//same as
//for_each(begin(v),end(v),[&v2](string& s){back_inserter(v2) = move(s);});
move_iterator<vector<string>::iterator> itrbeg(v.begin());
move_iterator<vector<string>::iterator> itrend(v.end());
//v:{"","",""}
//v2:{"one","two","three"}
copy(itrbeg, itrend, back_inserter(v2));

Functionality
Constructors
NameDescription
move_iterator()
Default constructor

Example:
vector<string> v{"one", "two", "three"};

move_iterator<vector<string>::iterator> mov;

//*mov="one"
mov = move_iterator(begin(v));
move_iterator(iterator_type itr)
Constructs a move_iterator from itr.

Example:
vector<string> v{"one", "two", "three"};
//*mov="one"
move_iterator<vector<string>::iterator> mov = move_iterator(begin(v));
move_iterator(const move_iterator& r)
Copy constructor.

Example:
vector<string> v{"one", "two", "three"};
//*mov="one"
move_iterator<vector<string>::iterator> mov = move_iterator(begin(v));

//*mov="one" *mov2="one"
move_iterator<vector<string>::iterator> mov2(mov);

Overloaded operators
NameExample
reference operator*() Returns reference to the element at current position of the reverse iterator that can be used to read or write.

Example:
vector<string> v{"one", "two", "three"};
//*mov="one"
move_iterator<vector<string>::iterator> mov = move_iterator(begin(v));

//prints "one"
cout << *mov;
//s = "one" *mov=""
auto s = *mov;
  1. move_iterator& operator++()
  2. move_iteratoroperator++(int)
  1. Returns a reference to self after incrementing of its position. 
  2. Returns copy of self and increments its position. returns new reference 
Example:
vector<string> v{"one", "two", "three"};
//*mov="one"
move_iterator<vector<string>::iterator> mov = move_iterator(begin(v)), mov2;

//pre ++
//mov="two" mov2="one"
mov2 = mov++;
    
//post ++
//mov="two" mov2="two"
mov = ++mov2;
  1. move_iterator& operator--()
  2. move_iteratoroperator--(int)
  1. Returns a reference to self after decrementing of its position. 
  2. Returns copy of self and decrements its position.eturns reference 
Example:
vector<string> v{"one", "two", "three"};
//*mov="one"
move_iterator<vector<string>::iterator> mov = move_iterator(begin(v)), mov2;

//*mov="two"
++mov;
    
//pre --
//mov2="two" mov="one"
mov2 = mov--;


//post --
//mov2="one" mov="one"
mov = --mov2;
move_iteratoroperator=(const move_iterator<Iter2>& movAssigns iterator.

Example:
vector<pair<string,string>> v{{"one", "two"}};
move_iterator<vector<pair<string,string>>::iterator> mov;

//*mov = "one"
mov = move_iterator(begin(v));
pointer operator->() Returns member of the element from a class object,

Example:
vector<pair<string,string>> v{{"one", "two"}};
move_iterator<vector<pair<string,string>>::iterator> mov = move_iterator(begin(v));

//s= "one" p:{"one", "two"}
auto s = mov->first;

//p:{"one", "two"} *mov={"",""}
auto p = *mov;
/*unspecified*/ operator[] (difference_type n) Returns reference to the element after adding in the index.

Example:
vector<string> v{"one", "two", "three"};
//*mov="one"
move_iterator<vector<string>::iterator> mov = move_iterator(begin(v));

//*mov="two"
++mov;
    
//[]
//s="two" s2="one" s3="three"
//mov[0]="" mov[-1]="" mov[1]=""
auto s=mov[0], s2=mov[-1], s3=mov[1];
move_iterator operator+ (difference_type n)Returns iterator after adding index to the iterator.

Example:
vector<string> v{"one", "two", "three"};
//*mov="one"
move_iterator<vector<string>::iterator> mov = move_iterator(begin(v)), mov2;

//+
//*mov2="two"
mov2 = mov+1;
move_iterator operator- (difference_type n)Returns iterator after subtracting index to the iterator.

Example:
vector<string> v{"one", "two", "three"};
//*mov="one"
move_iterator<vector<string>::iterator> mov = move_iterator(begin(v)), mov2;

//*mov="two"
++mov;
//- //*mov2="one" mov2 = mov-1;
move_iterator operator-= (difference_type n)Subtracts index to self.

Example:
vector<string> v{"one", "two", "three"};
//*mov="one"
move_iterator<vector<string>::iterator> mov = move_iterator(begin(v));

//*mov="two"
++mov;
//-= //*mov="one" mov-= 1;
move_iterator  operator+= (difference_type n)Adds index to self.

Example:
vector<string> v{"one", "two", "three"};
//*mov="one"
move_iterator<vector<string>::iterator> mov = move_iterator(begin(v));

//+=
//*mov="two" mov+= 1;

Iterator
NameDescription
iterator_type base()

Returns a copy of the base iterator.

Example:
vector<string> v{"one", "two", "three"};
//*mov="one"
move_iterator<vector<string>::iterator> mov = move_iterator(begin(v));

//s = "one", *mov="one"
auto s = *mov.base();

External overloaded operators
NameDescription
move_iterator <Iterator> operator+ (difference_type n,
const move_iterator <Iterator>& rev_it)
Returns move iterator after adding n to the iterator.

Example:
vector<string> v{"one", "two", "three"};
//*mov="one"
move_iterator<vector<string>::iterator> mov = move_iterator(begin(v)), mov2;
//*mov2="two"
mov2 = 1 + mov;
difference_type  operator-(const move_iterator <Iterator>& first_it, 
const move_iterator <Iterator>& second_it)
Returns distance between two move iterators. i.e., second_it-first_it.

Example:

vector<string> v{"one", "two", "three"};
//*mov="one" 
move_iterator<vector<string>::iterator> 
    mov = move_iterator(begin(v)), 
    mov2 = move_iterator(end(v));

    
//d=3
auto d = mov2-mov;
cout << d;
  1. bool operator== (const move_iterator <iter>& lhs,
    const move_iterator <iter2>& rhs)
  2. bool operator!= (const move_iterator <iter>& lhs,
    const move_iterator <iter2>& rhs)
  3. bool operator> (const move_iterator <iter>& lhs,
    const move_iterator <iter2>& rhs)
  4. bool operator<(const move_iterator <iter>& lhs,
    const move_iterator <iter2>& rhs)
  5. bool operator>=(const move_iterator <iter>& lhs,
    const move_iterator <iter2>& rhs)
  6. bool operator<=(const move_iterator <iter>& lhs,
    const move_iterator <iter2>& rhs)
Relational Operators.

Example:

vector<string> v{"one", "two", "three"};
//*mov="one" mov2=""
move_iterator<vector<string>::iterator> 
    mov = move_iterator(begin(v)), 
    mov2 = move_iterator(end(v));

//== != < > >= <= //mov == mov2 F
//mov != mov2 T
//mov > mov2 F
//mov >= mov2 F
//mov < mov2 T
//mov <= mov2 T


make_move_iterator
An utility function to create a move iterator from an legacy iterator which can be a bidirectional iterator or a random-access iterator. .

Syntax
The syntax is as below. Template parameter Iter represents the original iterator for which reverse_iterator is created. Iter can be bidirectional iterator or a random-access iterator
template < class Iter > 
move_iterator<Iter> make_move_iterator( Iter i )

The following example shows its usage.
vector<string> v{"one", "two", "three"};
//*mov="one" 
move_iterator<vector<string>::iterator> 
    mov = make_move_iterator(begin(v)),