diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2010-09-17 15:48:55 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2010-09-17 15:48:55 +0000 |
commit | d39c594d39df7f283c2fb8a704a3f31c501180d9 (patch) | |
tree | 36453626c792cccd91f783a38a169d610a6b9db9 /include/llvm/ADT/SmallVector.h | |
parent | 6144c1de6a7674dad94290650e4e14f24d42e421 (diff) |
Diffstat (limited to 'include/llvm/ADT/SmallVector.h')
-rw-r--r-- | include/llvm/ADT/SmallVector.h | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index fa61d207bd305..1d6181a95da36 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -206,7 +206,7 @@ template <typename T, bool isPodLike> void SmallVectorTemplateBase<T, isPodLike>::grow(size_t MinSize) { size_t CurCapacity = this->capacity(); size_t CurSize = this->size(); - size_t NewCapacity = 2*CurCapacity; + size_t NewCapacity = 2*CurCapacity + 1; // Always grow, even from zero. if (NewCapacity < MinSize) NewCapacity = MinSize; T *NewElts = static_cast<T*>(malloc(NewCapacity*sizeof(T))); @@ -707,6 +707,36 @@ public: }; +/// Specialize SmallVector at N=0. This specialization guarantees +/// that it can be instantiated at an incomplete T if none of its +/// members are required. +template <typename T> +class SmallVector<T,0> : public SmallVectorImpl<T> { +public: + SmallVector() : SmallVectorImpl<T>(0) {} + + explicit SmallVector(unsigned Size, const T &Value = T()) + : SmallVectorImpl<T>(0) { + this->reserve(Size); + while (Size--) + this->push_back(Value); + } + + template<typename ItTy> + SmallVector(ItTy S, ItTy E) : SmallVectorImpl<T>(0) { + this->append(S, E); + } + + SmallVector(const SmallVector &RHS) : SmallVectorImpl<T>(0) { + SmallVectorImpl<T>::operator=(RHS); + } + + SmallVector &operator=(const SmallVectorImpl<T> &RHS) { + return SmallVectorImpl<T>::operator=(RHS); + } + +}; + } // End llvm namespace namespace std { |