14 #ifndef LLVM_VECSMALL_ADT_SMALLVECTOR_H 15 #define LLVM_VECSMALL_ADT_SMALLVECTOR_H 22 #include <initializer_list> 27 #define LLVM_VECSMALL_NODISCARD 28 #define LLVM_VECSMALL_ATTRIBUTE_ALWAYS_INLINE inline 29 #define LLVM_VECSMALL_UNLIKELY(x) (x) 53 struct IsPod : std::integral_constant<bool, std::is_standard_layout<T>::value &&
54 std::is_trivial<T>::value> {};
59 void *BeginX, *
EndX, *CapacityX;
63 : BeginX(FirstEl), EndX(FirstEl), CapacityX((char*)FirstEl+Size) {}
67 void grow_pod(
void *FirstEl,
size_t MinSizeInBytes,
size_t TSize);
72 return size_t((
char*)EndX - (
char*)BeginX);
77 return size_t((
char*)CapacityX - (
char*)BeginX);
88 template <
typename T,
typename =
void>
104 void grow_pod(
size_t MinSizeInBytes,
size_t TSize) {
111 return BeginX ==
static_cast<const void*
>(&FirstEl);
116 BeginX = EndX = CapacityX = &FirstEl;
137 iterator
begin() {
return (iterator)this->BeginX; }
139 const_iterator
begin()
const {
return (const_iterator)this->BeginX; }
141 iterator
end() {
return (iterator)this->EndX; }
143 const_iterator
end()
const {
return (const_iterator)this->EndX; }
146 const_iterator
capacity_ptr()
const {
return (const_iterator)this->CapacityX;}
150 reverse_iterator
rbegin() {
return reverse_iterator(end()); }
151 const_reverse_iterator
rbegin()
const{
return const_reverse_iterator(end()); }
152 reverse_iterator
rend() {
return reverse_iterator(begin()); }
153 const_reverse_iterator
rend()
const {
return const_reverse_iterator(begin());}
156 size_type
size()
const {
return end()-begin(); }
157 size_type
max_size()
const {
return size_type(-1) /
sizeof(T); }
160 size_t capacity()
const {
return capacity_ptr() - begin(); }
163 pointer
data() {
return pointer(begin()); }
165 const_pointer
data()
const {
return const_pointer(begin()); }
199 template <
typename T,
bool isPodLike>
213 template<
typename It1,
typename It2>
215 std::uninitialized_copy(std::make_move_iterator(I),
216 std::make_move_iterator(E), Dest);
221 template<
typename It1,
typename It2>
223 std::uninitialized_copy(I, E, Dest);
229 void grow(
size_t MinSize = 0);
235 ::new ((
void*) this->end()) T(Elt);
236 this->setEnd(this->end()+1);
242 ::new ((
void*) this->end()) T(::
std::move(Elt));
243 this->setEnd(this->end()+1);
247 this->setEnd(this->end()-1);
253 template <
typename T,
bool isPodLike>
255 size_t CurCapacity = this->capacity();
256 size_t CurSize = this->
size();
259 if (NewCapacity < MinSize)
260 NewCapacity = MinSize;
261 T *NewElts =
static_cast<T*
>(malloc(NewCapacity*
sizeof(T)));
264 this->uninitialized_move(this->begin(), this->end(), NewElts);
267 destroy_range(this->begin(), this->end());
270 if (!this->isSmall())
273 this->setEnd(NewElts+CurSize);
274 this->BeginX = NewElts;
275 this->CapacityX = this->begin()+NewCapacity;
281 template <
typename T>
291 template<
typename It1,
typename It2>
294 uninitialized_copy(I, E, Dest);
299 template<
typename It1,
typename It2>
302 std::uninitialized_copy(I, E, Dest);
307 template <
typename T1,
typename T2>
309 T1 *I, T1 *E, T2 *Dest,
317 memcpy(Dest, I, (E - I) *
sizeof(T));
322 void grow(
size_t MinSize = 0) {
323 this->grow_pod(MinSize*
sizeof(T),
sizeof(T));
329 memcpy(this->end(), &Elt,
sizeof(T));
330 this->setEnd(this->end()+1);
334 this->setEnd(this->end()-1);
341 template <
typename T>
361 this->destroy_range(this->begin(), this->end());
364 if (!this->isSmall())
370 this->destroy_range(this->begin(), this->end());
371 this->EndX = this->BeginX;
375 if (N < this->
size()) {
376 this->destroy_range(this->begin()+N, this->end());
377 this->setEnd(this->begin()+N);
378 }
else if (N > this->
size()) {
379 if (this->capacity() < N)
381 for (
auto I = this->end(), E = this->begin() + N; I != E; ++I)
383 this->setEnd(this->begin()+N);
388 if (N < this->
size()) {
389 this->destroy_range(this->begin()+N, this->end());
390 this->setEnd(this->begin()+N);
391 }
else if (N > this->
size()) {
392 if (this->capacity() < N)
394 std::uninitialized_fill(this->end(), this->begin()+N, NV);
395 this->setEnd(this->begin()+N);
400 if (this->capacity() < N)
413 template<
typename in_iter>
414 void append(in_iter in_start, in_iter in_end) {
415 size_type NumInputs = std::distance(in_start, in_end);
417 if (NumInputs > size_type(this->capacity_ptr()-this->end()))
418 this->grow(this->
size()+NumInputs);
421 this->uninitialized_copy(in_start, in_end, this->end());
422 this->setEnd(this->end() + NumInputs);
426 void append(size_type NumInputs,
const T &Elt) {
428 if (NumInputs > size_type(this->capacity_ptr()-this->end()))
429 this->grow(this->
size()+NumInputs);
432 std::uninitialized_fill_n(this->end(), NumInputs, Elt);
433 this->setEnd(this->end() + NumInputs);
436 void append(std::initializer_list<T> IL) {
437 append(IL.begin(), IL.end());
440 void assign(size_type NumElts,
const T &Elt) {
442 if (this->capacity() < NumElts)
444 this->setEnd(this->begin()+NumElts);
445 std::uninitialized_fill(this->begin(), this->end(), Elt);
448 void assign(std::initializer_list<T> IL) {
455 iterator I =
const_cast<iterator
>(CI);
457 assert(I >= this->begin() &&
"Iterator to erase is out of bounds.");
458 assert(I < this->end() &&
"Erasing at past-the-end iterator.");
468 iterator
erase(const_iterator CS, const_iterator CE) {
470 iterator
S =
const_cast<iterator
>(CS);
471 iterator E =
const_cast<iterator
>(CE);
473 assert(S >= this->begin() &&
"Range to erase is out of bounds.");
474 assert(S <= E &&
"Trying to erase invalid range.");
475 assert(E <= this->end() &&
"Trying to erase past the end.");
479 iterator I =
std::move(E, this->end(), S);
481 this->destroy_range(I, this->end());
487 if (I == this->end()) {
489 return this->end()-1;
492 assert(I >= this->begin() &&
"Insertion iterator is out of bounds.");
493 assert(I <= this->end() &&
"Inserting past the end of the vector.");
495 if (this->EndX >= this->CapacityX) {
496 size_t EltNo = I-this->begin();
498 I = this->begin()+EltNo;
501 ::new ((
void*) this->end()) T(::
std::move(this->back()));
503 std::move_backward(I, this->end()-1, this->end());
504 this->setEnd(this->end()+1);
509 if (I <= EltPtr && EltPtr < this->EndX)
516 iterator
insert(iterator I,
const T &Elt) {
517 if (I == this->end()) {
518 this->push_back(Elt);
519 return this->end()-1;
522 assert(I >= this->begin() &&
"Insertion iterator is out of bounds.");
523 assert(I <= this->end() &&
"Inserting past the end of the vector.");
525 if (this->EndX >= this->CapacityX) {
526 size_t EltNo = I-this->begin();
528 I = this->begin()+EltNo;
530 ::new ((
void*) this->end()) T(
std::move(this->back()));
532 std::move_backward(I, this->end()-1, this->end());
533 this->setEnd(this->end()+1);
537 const T *EltPtr = &Elt;
538 if (I <= EltPtr && EltPtr < this->EndX)
545 iterator
insert(iterator I, size_type NumToInsert,
const T &Elt) {
547 size_t InsertElt = I - this->begin();
549 if (I == this->end()) {
551 return this->begin()+InsertElt;
554 assert(I >= this->begin() &&
"Insertion iterator is out of bounds.");
555 assert(I <= this->end() &&
"Inserting past the end of the vector.");
561 I = this->begin()+InsertElt;
567 if (
size_t(this->end()-I) >= NumToInsert) {
568 T *OldEnd = this->end();
569 append(std::move_iterator<iterator>(this->end() - NumToInsert),
570 std::move_iterator<iterator>(this->end()));
573 std::move_backward(I, OldEnd-NumToInsert, OldEnd);
583 T *OldEnd = this->end();
584 this->setEnd(this->end() + NumToInsert);
585 size_t NumOverwritten = OldEnd-I;
586 this->uninitialized_move(I, OldEnd, this->end()-NumOverwritten);
592 std::uninitialized_fill_n(OldEnd, NumToInsert-NumOverwritten, Elt);
596 template<
typename ItTy>
597 iterator
insert(iterator I, ItTy From, ItTy To) {
599 size_t InsertElt = I - this->begin();
601 if (I == this->end()) {
603 return this->begin()+InsertElt;
606 assert(I >= this->begin() &&
"Insertion iterator is out of bounds.");
607 assert(I <= this->end() &&
"Inserting past the end of the vector.");
609 size_t NumToInsert = std::distance(From, To);
615 I = this->begin()+InsertElt;
621 if (
size_t(this->end()-I) >= NumToInsert) {
622 T *OldEnd = this->end();
623 append(std::move_iterator<iterator>(this->end() - NumToInsert),
624 std::move_iterator<iterator>(this->end()));
627 std::move_backward(I, OldEnd-NumToInsert, OldEnd);
637 T *OldEnd = this->end();
638 this->setEnd(this->end() + NumToInsert);
639 size_t NumOverwritten = OldEnd-I;
640 this->uninitialized_move(I, OldEnd, this->end()-NumOverwritten);
643 for (T *J = I; NumOverwritten > 0; --NumOverwritten) {
649 this->uninitialized_copy(From, To, OldEnd);
653 void insert(iterator I, std::initializer_list<T> IL) {
654 insert(I, IL.begin(), IL.end());
657 template <
typename... ArgTypes>
void emplace_back(ArgTypes &&... Args) {
660 ::new ((
void *)this->end()) T(std::forward<ArgTypes>(Args)...);
661 this->setEnd(this->end() + 1);
669 if (this->
size() != RHS.
size())
return false;
670 return std::equal(this->begin(), this->end(), RHS.
begin());
673 return !(*
this == RHS);
677 return std::lexicographical_compare(this->begin(), this->end(),
691 assert(N <= this->capacity());
692 this->setEnd(this->begin() + N);
697 template <
typename T>
699 if (
this == &RHS)
return;
702 if (!this->isSmall() && !RHS.
isSmall()) {
708 if (RHS.
size() > this->capacity())
709 this->grow(RHS.
size());
711 RHS.
grow(this->size());
714 size_t NumShared = this->
size();
715 if (NumShared > RHS.
size()) NumShared = RHS.
size();
716 for (
size_type i = 0; i != NumShared; ++i)
721 size_t EltDiff = this->
size() - RHS.
size();
722 this->uninitialized_copy(this->begin()+NumShared, this->end(), RHS.
end());
724 this->destroy_range(this->begin()+NumShared, this->end());
725 this->setEnd(this->begin()+NumShared);
726 }
else if (RHS.
size() > this->
size()) {
727 size_t EltDiff = RHS.
size() - this->
size();
728 this->uninitialized_copy(RHS.
begin()+NumShared, RHS.
end(), this->end());
729 this->setEnd(this->end() + EltDiff);
730 this->destroy_range(RHS.
begin()+NumShared, RHS.
end());
735 template <
typename T>
739 if (
this == &RHS)
return *
this;
743 size_t RHSSize = RHS.
size();
744 size_t CurSize = this->
size();
745 if (CurSize >= RHSSize) {
751 NewEnd = this->begin();
754 this->destroy_range(NewEnd, this->end());
757 this->setEnd(NewEnd);
764 if (this->capacity() < RHSSize) {
766 this->destroy_range(this->begin(), this->end());
767 this->setEnd(this->begin());
770 }
else if (CurSize) {
776 this->uninitialized_copy(RHS.
begin()+CurSize, RHS.
end(),
777 this->begin()+CurSize);
780 this->setEnd(this->begin()+RHSSize);
784 template <
typename T>
787 if (
this == &RHS)
return *
this;
790 if (!RHS.isSmall()) {
791 this->destroy_range(this->begin(), this->end());
792 if (!this->isSmall()) free(this->begin());
793 this->BeginX = RHS.BeginX;
794 this->EndX = RHS.EndX;
795 this->CapacityX = RHS.CapacityX;
802 size_t RHSSize = RHS.size();
803 size_t CurSize = this->
size();
804 if (CurSize >= RHSSize) {
808 NewEnd =
std::move(RHS.begin(), RHS.end(), NewEnd);
811 this->destroy_range(NewEnd, this->end());
812 this->setEnd(NewEnd);
824 if (this->capacity() < RHSSize) {
826 this->destroy_range(this->begin(), this->end());
827 this->setEnd(this->begin());
830 }
else if (CurSize) {
832 std::move(RHS.begin(), RHS.begin()+CurSize, this->begin());
836 this->uninitialized_move(RHS.begin()+CurSize, RHS.end(),
837 this->begin()+CurSize);
840 this->setEnd(this->begin()+RHSSize);
850 template <
typename T,
unsigned N>
865 template <
typename T,
unsigned N>
875 this->assign(Size,
Value);
878 template<
typename ItTy>
931 template<
typename T,
unsigned N>
947 template<
typename T,
unsigned N>
960 size_t CurSizeBytes = size_in_bytes();
962 if (NewCapacityInBytes < MinSizeInBytes)
963 NewCapacityInBytes = MinSizeInBytes;
966 if (BeginX == FirstEl) {
967 NewElts = malloc(NewCapacityInBytes);
970 memcpy(NewElts, this->BeginX, CurSizeBytes);
973 NewElts = realloc(this->BeginX, NewCapacityInBytes);
975 assert(NewElts &&
"Out of memory");
977 this->EndX = (
char*)NewElts+CurSizeBytes;
978 this->BeginX = NewElts;
979 this->CapacityX = (
char*)this->BeginX + NewCapacityInBytes;
void grow_pod(void *FirstEl, size_t MinSizeInBytes, size_t TSize)
SmallVectorTemplateBase< T, IsPod< T >::value > SuperClass
const SmallVector & operator=(const SmallVector &RHS)
void resize(size_type N, const T &NV)
pointer data()
Return a pointer to the vector's buffer, even if empty().
LLVM_VECSMALL_NODISCARD bool empty() const
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
void set_size(size_type N)
SuperClass::size_type size_type
ptrdiff_t difference_type
const SmallVector & operator=(std::initializer_list< T > IL)
static void uninitialized_copy(T1 *I, T1 *E, T2 *Dest, typename std::enable_if< std::is_same< typename std::remove_const< T1 >::type, T2 >::value >::type *=nullptr)
void swap(SmallVectorImpl &RHS)
span_CONFIG_SIZE_TYPE size_t
size_t capacity() const
Return the total number of elements in the currently allocated buffer.
size_t capacity_in_bytes() const
capacity_in_bytes - This returns capacity()*sizeof(T).
static void uninitialized_move(It1 I, It1 E, It2 Dest)
static void uninitialized_copy(It1 I, It1 E, It2 Dest)
SmallVector(std::initializer_list< T > IL)
SmallVectorStorage< T, N > Storage
Inline space for elements which aren't stored in the base class.
void reserve(size_type N)
iterator erase(const_iterator CS, const_iterator CE)
LLVM_VECSMALL_ATTRIBUTE_ALWAYS_INLINE const_iterator end() const
size_t size_in_bytes() const
This returns size()*sizeof(T).
void grow(size_t MinSize=0)
LLVM_VECSMALL_ATTRIBUTE_ALWAYS_INLINE reference operator[](size_type idx)
#define LLVM_VECSMALL_NODISCARD
void reserve(T &, std::size_t)
uint64_t NextPowerOf2(uint64_t A)
SmallVectorTemplateBase(size_t Size)
void emplace_back(ArgTypes &&... Args)
SmallVector(size_t Size, const T &Value=T())
SmallVectorBase(void *FirstEl, size_t Size)
FMT_CONSTEXPR auto fill_n(OutputIt out, Size count, const T &value) -> OutputIt
std::reverse_iterator< const_iterator > const_reverse_iterator
static void uninitialized_move(It1 I, It1 E, It2 Dest)
SmallVectorTemplateBase(size_t Size)
const_reference front() const
bool operator==(const SmallVectorImpl &RHS) const
SmallVectorImpl & operator=(const SmallVectorImpl &RHS)
LLVM_VECSMALL_ATTRIBUTE_ALWAYS_INLINE iterator begin()
void grow_pod(size_t MinSizeInBytes, size_t TSize)
A ROSMessage will contain one or more ROSField(s). Each field is little more than a name / type pair...
OutputIterator copy(const RangeT &range, OutputIterator out)
const_reverse_iterator rend() const
SuperClass::const_iterator const_iterator
bool operator!=(const SmallVectorImpl &RHS) const
void assign(size_type NumElts, const T &Elt)
#define assert(condition)
void insert(iterator I, std::initializer_list< T > IL)
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
void assign(std::initializer_list< T > IL)
void append(size_type NumInputs, const T &Elt)
Add the specified range to the end of the SmallVector.
const SmallVector & operator=(SmallVectorImpl< T > &&RHS)
static void uninitialized_copy(It1 I, It1 E, It2 Dest)
SmallVectorImpl(unsigned N)
This is all the non-templated stuff common to all SmallVectors.
std::reverse_iterator< iterator > reverse_iterator
iterator insert(iterator I, ItTy From, ItTy To)
LLVM_VECSMALL_NODISCARD T pop_back_val()
SmallVector(SmallVector &&RHS)
const SmallVector & operator=(SmallVector &&RHS)
LLVM_VECSMALL_ATTRIBUTE_ALWAYS_INLINE const_iterator begin() const
void resetToSmall()
Put this vector in a state of being small.
reverse_iterator rbegin()
SmallVectorTemplateCommon(size_t Size)
void grow(size_t MinSize=0)
size_type max_size() const
iterator erase(const_iterator CI)
const T & move(const T &v)
iterator insert(iterator I, size_type NumToInsert, const T &Elt)
SmallVector(SmallVectorImpl< T > &&RHS)
iterator insert(iterator I, T &&Elt)
SmallVector(ItTy S, ItTy E)
iterator insert(iterator I, const T &Elt)
SmallVector(const SmallVector &RHS)
const_iterator capacity_ptr() const
LLVM_VECSMALL_ATTRIBUTE_ALWAYS_INLINE const_reference operator[](size_type idx) const
static void destroy_range(T *S, T *E)
LLVM_VECSMALL_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void append(std::initializer_list< T > IL)
const_reference back() const
const T & const_reference
span_constexpr std::size_t size(span< T, Extent > const &spn)
void clear(lua_State *L, int table_index)
static size_t capacity_in_bytes(const SmallVector< T, N > &X)
LLVM_VECSMALL_ATTRIBUTE_ALWAYS_INLINE iterator end()
void push_back(const T &Elt)
void push_back(const T &Elt)
SuperClass::iterator iterator
const_pointer data() const
Return a pointer to the vector's buffer, even if empty().
bool operator<(const SmallVectorImpl &RHS) const
std::aligned_union< 1, T >::type U
void swap(llvm_vecsmall::SmallVector< T, N > &LHS, llvm_vecsmall::SmallVector< T, N > &RHS)
Implement std::swap in terms of SmallVector swap.
#define LLVM_VECSMALL_UNLIKELY(x)
const_reverse_iterator rbegin() const
#define LLVM_VECSMALL_ATTRIBUTE_ALWAYS_INLINE
QCXXHighlighter::QCXXHighlighter(QTextDocument *document) m_highlightRule append)({ QRegularExpression(R"(#[a-zA-Z_]+)"), "Preprocessor" })
static void destroy_range(T *, T *)