diff --git a/paddle/fluid/framework/mixed_vector.h b/paddle/fluid/framework/mixed_vector.h index a06e34d55115648bc387200bb0cbde54c626d817..6e5ceefadd7c35d743df454909beaef37d9343d5 100644 --- a/paddle/fluid/framework/mixed_vector.h +++ b/paddle/fluid/framework/mixed_vector.h @@ -106,9 +106,11 @@ class Vector { // std::vector iterator methods. Based on CPU data access method size_t size() const { return size_; } - T* begin() { return size() == 0 ? &EmptyDummy() : &this->operator[](0); } + T* begin() { return capacity() == 0 ? &EmptyDummy() : &this->operator[](0); } - T* end() { return size() == 0 ? &EmptyDummy() : &this->operator[](size()); } + T* end() { + return capacity() == 0 ? &EmptyDummy() : &this->operator[](size()); + } T& front() { return *begin(); } @@ -119,11 +121,11 @@ class Vector { } const T* begin() const { - return size() == 0 ? &EmptyDummy() : &this->operator[](0); + return capacity() == 0 ? &EmptyDummy() : &this->operator[](0); } const T* end() const { - return size() == 0 ? &EmptyDummy() : &this->operator[](size()); + return capacity() == 0 ? &EmptyDummy() : &this->operator[](size()); } const T* cbegin() const { return begin(); }