diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/generic/vector.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/generic/vector.h')
-rw-r--r-- | util/generic/vector.h | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/util/generic/vector.h b/util/generic/vector.h new file mode 100644 index 00000000000..a5b258955a8 --- /dev/null +++ b/util/generic/vector.h @@ -0,0 +1,132 @@ +#pragma once + +#include "fwd.h" +#include "reserve.h" + +#include <util/memory/alloc.h> + +#include <vector> +#include <initializer_list> + +template <class T, class A> +class TVector: public std::vector<T, TReboundAllocator<A, T>> { +public: + using TBase = std::vector<T, TReboundAllocator<A, T>>; + using TSelf = TVector<T, A>; + using size_type = typename TBase::size_type; + + inline TVector() + : TBase() + { + } + + inline TVector(const typename TBase::allocator_type& a) + : TBase(a) + { + } + + inline explicit TVector(::NDetail::TReserveTag rt) + : TBase() + { + this->reserve(rt.Capacity); + } + + inline explicit TVector(::NDetail::TReserveTag rt, const typename TBase::allocator_type& a) + : TBase(a) + { + this->reserve(rt.Capacity); + } + + inline explicit TVector(size_type count) + : TBase(count) + { + } + + inline explicit TVector(size_type count, const typename TBase::allocator_type& a) + : TBase(count, a) + { + } + + inline TVector(size_type count, const T& val) + : TBase(count, val) + { + } + + inline TVector(size_type count, const T& val, const typename TBase::allocator_type& a) + : TBase(count, val, a) + { + } + + inline TVector(std::initializer_list<T> il) + : TBase(il) + { + } + + inline TVector(std::initializer_list<T> il, const typename TBase::allocator_type& a) + : TBase(il, a) + { + } + + inline TVector(const TSelf& src) + : TBase(src) + { + } + + inline TVector(TSelf&& src) noexcept + : TBase(std::forward<TSelf>(src)) + { + } + + template <class TIter> + inline TVector(TIter first, TIter last) + : TBase(first, last) + { + } + + inline TSelf& operator=(const TSelf& src) { + TBase::operator=(src); + return *this; + } + + inline TSelf& operator=(TSelf&& src) noexcept { + TBase::operator=(std::forward<TSelf>(src)); + return *this; + } + + inline TSelf& operator=(std::initializer_list<T> il) { + this->assign(il.begin(), il.end()); + return *this; + } + + inline explicit operator bool() const noexcept { + return !this->empty(); + } + + Y_PURE_FUNCTION inline bool empty() const noexcept { + return TBase::empty(); + } + + inline yssize_t ysize() const noexcept { + return (yssize_t)TBase::size(); + } + +#ifdef _YNDX_LIBCXX_ENABLE_VECTOR_POD_RESIZE_UNINITIALIZED + void yresize(size_type newSize) { + if (std::is_pod<T>::value) { + TBase::resize_uninitialized(newSize); + } else { + TBase::resize(newSize); + } + } +#else + void yresize(size_type newSize) { + TBase::resize(newSize); + } +#endif + + inline void crop(size_type size) { + if (this->size() > size) { + this->erase(this->begin() + size, this->end()); + } + } +}; |