]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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/detail/no_exceptions_support.hpp> | |
30 | ||
31 | namespace boost { | |
32 | ||
33 | ////////////////////////////////////////////////////////////////////////////// | |
34 | // | |
35 | // move | |
36 | // | |
37 | ////////////////////////////////////////////////////////////////////////////// | |
38 | ||
39 | #if !defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE) | |
40 | ||
41 | //! <b>Effects</b>: Moves elements in the range [first,last) into the range [result,result + (last - | |
42 | //! first)) starting from first and proceeding to last. For each non-negative integer n < (last-first), | |
43 | //! performs *(result + n) = ::boost::move (*(first + n)). | |
44 | //! | |
45 | //! <b>Effects</b>: result + (last - first). | |
46 | //! | |
47 | //! <b>Requires</b>: result shall not be in the range [first,last). | |
48 | //! | |
49 | //! <b>Complexity</b>: Exactly last - first move assignments. | |
50 | template <typename I, // I models InputIterator | |
51 | typename O> // O models OutputIterator | |
52 | O move(I f, I l, O result) | |
53 | { | |
54 | while (f != l) { | |
55 | *result = ::boost::move(*f); | |
56 | ++f; ++result; | |
57 | } | |
58 | return result; | |
59 | } | |
60 | ||
61 | ////////////////////////////////////////////////////////////////////////////// | |
62 | // | |
63 | // move_backward | |
64 | // | |
65 | ////////////////////////////////////////////////////////////////////////////// | |
66 | ||
67 | //! <b>Effects</b>: Moves elements in the range [first,last) into the range | |
68 | //! [result - (last-first),result) starting from last - 1 and proceeding to | |
69 | //! first. For each positive integer n <= (last - first), | |
70 | //! performs *(result - n) = ::boost::move(*(last - n)). | |
71 | //! | |
72 | //! <b>Requires</b>: result shall not be in the range [first,last). | |
73 | //! | |
74 | //! <b>Returns</b>: result - (last - first). | |
75 | //! | |
76 | //! <b>Complexity</b>: Exactly last - first assignments. | |
77 | template <typename I, // I models BidirectionalIterator | |
78 | typename O> // O models BidirectionalIterator | |
79 | O move_backward(I f, I l, O result) | |
80 | { | |
81 | while (f != l) { | |
82 | --l; --result; | |
83 | *result = ::boost::move(*l); | |
84 | } | |
85 | return result; | |
86 | } | |
87 | ||
88 | #else | |
89 | ||
90 | using ::std::move_backward; | |
91 | ||
92 | #endif //!defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE) | |
93 | ||
94 | ////////////////////////////////////////////////////////////////////////////// | |
95 | // | |
96 | // uninitialized_move | |
97 | // | |
98 | ////////////////////////////////////////////////////////////////////////////// | |
99 | ||
100 | //! <b>Effects</b>: | |
101 | //! \code | |
102 | //! for (; first != last; ++result, ++first) | |
103 | //! new (static_cast<void*>(&*result)) | |
104 | //! typename iterator_traits<ForwardIterator>::value_type(boost::move(*first)); | |
105 | //! \endcode | |
106 | //! | |
107 | //! <b>Returns</b>: result | |
108 | template | |
109 | <typename I, // I models InputIterator | |
110 | typename F> // F models ForwardIterator | |
111 | F uninitialized_move(I f, I l, F r | |
112 | /// @cond | |
113 | // ,typename ::boost::move_detail::enable_if<has_move_emulation_enabled<typename boost::movelib::iterator_traits<I>::value_type> >::type* = 0 | |
114 | /// @endcond | |
115 | ) | |
116 | { | |
117 | typedef typename boost::movelib::iterator_traits<I>::value_type input_value_type; | |
118 | ||
119 | F back = r; | |
120 | BOOST_TRY{ | |
121 | while (f != l) { | |
122 | void * const addr = static_cast<void*>(::boost::move_detail::addressof(*r)); | |
123 | ::new(addr) input_value_type(::boost::move(*f)); | |
124 | ++f; ++r; | |
125 | } | |
126 | } | |
127 | BOOST_CATCH(...){ | |
128 | for (; back != r; ++back){ | |
129 | back->~input_value_type(); | |
130 | } | |
131 | BOOST_RETHROW; | |
132 | } | |
133 | BOOST_CATCH_END | |
134 | return r; | |
135 | } | |
136 | ||
137 | /// @cond | |
138 | /* | |
139 | template | |
140 | <typename I, // I models InputIterator | |
141 | typename F> // F models ForwardIterator | |
142 | F uninitialized_move(I f, I l, F r, | |
143 | typename ::boost::move_detail::disable_if<has_move_emulation_enabled<typename boost::movelib::iterator_traits<I>::value_type> >::type* = 0) | |
144 | { | |
145 | return std::uninitialized_copy(f, l, r); | |
146 | } | |
147 | */ | |
148 | ||
149 | /// @endcond | |
150 | ||
151 | } //namespace boost { | |
152 | ||
153 | #include <boost/move/detail/config_end.hpp> | |
154 | ||
155 | #endif //#ifndef BOOST_MOVE_ALGO_MOVE_HPP |