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());
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>
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;
556 *
const_cast<iterator>(position) = item;
557 return const_cast<iterator>(position);
573 size_t index = position -
_begin;
575 position =
_begin + index;
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;
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);
667 return const_cast<iterator>(position);
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;
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;
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;
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;
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>
A container similar to std::vector, but one that allows construction without initializing its element...
const Tp * const_iterator
Iterator type of constant elements.
void assign_from_range(InputIterator first, InputIterator last, std::forward_iterator_tag)
uvector & assign_copy_from(const uvector< Tp, Alloc > &other, std::true_type)
implementation of operator=(const&) with propagate_on_container_copy_assignment
iterator insert_uninitialized(const_iterator position, size_t n)
— NON STANDARD METHODS —
~uvector() noexcept
Destructor.
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 deallocate() noexcept
void shrink_to_fit()
Change the capacity of the container such that no extra space is hold.
uvector(const allocator_type &allocator=Alloc()) noexcept
Construct an empty uvector.
uvector & operator=(const uvector< Tp, Alloc > &other)
Assign another uvector to this uvector.
void push_back_uninitialized(size_t n)
Add elements at the end without initializing them.
void push_back(std::initializer_list< Tp > initlist)
Add elements from an initializer list to the end of the container.
void push_back_range(InputIterator first, InputIterator last, std::false_type)
const_reverse_iterator crend() const noexcept
Get constant reverse iterator to element before first element.
Tp * data() noexcept
Get pointer to internal storage.
const Tp & const_reference
Constant reference to element type.
void deallocate(pointer begin, size_t n) noexcept
const_reverse_iterator rbegin() const noexcept
Get constant reverse iterator to last element.
const Tp & operator[](size_t index) const noexcept
Get a constant reference to the element at the given index.
uvector(const uvector< Tp, Alloc > &other, const allocator_type &allocator)
Copy construct a uvector with custom allocator.
uvector(uvector< Tp, Alloc > &&other) noexcept
Move construct a uvector.
Tp & back() noexcept
Get reference to last element in container.
size_t capacity() const noexcept
Get the number of elements the container can currently hold without reallocating storage.
size_t size() const noexcept
Get number of elements in container.
void push_back_range(InputIterator first, InputIterator last, std::forward_iterator_tag)
void construct_from_range(InputIterator first, InputIterator last, std::false_type)
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator type.
void resize(size_t n)
Change the number of elements in the container.
iterator insert_from_range(const_iterator position, InputIterator first, InputIterator last, std::forward_iterator_tag)
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 swap(uvector< Tp, Alloc > &other, std::false_type) noexcept
implementation of swap without propagate_on_container_swap
const_iterator cbegin() const noexcept
Get constant iterator to first element.
Tp * pointer
Pointer to element type.
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.
reverse_iterator rend() noexcept
Get reverse iterator to element before first element.
void push_back(size_t n, const Tp &val)
Add elements at the end and initialize them with a value.
Tp * iterator
Iterator type.
void reserve(size_t n)
Reserve space for a number of elements, to prevent the overhead of extra reallocations.
const_reverse_iterator rend() const noexcept
Get constant reverse iterator to element before first element.
uvector & assign_move_from(uvector< Tp, Alloc > &&other, std::true_type) noexcept
implementation of operator=() with propagate_on_container_move_assignment
void assign(std::initializer_list< Tp > initlist)
Assign this container to an initializer list.
Tp & reference
Reference to element type.
const Tp * const_pointer
Pointer to constant element type.
Alloc allocator_type
Type of allocator used to allocate and deallocate space.
void enlarge(size_t newSize)
void assign(size_t n, const Tp &val)
Resize the container and assign the given value to all elements.
const Tp & at(size_t index) const
Get a constant reference to the element at the given index with bounds checking.
Tp value_type
Element type.
iterator begin() noexcept
Get iterator to first element.
const Tp & back() const noexcept
Get constant reference to last element in container.
const_iterator begin() const noexcept
Get constant iterator to first element.
uvector(InputIterator first, InputIterator last, const allocator_type &allocator=Alloc())
Construct a vector by copying elements from a range.
iterator insert(const_iterator position, InputIterator first, InputIterator last)
Insert elements at a given position and initialize them from a range.
void clear()
Remove all elements from the container.
uvector & assign_copy_from(const uvector< Tp, Alloc > &other, std::false_type)
implementation of operator=(const&) without propagate_on_container_copy_assignment
bool empty() const noexcept
Determine if the container is currently empty.
iterator erase(const_iterator position)
Delete an element from the container.
void resize(size_t n, const Tp &val)
Change the number of elements in the container.
const_iterator cend() const noexcept
Get constant iterator to element past last element.
iterator insert_from_range(const_iterator position, Integral n, Integral val, std::true_type)
iterator insert(const_iterator position, std::initializer_list< Tp > initlist)
Insert elements at a given position and initialize them from a initializer list.
std::false_type allocator_is_always_equal
void swap(uvector< Tp, Alloc > &other, std::true_type) noexcept
implementation of swap with propagate_on_container_swap
iterator end() noexcept
Get iterator to element past last element.
const Tp * data() const noexcept
Get constant pointer to internal storage.
void emplace_back(Args &&... args)
Add the given value to the end of the container by constructing it in place.
const_iterator end() const noexcept
Get constant iterator to element past last element.
pointer allocate(size_t n)
iterator insert(const_iterator position, size_t n, const Tp &val)
Insert elements at a given position and initialize them with a value.
const Tp & front() const noexcept
Get constant reference to first element in container.
size_t enlarge_size(size_t extra_space_needed) const noexcept
void pop_back()
Remove the last element from the container.
iterator insert(const_iterator position, Tp &&item)
Insert an element at a given position by moving it in.
Tp & operator[](size_t index) noexcept
Get a reference to the element at the given index.
Tp & at(size_t index)
Get a reference to the element at the given index with bounds checking.
void enlarge_for_insert(size_t newSize, size_t insert_position, size_t insert_count)
uvector(const uvector< Tp, Alloc > &other)
Copy construct a uvector.
void push_back(InputIterator first, InputIterator last)
Add a range of items to the end of the container.
reverse_iterator rbegin() noexcept
Get reverse iterator to last element.
std::reverse_iterator< const_iterator > const_reverse_iterator
Reverse iterator of constant elements.
uvector(std::initializer_list< Tp > initlist, const allocator_type &allocator=Alloc())
Construct a uvector from a initializer list.
void assign(InputIterator first, InputIterator last)
Assign this container to be equal to the given range.
const_reverse_iterator crbegin() const noexcept
Get constant reverse iterator to last element.
void construct_from_range(Integral n, Integral val, std::true_type)
void assign_from_range(InputIterator first, InputIterator last, std::false_type)
iterator erase(const_iterator first, const_iterator last)
Delete a range of elements from the container.
void push_back(const Tp &item)
Add the given value to the end of the container.
void swap(uvector< Tp, Alloc > &other) noexcept
Swap the contents of this uvector with the given uvector.
std::ptrdiff_t difference_type
Difference between to iterators.
void push_back(Tp &&item)
Add the given value to the end of the container by moving it in.
void construct_from_range(InputIterator first, InputIterator last, std::forward_iterator_tag)
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.
uvector(size_t n)
Construct a vector with given amount of elements, without initializing these.
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.
size_t max_size() const noexcept
Get maximum number of elements that this container can hold.
Tp & front() noexcept
Get reference to first element in container.
allocator_type get_allocator() const noexcept
Get a copy of the allocator.
iterator emplace(const_iterator position, Args &&... args)
Insert an element at a given position by constructing it in place.
void check_bounds(size_t index) const
std::size_t size_t
Type used for indexing elements.
iterator insert(const_iterator position, const Tp &item)
Insert an element at a given position.
uvector(uvector< Tp, Alloc > &&other, const allocator_type &allocator) noexcept
Move construct a uvector with custom allocator.
iterator insert_from_range(const_iterator position, InputIterator first, InputIterator last, std::false_type)
std::size_t size_type
Type used for indexing elements.
bool operator>(const uvector< Tp, Alloc > &lhs, const uvector< Tp, Alloc > &rhs) noexcept
Compare two uvectors for larger than.
bool operator<=(const uvector< Tp, Alloc > &lhs, const uvector< Tp, Alloc > &rhs) noexcept
Compare two uvectors for smaller than or equal.
bool operator==(const uvector< Tp, Alloc > &lhs, const uvector< Tp, Alloc > &rhs) noexcept
Compare two uvectors for equality.
bool operator>=(const uvector< Tp, Alloc > &lhs, const uvector< Tp, Alloc > &rhs) noexcept
Compare two uvectors for larger than or equal.
bool operator<(const uvector< Tp, Alloc > &lhs, const uvector< Tp, Alloc > &rhs) noexcept
Compare two uvectors for smaller than.
void swap(uvector< Tp, Alloc > &x, uvector< Tp, Alloc > &y)
Swap the contents of the two uvectors.
bool operator!=(const uvector< Tp, Alloc > &lhs, const uvector< Tp, Alloc > &rhs) noexcept
Compare two uvectors for inequality.
StatsData< AccumType > copy(const StatsData< AccumType > &stats)
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
PtrHolder< T > & operator=(const PtrHolder< T > &other)
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.