From 5b5f7260a0f0da9a2057245fd42a6b196ccec33d Mon Sep 17 00:00:00 2001 From: John McCall Date: Wed, 25 Aug 2010 23:11:24 +0000 Subject: [PATCH] Provide an explicit specialization of SmallVector at N=0 which does not require its type argument to be complete if no members are actually used. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112106 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/SmallVector.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index fa61d207bd3..3be1787bc39 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -707,6 +707,39 @@ 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 +class SmallVector : public SmallVectorImpl { +public: + SmallVector() : SmallVectorImpl(0) { + } + + explicit SmallVector(unsigned Size, const T &Value = T()) + : SmallVectorImpl(0) { + this->reserve(Size); + while (Size--) + this->push_back(Value); + } + + template + SmallVector(ItTy S, ItTy E) : SmallVectorImpl(0) { + this->append(S, E); + } + + SmallVector(const SmallVector &RHS) : SmallVectorImpl(0) { + if (!RHS.empty()) + SmallVectorImpl::operator=(RHS); + } + + const SmallVector &operator=(const SmallVector &RHS) { + SmallVectorImpl::operator=(RHS); + return *this; + } + +}; + } // End llvm namespace namespace std { -- 2.34.1