diff --git a/libcorpus2_whole/corpus.h b/libcorpus2_whole/corpus.h index d00a3261a0cee22e66f433614d94420ce1005a78..85c5caf294220456a968a204a328a405f279eb40 100644 --- a/libcorpus2_whole/corpus.h +++ b/libcorpus2_whole/corpus.h @@ -50,17 +50,20 @@ public: /// Next document in corpus boost::shared_ptr<Document> next_document() { + static boost::shared_ptr<Document> _empty_doc_ptr; if (!this->set_) { if (this->documents_.size() == 0) { - boost::shared_ptr<Document> tmp; - return tmp; - } - else { - this->set_ = true; - this->current_document_ = documents_.begin(); + return _empty_doc_ptr; } + + this->set_ = true; + this->current_document_ = documents_.begin(); } else { + if (current_document_ == documents_.end()) { + return _empty_doc_ptr; + } + current_document_++; }