1 #ifndef CASACORE_STORAGE_2_H
2 #define CASACORE_STORAGE_2_H
9 namespace arrays_internal {
15 template<
typename T,
typename Alloc>
29 Storage(std::size_t n,
const Alloc& allocator) :
38 Storage(std::size_t n,
const T& val,
const Alloc& allocator) :
51 template<
typename InputIterator>
52 Storage(InputIterator startIter, InputIterator endIter,
const Alloc& allocator) :
53 Storage(startIter, endIter, allocator,
55 std::is_integral<InputIterator>,
57 std::is_same<InputIterator, const char*>,
58 std::is_base_of<
std::string, T>
65 static std::unique_ptr<Storage<T, Alloc>>
MakeFromMove(T* startIter, T* endIter,
const Alloc& allocator)
67 return std::unique_ptr<Storage<T, Alloc>>(
new Storage(startIter, endIter, allocator, std::false_type(), std::true_type()));
72 static std::unique_ptr<Storage<T, Alloc>>
MakeFromSharedData(T* existingData,
size_t n,
const Alloc& allocator)
74 std::unique_ptr<Storage<T, Alloc>> newStorage = std::unique_ptr<Storage>(
new Storage<T, Alloc>(allocator));
75 newStorage->_data = existingData;
76 newStorage->_end = existingData + n;
77 newStorage->_isShared =
true;
84 static std::unique_ptr<Storage<T, Alloc>>
MakeUninitialized(
size_t n,
const Alloc& allocator)
87 std::unique_ptr<Storage<T, Alloc>> newStorage = std::unique_ptr<Storage>(
new Storage<T, Alloc>(allocator));
89 newStorage->_data =
nullptr;
91 newStorage->_data =
static_cast<Alloc&
>(*newStorage).allocate(n);
92 newStorage->_end = newStorage->_data + n;
101 for(
size_t i=0; i!=
size(); ++i)
117 const Alloc&
get_allocator()
const {
return static_cast<const Alloc&
>(*this); }
130 Storage(T* startIter, T* endIter,
const Alloc& allocator, std::false_type , std::true_type ) :
138 template<
typename InputIterator>
139 Storage(InputIterator startIter, InputIterator endIter,
const Alloc& allocator, std::false_type ) :
147 template<
typename Integral>
148 Storage(Integral n, Integral val,
const Alloc& allocator, std::true_type ) :
165 T*
data = Alloc::allocate(n);
168 for (; current !=
data+n; ++current) {
172 while(current !=
data)
177 Alloc::deallocate(
data, n);
189 T*
data = Alloc::allocate(n);
192 for (; current !=
data+n; ++current) {
193 new (current) T(val);
196 while(current !=
data)
201 Alloc::deallocate(
data, n);
208 template<
typename InputIterator>
211 if(startIter == endIter)
214 size_t n = std::distance(startIter, endIter);
215 T*
data = Alloc::allocate(n);
218 for (; current !=
data+n; ++current) {
219 new (current) T(*startIter);
223 while(current !=
data)
228 Alloc::deallocate(
data, n);
237 if(startIter == endIter)
240 size_t n = endIter - startIter;
241 T*
data = Alloc::allocate(n);
244 for (; current !=
data+n; ++current) {
245 new (current) T(std::move(*startIter));
249 while(current !=
data)
254 Alloc::deallocate(
data, n);
267 template<
class B1,
class... Bn>
269 : std::conditional<bool(B1::value), B1, disjunction<Bn...>>::type { };
273 template<
class B1,
class... Bn>
275 : std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
This class emplements a static (but run-time) sized array.
Storage(const Storage< T, Alloc > &)=delete
size_t size() const
Size of the data, zero if empty.
T * construct(size_t n, const T &val)
static std::unique_ptr< Storage< T, Alloc > > MakeUninitialized(size_t n, const Alloc &allocator)
Construct a Storage with uninitialized data.
Storage(T *startIter, T *endIter, const Alloc &allocator, std::false_type, std::true_type)
Moving range constructor implementation.
Storage(InputIterator startIter, InputIterator endIter, const Alloc &allocator)
Construct Storage from a range.
~Storage() noexcept
Destructs the elements and deallocates the data.
static std::unique_ptr< Storage< T, Alloc > > MakeFromMove(T *startIter, T *endIter, const Alloc &allocator)
Construct Storage from a range by moving.
T * construct_range(InputIterator startIter, InputIterator endIter)
Storage & operator=(const Storage &)=delete
Storage(Integral n, Integral val, const Alloc &allocator, std::true_type)
Copying range constructor implementation for integral types.
Storage(const Alloc &allocator)
Construct an empty Storage.
T * construct(size_t n)
These methods allocate the storage and construct the elements.
Storage(InputIterator startIter, InputIterator endIter, const Alloc &allocator, std::false_type)
Copying range constructor implementation for non-integral types.
Storage(std::size_t n, const T &val, const Alloc &allocator)
Construct Storage with a given size.
const Alloc & get_allocator() const
Returns the allocator associated with this Storage.
Storage(std::size_t n, const Alloc &allocator)
Construct Storage with a given size.
Storage(Storage< T, Alloc > &&)=delete
Storage & operator=(Storage &&)=delete
bool is_shared() const
Whether this Storage owns its data.
static std::unique_ptr< Storage< T, Alloc > > MakeFromSharedData(T *existingData, size_t n, const Alloc &allocator)
Construct a Storage from existing data.
T * data()
Return a pointer to the storage data.
T * construct_move(T *startIter, T *endIter)
this file contains all the compiler specific defines
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
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....