1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
#pragma once
#include "fwd.h"
#include "reserve.h"
#include <util/memory/alloc.h>
#include <vector>
#include <initializer_list>
#ifdef _YNDX_LIBCXX_ENABLE_VECTOR_POD_RESIZE_UNINITIALIZED
#include <type_traits>
#endif
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::move(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::move(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 static_cast<yssize_t>(TBase::size());
}
#if defined(_YNDX_LIBCXX_ENABLE_VECTOR_POD_RESIZE_UNINITIALIZED) && !defined(__CUDACC__)
void yresize(size_type newSize) {
if (std::is_standard_layout_v<T> && std::is_trivial_v<T>) {
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());
}
}
};
|