Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is std::uninitialized_move absent?

Tags:

c++

c++11

stl

The C++11 standard library includes the following related algorithms:

template <class InputIterator, class ForwardIterator>
  ForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
                                     ForwardIterator result);

template <class ForwardIterator, class T>
  void uninitialized_fill(ForwardIterator first, ForwardIterator last,
                          const T& x);

template<class InputIterator, class OutputIterator>
  OutputIterator copy(InputIterator first, InputIterator last,
                      OutputIterator result);

template<class ForwardIterator, class T>
  void fill(ForwardIterator first, ForwardIterator last, const T& value);

template<class InputIterator, class OutputIterator>
  OutputIterator move(InputIterator first, InputIterator last,
                      OutputIterator result);

There is no standard uninitialized_move algorithm. Is this an oversight, or by design?

If it is by design, what is the rationale?

like image 977
Jared Hoberock Avatar asked Sep 20 '12 18:09

Jared Hoberock


1 Answers

You can get the effect of an uninitialized_move with uninitialized_copy and move iterators:

std::uninitialized_copy(std::make_move_iterator(first),
                        std::make_move_iterator(last),
                        out);

std::move exists even though it can also be implemented with std::copy and move iterators, because the committee anticipated its use to be frequent and decided to provide it as a convenience function [1][2].

like image 140
R. Martinho Fernandes Avatar answered Sep 20 '22 23:09

R. Martinho Fernandes