72 template<
typename Tp,
typename Alloc = std::allocator<Tp> >
75 static_assert(std::is_standard_layout<Tp>(),
"A uvector can only hold classes with standard layout");
77 #if __cplusplus > 201402L
147 std::uninitialized_fill_n<Tp*,size_t>(
_begin, n, val);
155 template<
class InputIterator>
159 construct_from_range<InputIterator>(
first, last, std::is_integral<InputIterator>());
168 Alloc(std::allocator_traits<Alloc>::select_on_container_copy_construction(static_cast<
allocator_type>(other))),
193 Alloc(std::move(other)),
198 other._begin =
nullptr;
199 other._end =
nullptr;
200 other._endOfStorage =
nullptr;
213 other._begin =
nullptr;
214 other._end =
nullptr;
215 other._endOfStorage =
nullptr;
229 for(
typename std::initializer_list<Tp>::const_iterator i=initlist.begin(); i!=initlist.end(); ++i)
248 return assign_copy_from(other,
typename std::allocator_traits<Alloc>::propagate_on_container_copy_assignment());
256 std::allocator_traits<Alloc>::propagate_on_container_move_assignment::
value||
259 return assign_move_from(std::move(other),
typename std::allocator_traits<Alloc>::propagate_on_container_move_assignment());
302 size_t max_size() const noexcept {
return Alloc::max_size(); }
338 size_t oldSize =
size();
349 std::uninitialized_fill<Tp*,size_t>(
_begin + oldSize,
_end, val);
372 const size_t curSize =
size();
377 _end = newStorage + curSize;
390 const size_t curSize =
size();
403 _end = newStorage + curSize;
426 const Tp&
at(
size_t index)
const
442 const Tp&
back() const noexcept {
return *(
_end - 1); }
456 template<
class InputIterator>
457 void assign(InputIterator first, InputIterator last)
459 assign_from_range<InputIterator>(
first, last, std::is_integral<InputIterator>());
477 std::uninitialized_fill_n<Tp*,size_t>(
_begin, n, val);
485 void assign(std::initializer_list<Tp> initlist)
496 for(
typename std::initializer_list<Tp>::const_iterator i=initlist.begin(); i!=initlist.end(); ++i)
526 *
_end = std::move(item);
548 size_t index = position -
_begin;
550 position = _begin + index;
553 std::move_backward(const_cast<iterator>(position),
_end,
_end+1);
556 *
const_cast<iterator>(position) = item;
557 return const_cast<iterator>(position);
573 size_t index = position -
_begin;
575 position = _begin + index;
578 std::move_backward(const_cast<iterator>(position),
_end,
_end+n);
581 std::uninitialized_fill_n<Tp*,size_t>(
const_cast<iterator>(position), n, val);
582 return const_cast<iterator>(position);
594 template <
class InputIterator>
597 return insert_from_range<InputIterator>(position,
first, last, std::is_integral<InputIterator>());
616 size_t index = position -
_begin;
618 position = _begin + index;
621 std::move_backward(const_cast<iterator>(position),
_end,
_end+1);
624 *
const_cast<iterator>(position) = std::move(item);
625 return const_cast<iterator>(position);
640 size_t index = position -
_begin;
642 position = _begin + index;
645 std::move_backward(const_cast<iterator>(position),
_end,
_end+initlist.size());
646 _end += initlist.size();
649 for(
typename std::initializer_list<Tp>::const_iterator i=initlist.begin(); i!=initlist.end(); ++i)
654 return const_cast<iterator>(position);
665 std::move(const_cast<iterator>(position)+1,
_end, const_cast<iterator>(position));
667 return const_cast<iterator>(position);
679 std::move(const_cast<iterator>(last),
_end, const_cast<iterator>(first));
697 swap(other,
typename std::allocator_traits<Alloc>::propagate_on_container_swap());
714 template<
typename... Args>
719 size_t index = position -
_begin;
721 position = _begin + index;
724 std::move_backward(const_cast<iterator>(position),
_end,
_end+1);
727 *
const_cast<iterator>(position) = Tp(std::forward<Args>(args)...);
728 return const_cast<iterator>(position);
735 template<
typename... Args>
740 *
_end = Tp(std::forward<Args>(args)...);
766 size_t index = position -
_begin;
768 position = _begin + index;
771 std::move_backward(const_cast<iterator>(position),
_end,
_end+n);
774 return const_cast<iterator>(position);
784 template <
class InputIterator>
787 push_back_range<InputIterator>(
first, last, std::is_integral<InputIterator>());
803 std::uninitialized_fill_n<Tp*,size_t>(
_end, n, val);
819 for(
typename std::initializer_list<Tp>::iterator i = initlist.begin(); i != initlist.end(); ++i)
841 return Alloc::allocate(n);
852 Alloc::deallocate(
begin, n);
855 template<
typename InputIterator>
858 construct_from_range<InputIterator>(
first, last,
typename std::iterator_traits<InputIterator>::iterator_category());
861 template<
typename Integral>
867 std::uninitialized_fill_n<Tp*,size_t>(
_begin, n, val);
870 template<
typename InputIterator>
873 size_t n = std::distance(first, last);
885 template<
typename InputIterator>
888 assign_from_range<InputIterator>(
first, last,
typename std::iterator_traits<InputIterator>::iterator_category());
893 template<
typename Integral>
904 std::uninitialized_fill_n<Tp*,size_t>(
_begin, n, val);
907 template<
typename InputIterator>
910 size_t n = std::distance(first, last);
927 template<
typename InputIterator>
930 return insert_from_range<InputIterator>(position,
first, last,
931 typename std::iterator_traits<InputIterator>::iterator_category());
934 template<
typename Integral>
939 size_t index = position -
_begin;
941 position = _begin + index;
944 std::move_backward(const_cast<iterator>(position),
_end,
_end+n);
947 std::uninitialized_fill_n<Tp*,size_t>(
const_cast<iterator>(position), n, val);
948 return const_cast<iterator>(position);
951 template<
typename InputIterator>
954 size_t n = std::distance(first, last);
957 size_t index = position -
_begin;
959 position = _begin + index;
962 std::move_backward(const_cast<iterator>(position),
_end,
_end+n);
965 Tp* destIter =
const_cast<iterator>(position);
971 return const_cast<iterator>(position);
977 throw std::out_of_range(
"Access to element in uvector past end");
1001 _end = newStorage +
size() + insert_count;
1009 const size_t n = other.
size();
1029 const size_t n = other.
size();
1050 other._begin =
nullptr;
1051 other._end =
nullptr;
1052 other._endOfStorage =
nullptr;
1072 other._begin =
nullptr;
1073 other._end =
nullptr;
1074 other._endOfStorage =
nullptr;
1084 std::swap(static_cast<Alloc&>(other), static_cast<Alloc&>(*
this));
1116 template<
typename InputIterator>
1119 push_back_range<InputIterator>(
first, last,
typename std::iterator_traits<InputIterator>::iterator_category());
1124 template<
typename Integral>
1131 std::uninitialized_fill_n<Tp*,size_t>(
_end, n, val);
1135 template<
typename InputIterator>
1138 size_t n = std::distance(first, last);
1143 while(first != last)
1154 template<
class Tp,
class Alloc>
1157 return lhs.size()==rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin());
1161 template<
class Tp,
class Alloc>
1164 return !(lhs == rhs);
1171 template <
class Tp,
class Alloc>
1174 const size_t minSize =
std::min(lhs.size(), rhs.size());
1175 for(
size_t i=0; i!=minSize; ++i)
1179 else if(lhs[i] > rhs[i])
1182 return lhs.size() < rhs.size();
1189 template <
class Tp,
class Alloc>
1192 const size_t minSize =
std::min(lhs.size(), rhs.size());
1193 for(
size_t i=0; i!=minSize; ++i)
1197 else if(lhs[i] > rhs[i])
1200 return lhs.size() <= rhs.size();
1207 template <
class Tp,
class Alloc>
1217 template <
class Tp,
class Alloc>
1233 template <
class Tp,
class Alloc>
1243 #endif // AO_UVECTOR_H
Tp * pointer
Pointer to element type.
iterator erase(const_iterator position)
Delete an element from the container.
reverse_iterator rend() noexcept
Get reverse iterator to element before first element.
A container similar to std::vector, but one that allows construction without initializing its element...
void assign(InputIterator first, InputIterator last)
Assign this container to be equal to the given range.
size_t max_size() const noexcept
Get maximum number of elements that this container can hold.
bool empty() const noexcept
Determine if the container is currently empty.
std::size_t size_type
Type used for indexing elements.
const Tp & back() const noexcept
Get constant reference to last element in container.
StatsData< AccumType > copy(const StatsData< AccumType > &stats)
uvector(InputIterator first, InputIterator last, const allocator_type &allocator=Alloc())
Construct a vector by copying elements from a range.
bool operator>=(const uvector< Tp, Alloc > &lhs, const uvector< Tp, Alloc > &rhs) noexcept
Compare two uvectors for larger than or equal.
iterator insert_from_range(const_iterator position, InputIterator first, InputIterator last, std::false_type)
void swap(uvector< Tp, Alloc > &other) noexcept
Swap the contents of this uvector with the given uvector.
allocator_type get_allocator() const noexcept
Get a copy of the allocator.
Tp & front() noexcept
Get reference to first element in container.
const Tp * const_pointer
Pointer to constant element type.
uvector & operator=(uvector< Tp, Alloc > &&other) noexcept(std::allocator_traits< Alloc >::propagate_on_container_move_assignment::value||allocator_is_always_equal::value)
Assign another uvector to this uvector.
bool operator==(const uvector< Tp, Alloc > &lhs, const uvector< Tp, Alloc > &rhs) noexcept
Compare two uvectors for equality.
void push_back(InputIterator first, InputIterator last)
Add a range of items to the end of the container.
std::ptrdiff_t difference_type
Difference between to iterators.
iterator erase(const_iterator first, const_iterator last)
Delete a range of elements from the container.
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
void assign(std::initializer_list< Tp > initlist)
Assign this container to an initializer list.
void resize(size_t n)
Change the number of elements in the container.
uvector(size_t n)
Construct a vector with given amount of elements, without initializing these.
iterator begin() noexcept
Get iterator to first element.
const Tp * const_iterator
Iterator type of constant elements.
void push_back_range(InputIterator first, InputIterator last, std::false_type)
iterator insert_uninitialized(const_iterator position, size_t n)
— NON STANDARD METHODS —
PtrHolder< T > & operator=(const PtrHolder< T > &other)
size_t enlarge_size(size_t extra_space_needed) const noexcept
const Tp & const_reference
Constant reference to element type.
std::false_type allocator_is_always_equal
Tp * iterator
Iterator type.
reverse_iterator rbegin() noexcept
Get reverse iterator to last element.
void push_back(const Tp &item)
Add the given value to the end of the container.
const Tp & at(size_t index) const
Get a constant reference to the element at the given index with bounds checking.
void pop_back()
Remove the last element from the container.
uvector & operator=(const uvector< Tp, Alloc > &other)
Assign another uvector to this uvector.
const Tp & operator[](size_t index) const noexcept
Get a constant reference to the element at the given index.
uvector(uvector< Tp, Alloc > &&other, const allocator_type &allocator) noexcept
Move construct a uvector with custom allocator.
Tp & operator[](size_t index) noexcept
Get a reference to the element at the given index.
const Tp * data() const noexcept
Get constant pointer to internal storage.
void construct_from_range(Integral n, Integral val, std::true_type)
Tp * data() noexcept
Get pointer to internal storage.
void swap(uvector< Tp, Alloc > &x, uvector< Tp, Alloc > &y)
Swap the contents of the two uvectors.
void deallocate(pointer begin, size_t n) noexcept
const_iterator cbegin() const noexcept
Get constant iterator to first element.
~uvector() noexcept
Destructor.
void resize(size_t n, const Tp &val)
Change the number of elements in the container.
uvector(std::initializer_list< Tp > initlist, const allocator_type &allocator=Alloc())
Construct a uvector from a initializer list.
Tp & reference
Reference to element type.
size_t capacity() const noexcept
Get the number of elements the container can currently hold without reallocating storage.
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
uvector(const allocator_type &allocator=Alloc()) noexcept
Construct an empty uvector.
void push_back(size_t n, const Tp &val)
Add elements at the end and initialize them with a value.
iterator insert(const_iterator position, Tp &&item)
Insert an element at a given position by moving it in.
iterator insert(const_iterator position, std::initializer_list< Tp > initlist)
Insert elements at a given position and initialize them from a initializer list.
void deallocate() noexcept
iterator insert(const_iterator position, InputIterator first, InputIterator last)
Insert elements at a given position and initialize them from a range.
const Tp & front() const noexcept
Get constant reference to first element in container.
void assign(size_t n, const Tp &val)
Resize the container and assign the given value to all elements.
void clear()
Remove all elements from the container.
iterator end() noexcept
Get iterator to element past last element.
iterator insert(const_iterator position, size_t n, const Tp &val)
Insert elements at a given position and initialize them with a value.
std::size_t size_t
Type used for indexing elements.
void emplace_back(Args &&...args)
Add the given value to the end of the container by constructing it in place.
Alloc allocator_type
Type of allocator used to allocate and deallocate space.
void swap(uvector< Tp, Alloc > &other, std::false_type) noexcept
implementation of swap without propagate_on_container_swap
void reserve(size_t n)
Reserve space for a number of elements, to prevent the overhead of extra reallocations.
iterator insert(const_iterator position, const Tp &item)
Insert an element at a given position.
const_iterator cend() const noexcept
Get constant iterator to element past last element.
void construct_from_range(InputIterator first, InputIterator last, std::forward_iterator_tag)
uvector(const uvector< Tp, Alloc > &other)
Copy construct a uvector.
uvector & assign_move_from(uvector< Tp, Alloc > &&other, std::true_type) noexcept
implementation of operator=() with propagate_on_container_move_assignment
Tp & back() noexcept
Get reference to last element in container.
uvector(size_t n, const value_type &val, const allocator_type &allocator=Alloc())
Construct a vector with given amount of elements and set these to a specific value.
iterator insert_from_range(const_iterator position, InputIterator first, InputIterator last, std::forward_iterator_tag)
void swap(Array< T, Alloc > &first, Array< T, Alloc > &second)
Swap the first array with the second.
bool operator>(const uvector< Tp, Alloc > &lhs, const uvector< Tp, Alloc > &rhs) noexcept
Compare two uvectors for larger than.
void swap(uvector< Tp, Alloc > &other, std::true_type) noexcept
implementation of swap with propagate_on_container_swap
uvector(uvector< Tp, Alloc > &&other) noexcept
Move construct a uvector.
void push_back_range(Integral n, Integral val, std::true_type)
This function is called from push_back(iter,iter) when Tp is an integral.
const_iterator end() const noexcept
Get constant iterator to element past last element.
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator type.
uvector & assign_copy_from(const uvector< Tp, Alloc > &other, std::false_type)
implementation of operator=(const&) without propagate_on_container_copy_assignment ...
pointer allocate(size_t n)
void construct_from_range(InputIterator first, InputIterator last, std::false_type)
void push_back(std::initializer_list< Tp > initlist)
Add elements from an initializer list to the end of the container.
const_iterator begin() const noexcept
Get constant iterator to first element.
void push_back_range(InputIterator first, InputIterator last, std::forward_iterator_tag)
void enlarge(size_t newSize)
bool operator!=(const uvector< Tp, Alloc > &lhs, const uvector< Tp, Alloc > &rhs) noexcept
Compare two uvectors for inequality.
void shrink_to_fit()
Change the capacity of the container such that no extra space is hold.
void assign_from_range(Integral n, Integral val, std::true_type)
This function is called from assign(iter,iter) when Tp is an integral.
void enlarge_for_insert(size_t newSize, size_t insert_position, size_t insert_count)
uvector & assign_move_from(uvector< Tp, Alloc > &&other, std::false_type) noexcept(allocator_is_always_equal::value)
implementation of operator=() without propagate_on_container_move_assignment
void push_back_uninitialized(size_t n)
Add elements at the end without initializing them.
const_reverse_iterator rbegin() const noexcept
Get constant reverse iterator to last element.
Tp & at(size_t index)
Get a reference to the element at the given index with bounds checking.
void push_back(Tp &&item)
Add the given value to the end of the container by moving it in.
const_reverse_iterator crbegin() const noexcept
Get constant reverse iterator to last element.
const_reverse_iterator crend() const noexcept
Get constant reverse iterator to element before first element.
const_reverse_iterator rend() const noexcept
Get constant reverse iterator to element before first element.
void assign_from_range(InputIterator first, InputIterator last, std::false_type)
void assign_from_range(InputIterator first, InputIterator last, std::forward_iterator_tag)
uvector(const uvector< Tp, Alloc > &other, const allocator_type &allocator)
Copy construct a uvector with custom allocator.
Tp value_type
Element type.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
void check_bounds(size_t index) const
uvector & assign_copy_from(const uvector< Tp, Alloc > &other, std::true_type)
implementation of operator=(const&) with propagate_on_container_copy_assignment
std::reverse_iterator< const_iterator > const_reverse_iterator
Reverse iterator of constant elements.
size_t size() const noexcept
Get number of elements in container.
iterator emplace(const_iterator position, Args &&...args)
Insert an element at a given position by constructing it in place.
iterator insert_from_range(const_iterator position, Integral n, Integral val, std::true_type)