[llvm-commits] [llvm] r112106 - /llvm/trunk/include/llvm/ADT/SmallVector.h
John McCall
rjmccall at apple.com
Wed Aug 25 16:11:24 PDT 2010
Author: rjmccall
Date: Wed Aug 25 18:11:24 2010
New Revision: 112106
URL: http://llvm.org/viewvc/llvm-project?rev=112106&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/ADT/SmallVector.h
Modified: llvm/trunk/include/llvm/ADT/SmallVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=112106&r1=112105&r2=112106&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallVector.h Wed Aug 25 18:11:24 2010
@@ -707,6 +707,39 @@
};
+/// 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) {
+ if (!RHS.empty())
+ SmallVectorImpl<T>::operator=(RHS);
+ }
+
+ const SmallVector &operator=(const SmallVector &RHS) {
+ SmallVectorImpl<T>::operator=(RHS);
+ return *this;
+ }
+
+};
+
} // End llvm namespace
namespace std {
More information about the llvm-commits
mailing list