5 #ifndef DUNE_COMMON_RESERVEDVECTOR_HH 6 #define DUNE_COMMON_RESERVEDVECTOR_HH 18 #include <initializer_list> 24 #ifdef CHECK_RESERVEDVECTOR 25 #define CHECKSIZE(X) assert(X) 27 #define CHECKSIZE(X) {} 47 template<
class T,
int n>
50 using storage_type = std::array<T,n>;
56 typedef typename storage_type::value_type
value_type;
59 typedef typename storage_type::pointer
pointer;
71 typedef typename storage_type::iterator
iterator;
92 noexcept(std::is_nothrow_default_constructible_v<value_type>)
101 noexcept(std::is_nothrow_copy_assignable_v<value_type> &&
110 template<
class InputIt,
111 std::enable_if_t<std::is_convertible_v<typename std::iterator_traits<InputIt>::value_type,
value_type>,
int> = 0>
113 noexcept(std::is_nothrow_copy_assignable_v<value_type> &&
118 storage_[
i] = *first++;
119 assert(first == last);
124 noexcept(std::is_nothrow_copy_assignable_v<value_type> &&
136 if (
size() != that.size())
139 if (!(storage_[
i]==that.storage_[
i]))
154 constexpr
void clear() noexcept
169 noexcept(std::is_nothrow_copy_assignable_v<value_type>)
172 storage_[size_++] = t;
177 noexcept(std::is_nothrow_move_assignable_v<value_type>)
180 storage_[size_++] = std::move(t);
184 template<
class... Args>
186 noexcept(std::is_nothrow_constructible_v<
value_type,decltype(args)...>)
195 ::new (const_cast<void*>(static_cast<const volatile void*>(p)))
203 if (!
empty()) size_--;
213 return storage_.begin();
219 return storage_.begin();
225 return storage_.cbegin();
249 return storage_.begin()+
size();
255 return storage_.begin()+
size();
261 return storage_.cbegin()+
size();
290 throw std::out_of_range(
"Index out of range");
298 throw std::out_of_range(
"Index out of range");
334 return storage_[size_-1];
341 return storage_[size_-1];
347 return storage_.data();
353 return storage_.data();
367 constexpr
bool empty() const noexcept
390 noexcept(std::is_nothrow_copy_assignable_v<value_type>)
398 noexcept(std::is_nothrow_swappable_v<value_type>)
401 swap(storage_, other.storage_);
402 swap(size_, other.size_);
417 return hash_range(v.storage_.data(),v.storage_.data()+v.size_);
421 storage_type storage_;
431 #endif // DUNE_COMMON_RESERVEDVECTOR_HH constexpr const_iterator cbegin() const noexcept
Returns a const_iterator pointing to the beginning of the vector.
Definition: reservedvector.hh:223
constexpr ReservedVector(InputIt first, InputIt last) noexcept(std::is_nothrow_copy_assignable_v< value_type > &&noexcept(ReservedVector()))
Constructs the vector from an iterator range [first,last)
Definition: reservedvector.hh:112
constexpr void push_back(const value_type &t) noexcept(std::is_nothrow_copy_assignable_v< value_type >)
Appends an element to the end of a vector, up to the maximum size n, O(1) time.
Definition: reservedvector.hh:168
static constexpr size_type max_size() noexcept
Returns the maximum length of the vector.
Definition: reservedvector.hh:379
constexpr void pop_back() noexcept
Erases the last element of the vector, O(1) time.
Definition: reservedvector.hh:201
constexpr bool operator==(const ReservedVector &that) const noexcept
Compares the values in the vector this with that for equality.
Definition: reservedvector.hh:134
constexpr void clear() noexcept
Erases all elements.
Definition: reservedvector.hh:155
static constexpr size_type capacity() noexcept
Returns current capacity (allocated memory) of the vector.
Definition: reservedvector.hh:373
constexpr reference at(size_type i)
Returns reference to the i'th element.
Definition: reservedvector.hh:287
This file provides some concepts introduced in the C++20 standard library <compare> and <concepts> no...
constexpr const_pointer data() const noexcept
Returns const pointer to the underlying memory.
Definition: reservedvector.hh:351
constexpr pointer data() noexcept
Returns pointer to the underlying memory.
Definition: reservedvector.hh:345
constexpr const_reference at(size_type i) const
Returns a const reference to the i'th element.
Definition: reservedvector.hh:295
std::reverse_iterator< const_iterator > const_reverse_iterator
Const reverse iterator.
Definition: reservedvector.hh:77
constexpr auto lexicographical_compare_three_way(I1 f1, I1 l1, I2 f2, I2 l2, Cmp comp={}) -> decltype(comp(*f1, *f2))
Lexicographically compares two ranges [first1, last1) and [first2, last2) using three-way comparison ...
Definition: algorithm.hh:37
storage_type::reference reference
Reference to T.
Definition: reservedvector.hh:63
constexpr const_reference back() const noexcept
Returns const reference to last element of vector.
Definition: reservedvector.hh:338
constexpr ReservedVector(std::initializer_list< value_type > const &l) noexcept(std::is_nothrow_copy_assignable_v< value_type > &&noexcept(ReservedVector(l.begin(), l.end())))
Constructs the vector from an initializer list.
Definition: reservedvector.hh:123
constexpr void push_back(value_type &&t) noexcept(std::is_nothrow_move_assignable_v< value_type >)
Appends an element to the end of a vector by moving the value, up to the maximum size n...
Definition: reservedvector.hh:176
constexpr ReservedVector(size_type count) noexcept(std::is_nothrow_default_constructible_v< value_type >)
Constructs the vector with count elements that will be default-initialized.
Definition: reservedvector.hh:91
storage_type::pointer pointer
Pointer to T.
Definition: reservedvector.hh:59
constexpr ReservedVector(size_type count, const value_type &value) noexcept(std::is_nothrow_copy_assignable_v< value_type > &&noexcept(ReservedVector(count)))
Constructs the vector with count copies of elements with value value.
Definition: reservedvector.hh:100
constexpr reference front() noexcept
Returns reference to first element of vector.
Definition: reservedvector.hh:317
constexpr const_reverse_iterator crbegin() const noexcept
Returns a const reverse-iterator pointing to the end of the vector.
Definition: reservedvector.hh:241
constexpr reference back() noexcept
Returns reference to last element of vector.
Definition: reservedvector.hh:331
constexpr void resize(size_type s) noexcept
Specifies a new size for the vector.
Definition: reservedvector.hh:161
constexpr const_iterator end() const noexcept
Returns a const_iterator pointing to the end of the vector.
Definition: reservedvector.hh:253
constexpr bool empty() const noexcept
Returns true if vector has no elements.
Definition: reservedvector.hh:367
I i
Definition: hybridmultiindex.hh:328
void swap(ReservedVector &other) noexcept(std::is_nothrow_swappable_v< value_type >)
Swap the content with another vector.
Definition: reservedvector.hh:397
constexpr iterator begin() noexcept
Returns a iterator pointing to the beginning of the vector.
Definition: reservedvector.hh:211
A Vector class with statically reserved memory.
Definition: reservedvector.hh:48
constexpr const_iterator begin() const noexcept
Returns a const_iterator pointing to the beginning of the vector.
Definition: reservedvector.hh:217
Dune namespace
Definition: alignedallocator.hh:12
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator.
Definition: reservedvector.hh:75
constexpr const_reference front() const noexcept
Returns const reference to first element of vector.
Definition: reservedvector.hh:324
storage_type::const_iterator const_iterator
Const iterator used to iterate through a vector.
Definition: reservedvector.hh:73
storage_type::size_type size_type
An unsigned integral type.
Definition: reservedvector.hh:67
storage_type::iterator iterator
Iterator used to iterate through a vector.
Definition: reservedvector.hh:71
constexpr reference operator[](size_type i) noexcept
Returns reference to the i'th element.
Definition: reservedvector.hh:303
Support for calculating hash values of objects.
constexpr const_iterator cend() const noexcept
Returns a const_iterator pointing to the end of the vector.
Definition: reservedvector.hh:259
storage_type::value_type value_type
The type of object, T, stored in the vector.
Definition: reservedvector.hh:57
reference emplace_back(Args &&... args) noexcept(std::is_nothrow_constructible_v< value_type, decltype(args)... >)
Appends an element to the end of a vector by constructing it in place.
Definition: reservedvector.hh:185
constexpr void fill(const value_type &value) noexcept(std::is_nothrow_copy_assignable_v< value_type >)
Fill the container with the value.
Definition: reservedvector.hh:389
storage_type::const_reference const_reference
Const reference to T.
Definition: reservedvector.hh:65
constexpr const_reverse_iterator rend() const noexcept
Returns a const reverse-iterator pointing to the begin of the vector.
Definition: reservedvector.hh:271
storage_type::difference_type difference_type
A signed integral type.
Definition: reservedvector.hh:69
constexpr reverse_iterator rbegin() noexcept
Returns a const reverse-iterator pointing to the end of the vector.
Definition: reservedvector.hh:229
constexpr size_type size() const noexcept
Returns number of elements in the vector.
Definition: reservedvector.hh:361
constexpr reverse_iterator rend() noexcept
Returns a const reverse-iterator pointing to the begin of the vector.
Definition: reservedvector.hh:265
friend std::ostream & operator<<(std::ostream &s, const ReservedVector &v)
Send ReservedVector to an output stream.
Definition: reservedvector.hh:408
constexpr const_reverse_iterator rbegin() const noexcept
Returns a const reverse-iterator pointing to the end of the vector.
Definition: reservedvector.hh:235
#define CHECKSIZE(X)
Definition: reservedvector.hh:27
std::size_t hash_range(It first, It last)
Hashes all elements in the range [first,last) and returns the combined hash.
Definition: hash.hh:322
constexpr iterator end() noexcept
Returns an iterator pointing to the end of the vector.
Definition: reservedvector.hh:247
#define DUNE_HASH_TYPE(...)
Wrapper macro for the type to be hashed in DUNE_DEFINE_HASH.
Definition: hash.hh:117
void swap(T &v1, T &v2, bool mask)
Definition: simd.hh:472
constexpr const_reverse_iterator crend() const noexcept
Returns a const reverse-iterator pointing to the begin of the vector.
Definition: reservedvector.hh:277
constexpr ReservedVector() noexcept(std::is_nothrow_default_constructible_v< value_type >)
Constructs an empty vector.
Definition: reservedvector.hh:84
#define DUNE_DEFINE_HASH(template_args, type)
Defines the required struct specialization to make type hashable via Dune::hash.
Definition: hash.hh:100
storage_type::const_pointer const_pointer
Const pointer to T.
Definition: reservedvector.hh:61
friend std::size_t hash_value(const ReservedVector &v) noexcept
Definition: reservedvector.hh:415
#define DUNE_HASH_TEMPLATE_ARGS(...)
Wrapper macro for the template arguments in DUNE_DEFINE_HASH.
Definition: hash.hh:109