5 #ifndef _FABCOIN_PREVECTOR_H_ 6 #define _FABCOIN_PREVECTOR_H_ 14 #include <type_traits> 35 template<
unsigned int N,
typename T,
typename Size = u
int32_t,
typename Diff =
int32_t>
150 char direct[
sizeof(
T) * N];
164 if (new_capacity <= N) {
182 char* new_indirect =
static_cast<char*
>(malloc(((
size_t)
sizeof(
T)) * new_capacity));
185 T* dst =
reinterpret_cast<T*
>(new_indirect);
209 template<
typename InputIterator>
210 void assign(InputIterator first, InputIterator last) {
211 size_type n = last - first;
216 while (first != last) {
237 template<
typename InputIterator>
238 prevector(InputIterator first, InputIterator last) : _size(0) {
239 size_type n = last - first;
241 while (first != last) {
251 while (it != other.
end()) {
263 if (&other ==
this) {
269 while (it != other.
end()) {
283 return is_direct() ? _size : _size - N - 1;
317 if (
size() > new_size) {
323 while (
size() < new_size) {
344 size_type p = pos -
begin();
345 size_type new_size =
size() + 1;
351 new(
static_cast<void*
>(
item_ptr(p)))
T(value);
356 size_type p = pos -
begin();
363 for (size_type i = 0; i <
count; i++) {
364 new(
static_cast<void*
>(
item_ptr(p + i)))
T(value);
368 template<
typename InputIterator>
370 size_type p = pos -
begin();
371 difference_type
count = last - first;
378 while (first != last) {
379 new(
static_cast<void*
>(
item_ptr(p)))
T(*first);
386 return erase(pos, pos + 1);
397 char* endp = (
char*)&(*
end());
398 if (!std::is_trivially_destructible<T>::value) {
407 memmove(&(*first), &(*last), endp - ((
char*)(&(*last))));
412 size_type new_size =
size() + 1;
446 if (!std::is_trivially_destructible<T>::value) {
463 if ((*b1) != (*b2)) {
473 return !(*
this == other);
476 bool operator<(const prevector<N, T, Size, Diff>& other)
const {
477 if (
size() < other.size()) {
480 if (
size() > other.size()) {
511 const value_type*
data()
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 value_type * const_pointer
bool operator!=(const prevector< N, T, Size, Diff > &other) const
void assign(size_type n, const T &val)
bool operator>=(iterator x) const
T * indirect_ptr(difference_type pos)
iterator operator+(size_type n)
bool operator==(const prevector< N, T, Size, Diff > &other) const
iterator operator-(size_type n)
prevector(prevector< N, T, Size, Diff > &&other)
bool operator==(reverse_iterator x) const
void assign(InputIterator first, InputIterator last)
reverse_iterator operator++(int)
iterator insert(iterator pos, const T &value)
const T * direct_ptr(difference_type pos) const
const value_type * data() const
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
bool operator<(iterator x) const
reverse_iterator operator--(int)
const_iterator & operator-=(size_type n)
const_reverse_iterator & operator--()
const_iterator & operator++()
void insert(iterator pos, InputIterator first, InputIterator last)
const T * operator->() const
const_reverse_iterator operator--(int)
reverse_iterator(T *ptr_)
bool operator!=(const_reverse_iterator x) const
bool operator<=(iterator x) const
bool operator!=(const_iterator x) const
const_reverse_iterator rend() const
assert(len-trim+(2 *lenIndices)<=WIDTH)
const T & operator[](size_type pos) const
const_reverse_iterator & operator++()
T & operator[](size_type pos)
const T * operator->() const
prevector(const prevector< N, T, Size, Diff > &other)
prevector(size_type n, const T &val=T())
const_reverse_iterator operator++(int)
bool operator!=(reverse_iterator x) const
void push_back(const T &value)
prevector & operator=(prevector< N, T, Size, Diff > &&other)
const T * indirect_ptr(difference_type pos) const
T & operator[](size_type pos)
void swap(prevector< N, T, Size, Diff > &other)
void insert(iterator pos, size_type count, const T &value)
const_iterator operator+(size_type n)
const_reverse_iterator(reverse_iterator x)
reverse_iterator rbegin()
iterator & operator+=(size_type n)
iterator erase(iterator pos)
const T * item_ptr(difference_type pos) const
const_reverse_iterator(const T *ptr_)
const_iterator begin() const
const_iterator(iterator x)
reverse_iterator & operator++()
const T * operator->() const
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
size_t allocated_memory() const
const_iterator & operator--()
const_iterator operator-(size_type n)
void reserve(size_type new_capacity)
bool operator!=(iterator x) const
bool operator<=(const_iterator x) const
const T & operator*() const
bool operator==(const_reverse_iterator x) const
const_reverse_iterator rbegin() const
void change_capacity(size_type new_capacity)
prevector(InputIterator first, InputIterator last)
T * item_ptr(difference_type pos)
const T & operator*() const
void * memcpy(void *a, const void *b, size_t c)
bool operator<(const_iterator x) const
reverse_iterator & operator--()
bool operator==(iterator x) const
std::random_access_iterator_tag iterator_category
union prevector::direct_or_indirect _union
std::bidirectional_iterator_tag iterator_category
const_iterator operator++(int)
const_iterator end() const
std::random_access_iterator_tag iterator_category
iterator erase(iterator first, iterator last)
bool operator>(const_iterator x) const
bool operator==(const_iterator x) const
bool operator>(iterator x) const
difference_type friend operator-(iterator a, iterator b)
const T & operator[](size_type pos) const
iterator & operator-=(size_type n)
void * memmove(void *a, const void *b, size_t c)
bool operator>=(const_iterator x) const
const_iterator & operator+=(size_type n)
const_iterator(const T *ptr_)
const T & operator[](size_type pos) const
const T & operator*() const
difference_type friend operator-(const_iterator a, const_iterator b)