From 91f090f5a34128470158d7c370b0cc8a3f94bf0f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20K=C4=99dzia?= <Pawel.Kedzia@pwr.wroc.pl>
Date: Tue, 3 Jan 2012 12:38:02 +0100
Subject: [PATCH] Last fix in next_document (I hope!)

---
 libcorpus2_whole/corpus.h | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/libcorpus2_whole/corpus.h b/libcorpus2_whole/corpus.h
index b4ca6e8..225018c 100644
--- a/libcorpus2_whole/corpus.h
+++ b/libcorpus2_whole/corpus.h
@@ -50,23 +50,22 @@ public:
 
 	/// Next document in corpus
 	boost::shared_ptr<Document> next_document() {
-		boost::shared_ptr<Document> _empty_doc_ptr;
+		static boost::shared_ptr<Document> _empty_doc_ptr;
 		if (!this->set_) {
 			if (this->documents_.size() == 0) {
 				return _empty_doc_ptr;
 			}
-
 			this->set_ = true;
 			this->current_document_ = documents_.begin();
 		}
 		else {
-			if (current_document_ == documents_.end()) {
-				return _empty_doc_ptr;
-			}
-
 			current_document_++;
 		}
 
+		if (current_document_ == documents_.end()) {
+			return _empty_doc_ptr;
+		}
+
 		return *current_document_;
 	}
 
-- 
GitLab