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 ) :
142 _end(
_data + std::distance(startIter, endIter)),
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 {};
Storage(std::size_t n, const Alloc &allocator)
Construct Storage with a given size.
Storage(std::size_t n, const T &val, const Alloc &allocator)
Construct Storage with a given size.
T * construct(size_t n, const T &val)
Storage & operator=(const Storage &)=delete
Storage(InputIterator startIter, InputIterator endIter, const Alloc &allocator, std::false_type)
Copying range constructor implementation for non-integral types.
T * construct_move(T *startIter, T *endIter)
~Storage() noexcept
Destructs the elements and deallocates the data.
bool is_shared() const
Whether this Storage owns its data.
Storage(InputIterator startIter, InputIterator endIter, const Alloc &allocator)
Construct Storage from a range.
Storage(const Alloc &allocator)
Construct an empty Storage.
T * construct(size_t n)
These methods allocate the storage and construct the elements.
static std::unique_ptr< Storage< T, Alloc > > MakeUninitialized(size_t n, const Alloc &allocator)
Construct a Storage with uninitialized data.
const Alloc & get_allocator() const
Returns the allocator associated with this Storage.
static std::unique_ptr< Storage< T, Alloc > > MakeFromMove(T *startIter, T *endIter, const Alloc &allocator)
Construct Storage from a range by moving.
static std::unique_ptr< Storage< T, Alloc > > MakeFromSharedData(T *existingData, size_t n, const Alloc &allocator)
Construct a Storage from existing data.
size_t size() const
Size of the data, zero if empty.
T * construct_range(InputIterator startIter, InputIterator endIter)
Storage(Integral n, Integral val, const Alloc &allocator, std::true_type)
Copying range constructor implementation for integral types.
T * data()
Return a pointer to the storage data.
Storage(T *startIter, T *endIter, const Alloc &allocator, std::false_type, std::true_type)
Moving range constructor implementation.
This class emplements a static (but run-time) sized array.
Used by template code above These are already in C++17, but currently only using C++11...
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.