Blaze 3.9
UninitializedDefaultConstruct.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_UTIL_ALGORITHMS_UNINITIALIZEDDEFAULTCONSTRUCT_H_
36#define _BLAZE_UTIL_ALGORITHMS_UNINITIALIZEDDEFAULTCONSTRUCT_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_DEFAULT_CONSTRUCT ALGORITHMS
54//
55//=================================================================================================
56
57//*************************************************************************************************
68template< typename ForwardIt >
69void uninitialized_default_construct( ForwardIt first, ForwardIt last )
70{
71 using T = typename std::iterator_traits<ForwardIt>::value_type;
72
73 ForwardIt current( first );
74
75 try {
76 for( ; current!=last; ++current ) {
77 ::new ( std::addressof( *current ) ) T;
78 }
79 }
80 catch( ... ) {
81 blaze::destroy( first, current );
82 throw;
83 }
84}
85//*************************************************************************************************
86
87
88//*************************************************************************************************
99template< typename ForwardIt >
100void uninitialized_default_construct_n( ForwardIt first, size_t n )
101{
102 using T = typename std::iterator_traits<ForwardIt>::value_type;
103
104 ForwardIt current( first );
105
106 try {
107 for( ; n > 0UL; (void) ++current, --n ) {
108 ::new ( std::addressof( *current ) ) T;
109 }
110 }
111 catch( ... ) {
112 blaze::destroy( first, current );
113 throw;
114 }
115}
116//*************************************************************************************************
117
118} // namespace blaze
119
120#endif
Header file for the generic destroy algorithm.
void uninitialized_default_construct_n(ForwardIt first, size_t n)
Default constructs elements in the given range.
Definition: UninitializedDefaultConstruct.h:100
void destroy(ForwardIt first, ForwardIt last)
Destroys the given range of objects .
Definition: Destroy.h:67
void uninitialized_default_construct(ForwardIt first, ForwardIt last)
Default constructs elements in the given range.
Definition: UninitializedDefaultConstruct.h:69
Header file for basic type definitions.