5 #ifndef BITCOIN_PREVECTOR_H 6 #define BITCOIN_PREVECTOR_H 15 #include <type_traits> 38 template<
unsigned int N,
typename T,
typename Size = u
int32_t,
typename Diff =
int32_t>
167 if (new_capacity <= N) {
185 char* new_indirect =
static_cast<char*
>(malloc(((
size_t)
sizeof(T)) * new_capacity));
186 assert(new_indirect);
188 T* dst =
reinterpret_cast<T*
>(new_indirect);
200 void fill(T* dst, ptrdiff_t count) {
201 if (IS_TRIVIALLY_CONSTRUCTIBLE<T>::value) {
205 ::memset(dst, 0, count *
sizeof(T));
207 for (
auto i = 0; i < count; ++i) {
208 new(
static_cast<void*
>(dst + i)) T();
213 void fill(T* dst, ptrdiff_t count,
const T& value) {
214 for (
auto i = 0; i < count; ++i) {
215 new(
static_cast<void*
>(dst + i)) T(value);
219 template<
typename InputIterator>
220 void fill(T* dst, InputIterator first, InputIterator last) {
221 while (first != last) {
222 new(
static_cast<void*
>(dst)) T(*first);
238 template<
typename InputIterator>
239 void assign(InputIterator first, InputIterator last) {
261 template<
typename InputIterator>
281 if (&other ==
this) {
329 if (cur_size == new_size) {
332 if (cur_size > new_size) {
339 ptrdiff_t increase = new_size - cur_size;
367 new(
static_cast<void*
>(ptr)) T(value);
378 memmove(ptr + count, ptr, (
size() - p) *
sizeof(T));
383 template<
typename InputIterator>
392 memmove(ptr + count, ptr, (
size() - p) *
sizeof(T));
394 fill(ptr, first, last);
398 return erase(pos, pos + 1);
409 char* endp = (
char*)&(*
end());
410 if (!std::is_trivially_destructible<T>::value) {
419 memmove(&(*first), &(*last), endp - ((
char*)(&(*last))));
458 if (!std::is_trivially_destructible<T>::value) {
475 if ((*b1) != (*b2)) {
485 return !(*
this == other);
488 bool operator<(const prevector<N, T, Size, Diff>& other)
const {
489 if (
size() < other.size()) {
492 if (
size() > other.size()) {
529 #endif // BITCOIN_PREVECTOR_H bool operator!=(const prevector< N, T, Size, Diff > &other) const
T * direct_ptr(difference_type pos)
std::bidirectional_iterator_tag iterator_category
prevector & operator=(const prevector< N, T, Size, Diff > &other)
const value_type & const_reference
const_iterator operator--(int)
void resize(size_type new_size)
const T * operator->() const
const T & operator[](size_type pos) const
const value_type * const_pointer
void assign(size_type n, const T &val)
T * indirect_ptr(difference_type pos)
iterator operator+(size_type n)
bool operator<=(const_iterator x) const
iterator operator-(size_type n)
prevector(prevector< N, T, Size, Diff > &&other)
void assign(InputIterator first, InputIterator last)
reverse_iterator operator++(int)
iterator insert(iterator pos, const T &value)
reverse_iterator operator--(int)
const T & operator[](size_type pos) const
void fill(T *dst, ptrdiff_t count, const T &value)
bool operator!=(iterator x) const
const_iterator & operator-=(size_type n)
const_reverse_iterator & operator--()
const_iterator & operator++()
void insert(iterator pos, InputIterator first, InputIterator last)
const_reverse_iterator operator--(int)
reverse_iterator(T *ptr_)
void fill(T *dst, InputIterator first, InputIterator last)
const T * operator->() const
const value_type * data() const
const T * direct_ptr(difference_type pos) const
size_t allocated_memory() const
bool operator==(const prevector< N, T, Size, Diff > &other) const
const_reverse_iterator & operator++()
T & operator[](size_type pos)
bool operator==(const_reverse_iterator x) const
bool operator>=(iterator x) const
prevector(const prevector< N, T, Size, Diff > &other)
const_reverse_iterator operator++(int)
bool operator>=(const_iterator x) const
const T * item_ptr(difference_type pos) const
void push_back(const T &value)
prevector & operator=(prevector< N, T, Size, Diff > &&other)
const T & operator*() const
const_reverse_iterator rend() const
const_reverse_iterator rbegin() const
T & operator[](size_type pos)
void swap(prevector< N, T, Size, Diff > &other)
bool operator<=(iterator x) const
void insert(iterator pos, size_type count, const T &value)
const_iterator operator+(size_type n)
const_reverse_iterator(reverse_iterator x)
bool operator>(const_iterator x) const
bool operator==(iterator x) const
reverse_iterator rbegin()
void fill(T *dst, ptrdiff_t count)
char direct[sizeof(T) *N]
iterator & operator+=(size_type n)
iterator erase(iterator pos)
bool operator<(iterator x) const
const_reverse_iterator(const T *ptr_)
const T & operator[](size_type pos) const
const_iterator(iterator x)
reverse_iterator & operator++()
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
bool operator!=(const_reverse_iterator x) const
const_iterator & operator--()
bool operator==(reverse_iterator x) const
const_iterator operator-(size_type n)
void reserve(size_type new_capacity)
const T * operator->() const
void change_capacity(size_type new_capacity)
prevector(InputIterator first, InputIterator last)
T * item_ptr(difference_type pos)
void * memcpy(void *a, const void *b, size_t c)
bool operator>(iterator x) const
reverse_iterator & operator--()
std::random_access_iterator_tag iterator_category
union prevector::direct_or_indirect _union
const T & operator*() const
std::bidirectional_iterator_tag iterator_category
const_iterator operator++(int)
std::random_access_iterator_tag iterator_category
iterator erase(iterator first, iterator last)
bool operator!=(const_iterator x) const
difference_type friend operator-(iterator a, iterator b)
const T * indirect_ptr(difference_type pos) const
bool operator<(const_iterator x) const
prevector(size_type n, const T &val)
const T & operator*() const
const_iterator end() const
iterator & operator-=(size_type n)
void * memmove(void *a, const void *b, size_t c)
const_iterator begin() const
bool operator==(const_iterator x) const
bool operator!=(reverse_iterator x) const
const_iterator & operator+=(size_type n)
const_iterator(const T *ptr_)
difference_type friend operator-(const_iterator a, const_iterator b)