-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninitialized_storage.hpp
124 lines (106 loc) · 4.98 KB
/
uninitialized_storage.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* \file uninitialized_storage.hpp
*
* \brief TODO: Add description
*
* \author Matthew Rodusek ([email protected])
*/
#ifndef BIT_STL_UTILITY_UNINITIALIZED_STORAGE_HPP
#define BIT_STL_UTILITY_UNINITIALIZED_STORAGE_HPP
#include <iterator> // std::iterator_traits
#include <new> // placement new
#include <memory> // std::addressof
#include <tuple> // std::get
#include <utility> // std::forward, std::index_sequence
namespace bit {
namespace stl {
//-------------------------------------------------------------------------
// Uninitialized Construction
//-------------------------------------------------------------------------
/// \brief Default constructs an instance of type \p T in the given memory
///
/// \param ptr The memory location to construct into
/// \return Pointer to the initialized memory (cast of \p ptr)
template<typename T>
T* uninitialized_default_construct_at( void* ptr );
/// \brief Copy constructs an instance of type \p T in the given memory
///
/// \param ptr The memory location to construct into
/// \param other The instance to copy
/// \return Pointer to the initialized memory (cast of \p ptr)
template<typename T>
T* uninitialized_copy_at( void* ptr, const T& other );
/// \brief Move constructs an instance of type \p T in the given memory
///
/// \param ptr The memory location to construct into
/// \param other The instance to move
/// \return Pointer to the initialized memory (cast of \p ptr)
template<typename T>
T* uninitialized_move_at( void* ptr, T&& other );
/// \brief Constructs an instance of type \p T with the given \p args
/// at the memory location specified in \p ptr
///
/// \param ptr The memory location to construct into
/// \param args... The arguments to supply to T's constructor
/// \return Pointer to the initialized memory (cast of \p ptr)
template<typename T, typename...Args>
T* uninitialized_construct_at( void* ptr, Args&&...args );
/// \brief Constructs an instance of type \p T with the given \p tuple
/// at the memory location specified in \p ptr.
///
/// This forwards the arguments from the \p tuple to the constructor
/// of T, as if by calling make_from_tuple
///
/// \param ptr The memory location to construct into
/// \param tuple The tuple containing arguments to forward to T
/// \return Pointer ot the initialzied memory (cast of \p ptr)
template<typename T, typename Tuple>
T* uninitialized_tuple_construct_at( void* ptr, Tuple&& tuple );
/// \brief Constructs an instance of type \p T with the given \p args
/// at the memory addresses in the given range [\p first, \p last )
///
/// \param first the start of the range of the elements to copy
/// \param last the end of the range of the elements to copy
/// \param args... The arguments to supply to the
template<typename ForwardIterator, typename...Args>
void uninitialized_construct( ForwardIterator first, ForwardIterator last, Args&&...args );
/// \brief Constructs an instance of type \p T with the given \p args
/// at the memory addresses in the given range [\p first, \p first + \p n )
///
/// \param first the start of the range of the elements to copy
/// \param n the number of entries to construct
/// \param args... The arguments to supply to the
template<typename ForwardIterator, typename Size, typename...Args>
ForwardIterator uninitialized_construct_n( ForwardIterator first, Size n, Args&&...args );
//-------------------------------------------------------------------------
// Destruction
//-------------------------------------------------------------------------
/// \brief Calls the destructor of the object pointed to by p, as if by p->~T().
///
/// \param p a pointer to the object to be destroyed
template<typename T>
void destroy_at( T* p );
/// \brief Destroys the objects in the range \c [first, \c last)
///
/// \param first the start of the range to destroy
/// \param end the end of the range to destroy
template<typename ForwardIterator>
void destroy( ForwardIterator first, ForwardIterator last );
/// \brief Destroys the \p n objects in the range starting at \p first
///
/// \param first the start of the range to destroy
/// \param n the number of entries to destroy
template<typename ForwardIterator>
ForwardIterator destroy_n( ForwardIterator first, std::size_t n );
/// \brief Destroys an array of entries at the given \p ptr
///
/// \note The pointer to the destroyed array must have been created with
/// A call to uninitialized_create_array_at
///
/// \param ptr A pointer to an
template<typename T>
void destroy_array_at( T* ptr );
} // namespace stl
} // namespace bit
#include "detail/uninitialized_storage.inl"
#endif /* BIT_STL_UTILITY_UNINITIALIZED_STORAGE_HPP */