 |
SWC-DB
v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
|
Go to the documentation of this file.
6 #ifndef swcdb_core_Vector_h
7 #define swcdb_core_Vector_h
11 namespace SWC {
namespace Core {
13 template<
typename T,
typename SizeT=u
int32_t, SizeT GROW_SZ=0>
17 = std::is_const_v<T> ||
18 !(std::is_pointer_v<T> ||
19 std::is_integral_v<T> ||
20 (std::is_reference_v<T> &&
21 !std::is_const_v<std::remove_reference_t<const T&>>) );
24 = !(std::is_pointer_v<T> ||
25 std::is_integral_v<T> ||
26 std::is_reference_v<T> ||
27 std::is_trivially_destructible_v<T> );
30 = std::is_nothrow_constructible_v<T, const T&>;
33 = std::is_nothrow_constructible_v<T, T&&>;
36 = std::is_nothrow_move_assignable_v<T>;
39 = std::is_nothrow_destructible_v<T>;
61 static_assert(
max_size() > 0,
"SWC-DB Vector supports only unsigned size!");
67 template<
typename... ArgsT>
70 :
_data(sz ?
_allocate(sz, std::forward<ArgsT>(args)...) : nullptr),
77 other._data =
nullptr;
78 other._cap = other._size = 0;
101 Vector(std::initializer_list<value_type>&& l)
112 for(
auto& it : *
this)
146 other._data =
nullptr;
147 other._cap = other._size = 0;
162 std::swap(
_data, other._data);
163 std::swap(
_cap, other._cap);
164 std::swap(
_size, other._size);
174 if(
_size != other.size())
177 if((*
this)[i] != other[i])
185 return !(*
this == other);
298 _grow(GROW_SZ ? (GROW_SZ < remain ? GROW_SZ : remain)
306 template<
typename... ArgsT>
313 _construct(ptr, std::forward<ArgsT>(args)...);
318 }
else if(sz <
_size) {
329 template<
typename... ArgsT>
338 template<
typename... ArgsT>
341 noexcept(std::is_nothrow_constructible_v<value_type, ArgsT...>) {
347 template<
typename... ArgsT>
355 template<
typename... ArgsT>
358 noexcept(std::is_nothrow_constructible_v<value_type, ArgsT...>) {
365 template<
typename... ArgsT>
373 throw std::out_of_range(
"Reached size_type limit!");
379 std::forward<ArgsT>(args)...);
382 return _data + offset;
385 template<
typename... ArgsT>
388 return insert(it -
_data, std::forward<ArgsT>(args)...);
391 template<
typename... ArgsT>
394 return *
insert(it, std::forward<ArgsT>(args)...);
397 template<
typename... ArgsT>
402 std::is_nothrow_constructible_v<value_type, ArgsT...>) {
404 return offset >=
_size
408 std::forward<ArgsT>(args)...);
416 return _data + offset;
422 throw std::out_of_range(
"Reached size_type limit!");
427 return _data + offset;
450 template<
typename IteratorT>
452 void assign(IteratorT first, IteratorT last) {
472 *ptr = std::move(*(ptr + 1));
476 return _data + offset;
497 *ptr = std::move(*(ptr + amt));
502 return _data + offset;
518 if(sz && (
_cap += sz))
524 return static_cast<pointer>(::operator
new(
526 std::align_val_t(std::alignment_of<value_type>::value)
550 template<
typename... ArgsT>
556 throw std::out_of_range(
"Offset above size_type limit!");
561 for(; i < offset; ++ptr, ++ptr_prev, ++i) {
564 ptr_prev->~value_type();
566 _construct(ptr++, std::forward<ArgsT>(args)...);
568 for(; i < size_prev; ++i, ++ptr, ++ptr_prev) {
571 ptr_prev->~value_type();
587 for(; i < offset; ++ptr, ++ptr_prev, ++i) {
590 ptr_prev->~value_type();
595 for(; i < size_prev; ++i, ++ptr, ++ptr_prev) {
598 ptr_prev->~value_type();
608 std::align_val_t(std::alignment_of<value_type>::value)
613 template<
typename... ArgsT>
619 _construct(ptr, std::forward<ArgsT>(args)...);
626 template<
typename... ArgsT>
629 noexcept(std::is_nothrow_constructible_v<value_type, ArgsT...>) {
631 new (ptr)
value_type(std::forward<ArgsT>(args)...);
640 for(
pointer ptr=
data; size_prev; --size_prev, ++ptr, ++data_prev)
651 for(
pointer ptr=
data; size_prev; --size_prev, ++ptr, ++data_prev) {
654 data_prev->~value_type();
665 for(
pointer ptr = prev + amount; remain; --remain, --ptr, --prev) {
708 #endif // swcdb_core_Vector_h
SWC_CAN_INLINE iterator erase(size_type offset) noexcept(_NoExceptMoveAssign &&_NoExceptDestructor)
constexpr SWC_CAN_INLINE reference front() noexcept
constexpr static bool _NoExceptMoveAssign
constexpr SWC_CAN_INLINE const_iterator end() const noexcept
SWC_CAN_INLINE void resize(size_type sz, ArgsT &&... args)
constexpr SWC_CAN_INLINE const_iterator begin() const noexcept
SWC_CAN_INLINE void clear() noexcept(_NoExceptDestructor)
SWC_CAN_INLINE Vector & operator=(Vector &&other) noexcept
constexpr SWC_CAN_INLINE size_type capacity() const noexcept
static SWC_CAN_INLINE pointer _move(pointer data, pointer data_prev, size_type size_prev) noexcept(_NoExceptMove &&_NoExceptDestructor)
static SWC_CAN_INLINE pointer _alter(pointer data, size_type remain, size_type amount) noexcept(_NoExceptMove &&_NoExceptDestructor)
const value_type * const_iterator
constexpr SWC_CAN_INLINE Vector(Vector &&other) noexcept
constexpr SWC_CAN_INLINE const_pointer data() const noexcept
SWC_CAN_INLINE ~Vector() noexcept(_NoExceptDestructor)
SWC_CAN_INLINE Vector(size_type sz, ArgsT &&... args)
constexpr SWC_CAN_INLINE Vector() noexcept
SWC_CAN_INLINE reference emplace(const_iterator it, ArgsT &&... args)
SWC_CAN_INLINE iterator insert(const_iterator it, const_iterator first, const_iterator last)
static SWC_CAN_INLINE pointer _copy(pointer data, const_pointer data_prev, size_type size_prev) noexcept(_NoExceptCopy)
static SWC_CAN_INLINE pointer _allocate_insert(pointer data_prev, size_type size_prev, size_type offset, size_type size, ArgsT &&... args)
SWC_CAN_INLINE iterator insert_unsafe(const_iterator it, ArgsT &&... args) noexcept(_NoExceptMove &&_NoExceptDestructor &&std::is_nothrow_constructible_v< value_type, ArgsT... >)
constexpr SWC_CAN_INLINE bool empty() const noexcept
SWC_CAN_INLINE void pop_back() noexcept(_NoExceptDestructor)
constexpr SWC_CAN_INLINE reference back() noexcept
constexpr SWC_CAN_INLINE iterator end() noexcept
The SWC-DB C++ namespace 'SWC'.
SWC_CAN_INLINE void push_back_unsafe(ArgsT &&... args) noexcept(std::is_nothrow_constructible_v< value_type, ArgsT... >)
constexpr static bool _NoExceptMove
constexpr static bool _Requires_Costructor
SWC_CAN_INLINE iterator erase(const_iterator it) noexcept(_NoExceptMoveAssign &&_NoExceptDestructor)
SWC_CAN_INLINE void _grow(size_type sz)
const value_type * const_pointer
constexpr SWC_CAN_INLINE bool operator==(const Vector &other) const noexcept
SWC_CAN_INLINE Vector(const Vector &other)
SWC_CAN_INLINE void swap(Vector &other) noexcept
SWC_CAN_INLINE Vector(std::initializer_list< value_type > &&l)
static SWC_CAN_INLINE pointer _construct(pointer ptr, ArgsT &&... args) noexcept(std::is_nothrow_constructible_v< value_type, ArgsT... >)
SWC_CAN_INLINE void free() noexcept
constexpr SWC_CAN_INLINE pointer data() noexcept
SWC_CAN_INLINE void shrink_to_fit(size_type sz=0)
constexpr static SWC_CAN_INLINE size_type max_size() noexcept
static SWC_CAN_INLINE pointer _allocate_uinitialized(pointer data_prev, size_t size_prev, size_type sz)
static SWC_CAN_INLINE pointer _allocate_insert(pointer data_prev, size_type size_prev, size_type offset, size_type size, const_iterator first, const_iterator last)
SWC_CAN_INLINE reference emplace_back_unsafe(ArgsT &&... args) noexcept(std::is_nothrow_constructible_v< value_type, ArgsT... >)
SWC_CAN_INLINE void reserve()
SWC_CAN_INLINE iterator insert(size_type offset, const_iterator first, const_iterator last)
constexpr SWC_CAN_INLINE const_iterator cend() const noexcept
SWC_CAN_INLINE Vector(const_iterator _b, const_iterator _e)
SWC_CAN_INLINE iterator insert(const_iterator it, ArgsT &&... args)
constexpr SWC_CAN_INLINE const_reference operator[](size_type pos) const noexcept
constexpr static bool _Requires_Destructor
static SWC_CAN_INLINE pointer _allocate(size_type sz, ArgsT &&... args)
constexpr SWC_CAN_INLINE const_reference back() const noexcept
SWC_CAN_INLINE iterator erase(const_iterator first, const_iterator last) noexcept(_NoExceptMoveAssign &&_NoExceptDestructor)
constexpr SWC_CAN_INLINE bool operator!=(const Vector &other) const noexcept
SWC_CAN_INLINE void assign(IteratorT first, IteratorT last)
const value_type & const_reference
SWC_CAN_INLINE void push_back(ArgsT &&... args)
constexpr SWC_CAN_INLINE const_iterator cbegin() const noexcept
static SWC_CAN_INLINE pointer _allocate_uinitialized(size_type size)
constexpr SWC_CAN_INLINE size_type size() const noexcept
constexpr static bool _NoExceptCopy
SWC_CAN_INLINE reference emplace_back(ArgsT &&... args)
SWC_CAN_INLINE iterator insert(size_type offset, ArgsT &&... args)
static SWC_CAN_INLINE void _deallocate(pointer data, size_t) noexcept
constexpr static bool _NoExceptDestructor
SWC_CAN_INLINE void reserve(size_type cap)
SWC_CAN_INLINE Vector & operator=(const Vector &other)
constexpr SWC_CAN_INLINE const_reference front() const noexcept
constexpr SWC_CAN_INLINE reference operator[](size_type pos) noexcept
constexpr SWC_CAN_INLINE iterator begin() noexcept