1#ifndef CASACORE_STORAGE_2_H
2#define CASACORE_STORAGE_2_H
36 template <
typename InputIterator>
37 Storage(InputIterator startIter, InputIterator endIter)
41 std::is_base_of<
std::string, T>>>()) {}
45 static std::unique_ptr<Storage<T>>
MakeFromMove(T* startIter, T* endIter) {
46 return std::unique_ptr<Storage<T>>(
47 new Storage(startIter, endIter, std::false_type(), std::true_type()));
53 std::unique_ptr<Storage<T>> newStorage = std::unique_ptr<Storage>(
new Storage<T>());
54 newStorage->_data = existingData;
55 newStorage->_end = existingData + n;
56 newStorage->_isShared =
true;
64 static_assert(std::is_trivial<T>::value,
"Only trivial types can be constructed uninitialized");
65 std::unique_ptr<Storage<T>> newStorage = std::unique_ptr<Storage>(
new Storage<T>());
67 newStorage->_data =
nullptr;
69 newStorage->_data = std::allocator<T>().allocate(n);
70 newStorage->_end = newStorage->_data + n;
77 for (
size_t i = 0; i !=
size(); ++i)
_data[
size() - i - 1].~T();
78 std::allocator<T>().deallocate(
_data,
size());
102 Storage(T* startIter, T* endIter, std::false_type , std::true_type )
108 template <
typename InputIterator>
109 Storage(InputIterator startIter, InputIterator endIter, std::false_type )
115 template <
typename Integral>
116 Storage(Integral n, Integral val, std::true_type )
128 T*
data = std::allocator<T>().allocate(n);
131 for (; current !=
data + n; ++current) {
135 while (current !=
data) {
139 std::allocator<T>().deallocate(
data, n);
150 T*
data = std::allocator<T>().allocate(n);
153 for (; current !=
data + n; ++current) {
154 new (current) T(val);
157 while (current !=
data) {
161 std::allocator<T>().deallocate(
data, n);
168 template <
typename InputIterator>
170 if (startIter == endIter)
173 size_t n = std::distance(startIter, endIter);
174 T*
data = std::allocator<T>().allocate(n);
177 for (; current !=
data + n; ++current) {
178 new (current) T(*startIter);
182 while (current !=
data) {
186 std::allocator<T>().deallocate(
data, n);
194 if (startIter == endIter)
197 size_t n = endIter - startIter;
198 T*
data = std::allocator<T>().allocate(n);
201 for (; current !=
data + n; ++current) {
202 new (current) T(std::move(*startIter));
206 while (current !=
data) {
210 std::allocator<T>().deallocate(
data, n);
225 template <
class B1,
class... Bn>
226 struct disjunction<B1, Bn...> : std::conditional<bool(B1::value), B1, disjunction<Bn...>>
::type {
233 template <
class B1,
class... Bn>
234 struct conjunction<B1, Bn...> : std::conditional<bool(B1::value), conjunction<Bn...>, B1>
::type {
static std::unique_ptr< Storage< T > > MakeFromSharedData(T *existingData, size_t n)
Construct a Storage from existing data.
Storage & operator=(Storage &&)=delete
Storage(Integral n, Integral val, std::true_type)
Copying range constructor implementation for integral types.
bool is_shared() const
Whether this Storage owns its data.
T * data()
Return a pointer to the storage data.
T * construct(size_t n, const T &val)
static std::unique_ptr< Storage< T > > MakeUninitialized(size_t n)
Construct a Storage with uninitialized data.
Storage(Storage< T > &&)=delete
~Storage() noexcept
Destructs the elements and deallocates the data.
T * construct_range(InputIterator startIter, InputIterator endIter)
Storage(InputIterator startIter, InputIterator endIter)
Construct Storage from a range.
static std::unique_ptr< Storage< T > > MakeFromMove(T *startIter, T *endIter)
Construct Storage from a range by moving.
Storage(std::size_t n, const T &val)
Construct Storage with a given size.
Storage()
Construct an empty Storage.
Storage(std::size_t n)
Construct Storage with a given size.
T * construct(size_t n)
These methods allocate the storage and construct the elements.
Storage(T *startIter, T *endIter, std::false_type, std::true_type)
Moving range constructor implementation.
Storage(const Storage< T > &)=delete
T * construct_move(T *startIter, T *endIter)
Storage & operator=(const Storage &)=delete
Storage(InputIterator startIter, InputIterator endIter, std::false_type)
Copying range constructor implementation for non-integral types.
size_t size() const
Size of the data, zero if empty.
For temporary backward namespace compatibility, use casa as alias for casacore.
Define real & complex conjugation for non-complex types and put comparisons into std namespace.
Used by template code above These are already in C++17, but currently only using C++11....