1//////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Ion Gaztanaga 2012-2016.
4// Distributed under the Boost Software License, Version 1.0.
5// (See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7//
8// See http://www.boost.org/libs/move for documentation.
9//
10//////////////////////////////////////////////////////////////////////////////
11
12//! \file
13
14#ifndef BOOST_MOVE_ALGO_MOVE_HPP
15#define BOOST_MOVE_ALGO_MOVE_HPP
16
17#ifndef BOOST_CONFIG_HPP
18# include <boost/config.hpp>
19#endif
20#
21#if defined(BOOST_HAS_PRAGMA_ONCE)
22# pragma once
23#endif
24
25#include <boost/move/detail/config_begin.hpp>
26
27#include <boost/move/utility_core.hpp>
28#include <boost/move/detail/iterator_traits.hpp>
29#include <boost/move/detail/iterator_to_raw_pointer.hpp>
30#include <boost/move/detail/addressof.hpp>
31#if defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE)
32#include <algorithm>
33#endif
34
35namespace boost {
36
37//////////////////////////////////////////////////////////////////////////////
38//
39// move
40//
41//////////////////////////////////////////////////////////////////////////////
42
43#if !defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE)
44
45 //! <b>Effects</b>: Moves elements in the range [first,last) into the range [result,result + (last -
46 //! first)) starting from first and proceeding to last. For each non-negative integer n < (last-first),
47 //! performs *(result + n) = ::boost::move (*(first + n)).
48 //!
49 //! <b>Effects</b>: result + (last - first).
50 //!
51 //! <b>Requires</b>: result shall not be in the range [first,last).
52 //!
53 //! <b>Complexity</b>: Exactly last - first move assignments.
54 template <typename I, // I models InputIterator
55 typename O> // O models OutputIterator
56 O move(I f, I l, O result)
57 {
58 while (f != l) {
59 *result = ::boost::move(*f);
60 ++f; ++result;
61 }
62 return result;
63 }
64
65 //////////////////////////////////////////////////////////////////////////////
66 //
67 // move_backward
68 //
69 //////////////////////////////////////////////////////////////////////////////
70
71 //! <b>Effects</b>: Moves elements in the range [first,last) into the range
72 //! [result - (last-first),result) starting from last - 1 and proceeding to
73 //! first. For each positive integer n <= (last - first),
74 //! performs *(result - n) = ::boost::move(*(last - n)).
75 //!
76 //! <b>Requires</b>: result shall not be in the range [first,last).
77 //!
78 //! <b>Returns</b>: result - (last - first).
79 //!
80 //! <b>Complexity</b>: Exactly last - first assignments.
81 template <typename I, // I models BidirectionalIterator
82 typename O> // O models BidirectionalIterator
83 O move_backward(I f, I l, O result)
84 {
85 while (f != l) {
86 --l; --result;
87 *result = ::boost::move(*l);
88 }
89 return result;
90 }
91
92#else
93
94 using ::std::move_backward;
95
96#endif //!defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE)
97
98//////////////////////////////////////////////////////////////////////////////
99//
100// uninitialized_move
101//
102//////////////////////////////////////////////////////////////////////////////
103
104//! <b>Effects</b>:
105//! \code
106//! for (; first != last; ++result, ++first)
107//! new (static_cast<void*>(&*result))
108//! typename iterator_traits<ForwardIterator>::value_type(boost::move(*first));
109//! \endcode
110//!
111//! <b>Returns</b>: result
112template
113 <typename I, // I models InputIterator
114 typename F> // F models ForwardIterator
115F uninitialized_move(I f, I l, F r
116 /// @cond
117// ,typename ::boost::move_detail::enable_if<has_move_emulation_enabled<typename boost::movelib::iterator_traits<I>::value_type> >::type* = 0
118 /// @endcond
119 )
120{
121 typedef typename boost::movelib::iterator_traits<I>::value_type input_value_type;
122
123 F back = r;
124 BOOST_MOVE_TRY{
125 while (f != l) {
126 void * const addr = static_cast<void*>(::boost::move_detail::addressof(*r));
127 ::new(addr) input_value_type(::boost::move(*f));
128 ++f; ++r;
129 }
130 }
131 BOOST_MOVE_CATCH(...){
132 for (; back != r; ++back){
133 boost::movelib::iterator_to_raw_pointer(back)->~input_value_type();
134 }
135 BOOST_MOVE_RETHROW;
136 }
137 BOOST_MOVE_CATCH_END
138 return r;
139}
140
141/// @cond
142/*
143template
144 <typename I, // I models InputIterator
145 typename F> // F models ForwardIterator
146F uninitialized_move(I f, I l, F r,
147 typename ::boost::move_detail::disable_if<has_move_emulation_enabled<typename boost::movelib::iterator_traits<I>::value_type> >::type* = 0)
148{
149 return std::uninitialized_copy(f, l, r);
150}
151*/
152
153/// @endcond
154
155} //namespace boost {
156
157#include <boost/move/detail/config_end.hpp>
158
159#endif //#ifndef BOOST_MOVE_ALGO_MOVE_HPP
160