Blaze 3.9
UninitializedMove.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_UTIL_ALGORITHMS_UNINITIALIZEDMOVE_H_
36#define _BLAZE_UTIL_ALGORITHMS_UNINITIALIZEDMOVE_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <iterator>
44#include <memory>
46#include <blaze/util/Types.h>
47
48
49namespace blaze {
50
51//=================================================================================================
52//
53// UNINITIALIZED_MOVE ALGORITHMS
54//
55//=================================================================================================
56
57//*************************************************************************************************
70template< typename InputIt
71 , typename ForwardIt >
72ForwardIt uninitialized_move( InputIt first, InputIt last, ForwardIt dest )
73{
74 using T = typename std::iterator_traits<ForwardIt>::value_type;
75
76 ForwardIt current( dest );
77
78 try {
79 for( ; first!=last; ++first, ++current ) {
80 ::new ( std::addressof( *current ) ) T( std::move( *first ) );
81 }
82 return current;
83 }
84 catch( ... ) {
85 blaze::destroy( dest, current );
86 throw;
87 }
88}
89//*************************************************************************************************
90
91
92//*************************************************************************************************
105template< typename InputIt
106 , typename ForwardIt >
107ForwardIt uninitialized_move_n( InputIt first, size_t n, ForwardIt dest )
108{
109 using T = typename std::iterator_traits<ForwardIt>::value_type;
110
111 ForwardIt current( dest );
112
113 try {
114 for( ; n > 0UL; (void) ++first, (void) ++current, --n ) {
115 ::new ( std::addressof( *current ) ) T( std::move( *first ) );
116 }
117 return current;
118 }
119 catch( ... ) {
120 blaze::destroy( dest, current );
121 throw;
122 }
123}
124//*************************************************************************************************
125
126} // namespace blaze
127
128#endif
Header file for the generic destroy algorithm.
void destroy(ForwardIt first, ForwardIt last)
Destroys the given range of objects .
Definition: Destroy.h:67
ForwardIt uninitialized_move(InputIt first, InputIt last, ForwardIt dest)
Move the elements from the given source range to the uninitialized destination range.
Definition: UninitializedMove.h:72
ForwardIt uninitialized_move_n(InputIt first, size_t n, ForwardIt dest)
Move the elements from the given source range to the uninitialized destination range.
Definition: UninitializedMove.h:107
Header file for basic type definitions.