OSDN Git Service

Revert "make QStack::pop() call QVector::last()"
authorIvailo Monev <xakepa10@laimg.moc>
Mon, 7 Nov 2016 12:32:40 +0000 (12:32 +0000)
committerIvailo Monev <xakepa10@laimg.moc>
Mon, 7 Nov 2016 12:32:40 +0000 (12:32 +0000)
This reverts commit 26ab0edab03d2699f2b238f97dad08b81fba22b7.

src/core/tools/qstack.h

index a924b1b..0bcce80 100644 (file)
@@ -57,9 +57,9 @@ public:
     inline ~QStack() {}
     inline void swap(QStack<T> &other) { QVector<T>::swap(other); } // prevent QVector<->QStack swaps
     inline void push(const T &t) { QVector<T>::append(t); }
-    inline T pop();
-    inline T &top() { return QVector<T>::last(); }; // for compatibility
-    const T &top() const { return QVector<T>::last(); }; // for compatibility
+    T pop();
+    T &top();
+    const T &top() const;
 };
 
 template<class T>
@@ -67,6 +67,14 @@ inline T QStack<T>::pop()
 { Q_ASSERT(!this->isEmpty()); T t = this->data()[this->size() -1];
   this->resize(this->size()-1); return t; }
 
+template<class T>
+inline T &QStack<T>::top()
+{ Q_ASSERT(!this->isEmpty()); this->detach(); return this->data()[this->size()-1]; }
+
+template<class T>
+inline const T &QStack<T>::top() const
+{ Q_ASSERT(!this->isEmpty()); return this->data()[this->size()-1]; }
+
 QT_END_NAMESPACE
 
 QT_END_HEADER