diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-07-22 15:45:39 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-07-22 15:45:39 +0000 |
commit | 5c7e281d368601858f9f5e5fe11734eea10b9523 (patch) | |
tree | 09fef3b190c27eaa8bc0791a0a09e08501c07747 /test/SemaTemplate/example-dynarray.cpp | |
parent | 1360d4ad9045056d646c118344c7c5148aea4a52 (diff) |
Test template instantiation for member functions of class templates defined
out of line.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76740 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaTemplate/example-dynarray.cpp')
-rw-r--r-- | test/SemaTemplate/example-dynarray.cpp | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/test/SemaTemplate/example-dynarray.cpp b/test/SemaTemplate/example-dynarray.cpp index 680ee04ba1..7dcc508d2c 100644 --- a/test/SemaTemplate/example-dynarray.cpp +++ b/test/SemaTemplate/example-dynarray.cpp @@ -43,30 +43,8 @@ public: unsigned size() const { return Last - Start; } unsigned capacity() const { return End - Start; } - void push_back(const T& value) { - if (Last == End) { - unsigned NewCapacity = capacity() * 2; - if (NewCapacity == 0) - NewCapacity = 4; - - T* NewStart = (T*)malloc(sizeof(T) * NewCapacity); - - unsigned Size = size(); - for (unsigned I = 0; I != Size; ++I) - new (NewStart + I) T(Start[I]); - - // FIXME: destruct old values - free(Start); - - Start = NewStart; - Last = Start + Size; - End = Start + NewCapacity; - } - - new (Last) T(value); - ++Last; - } - + void push_back(const T& value); + void pop_back() { // FIXME: destruct old value --Last; @@ -108,6 +86,31 @@ public: T* Start, *Last, *End; }; +template<typename T> +void dynarray<T>::push_back(const T& value) { + if (Last == End) { + unsigned NewCapacity = capacity() * 2; + if (NewCapacity == 0) + NewCapacity = 4; + + T* NewStart = (T*)malloc(sizeof(T) * NewCapacity); + + unsigned Size = size(); + for (unsigned I = 0; I != Size; ++I) + new (NewStart + I) T(Start[I]); + + // FIXME: destruct old values + free(Start); + + Start = NewStart; + Last = Start + Size; + End = Start + NewCapacity; + } + + new (Last) T(value); + ++Last; +} + struct Point { Point() { x = y = z = 0.0; } Point(const Point& other) : x(other.x), y(other.y), z(other.z) { } |