UninitializedValueConstruct.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_ALGORITHMS_UNINITIALIZEDVALUECONSTRUCT_H_
36 #define _BLAZE_UTIL_ALGORITHMS_UNINITIALIZEDVALUECONSTRUCT_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
44 #include <memory>
45 
46 
47 namespace blaze {
48 
49 //=================================================================================================
50 //
51 // UNINITIALIZED_VALUE_CONSTRUCT ALGORITHM
52 //
53 //=================================================================================================
54 
55 //*************************************************************************************************
66 template< class ForwardIt >
67 void uninitialized_value_construct( ForwardIt first, ForwardIt last )
68 {
69  using Value = typename std::iterator_traits<ForwardIt>::value_type;
70 
71  ForwardIt current( first );
72 
73  try {
74  for( ; current!=last; ++current ) {
75  ::new ( std::addressof( *current ) ) Value();
76  }
77  }
78  catch (...) {
79  for( ; first!=current; ++first ) {
80  first->~Value();
81  }
82  throw;
83  }
84 }
85 //*************************************************************************************************
86 
87 } // namespace blaze
88 
89 #endif
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
void uninitialized_value_construct(ForwardIt first, ForwardIt last)
Value constructs elements in the given range.
Definition: UninitializedValueConstruct.h:67