1#ifndef CASACORE_STORAGE_2_H
2#define CASACORE_STORAGE_2_H
9namespace arrays_internal {
48 template<
typename InputIterator>
49 Storage(InputIterator startIter, InputIterator endIter) :
52 std::is_integral<InputIterator>,
54 std::is_same<InputIterator, const char*>,
55 std::is_base_of<
std::string, T>
62 static std::unique_ptr<Storage<T>>
MakeFromMove(T* startIter, T* endIter)
64 return std::unique_ptr<Storage<T>>(
new Storage(startIter, endIter, std::false_type(), std::true_type()));
71 std::unique_ptr<Storage<T>> newStorage = std::unique_ptr<Storage>(
new Storage<T>());
72 newStorage->_data = existingData;
73 newStorage->_end = existingData + n;
74 newStorage->_isShared =
true;
83 static_assert(std::is_trivial<T>::value,
"Only trivial types can be constructed uninitialized");
84 std::unique_ptr<Storage<T>> newStorage = std::unique_ptr<Storage>(
new Storage<T>());
86 newStorage->_data =
nullptr;
88 newStorage->_data = std::allocator<T>().allocate(n);
89 newStorage->_end = newStorage->_data + n;
98 for(
size_t i=0; i!=
size(); ++i)
100 std::allocator<T>().deallocate(
_data,
size());
124 Storage(T* startIter, T* endIter, std::false_type , std::true_type ) :
131 template<
typename InputIterator>
132 Storage(InputIterator startIter, InputIterator endIter, std::false_type ) :
139 template<
typename Integral>
140 Storage(Integral n, Integral val, std::true_type ) :
156 T*
data = std::allocator<T>().allocate(n);
159 for (; current !=
data+n; ++current) {
163 while(current !=
data)
168 std::allocator<T>().deallocate(
data, n);
180 T*
data = std::allocator<T>().allocate(n);
183 for (; current !=
data+n; ++current) {
184 new (current) T(val);
187 while(current !=
data)
192 std::allocator<T>().deallocate(
data, n);
199 template<
typename InputIterator>
202 if(startIter == endIter)
205 size_t n = std::distance(startIter, endIter);
206 T*
data = std::allocator<T>().allocate(n);
209 for (; current !=
data+n; ++current) {
210 new (current) T(*startIter);
214 while(current !=
data)
219 std::allocator<T>().deallocate(
data, n);
228 if(startIter == endIter)
231 size_t n = endIter - startIter;
232 T*
data = std::allocator<T>().allocate(n);
235 for (; current !=
data+n; ++current) {
236 new (current) T(std::move(*startIter));
240 while(current !=
data)
245 std::allocator<T>().deallocate(
data, n);
258 template<
class B1,
class... Bn>
260 : std::conditional<bool(B1::value), B1, disjunction<Bn...>>::type { };
264 template<
class B1,
class... Bn>
266 : std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
This class emplements a static (but run-time) sized array.
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.
this file contains all the compiler specific defines
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....