[LyX/master] Use ranges, fix warning

Richard Kimberly Heck rikiheck at lyx.org
Fri Feb 28 06:33:50 UTC 2020


commit 5baca8171f0cb29232d6ac8e91d29acbc403437a
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date:   Fri Feb 28 01:48:10 2020 -0500

    Use ranges, fix warning
---
 src/Counters.cpp |   46 ++++++++++++++++++----------------------------
 src/Counters.h   |    2 +-
 2 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/src/Counters.cpp b/src/Counters.cpp
index 2daac53..830a100 100644
--- a/src/Counters.cpp
+++ b/src/Counters.cpp
@@ -184,7 +184,7 @@ Counter::StringMap & Counter::flatLabelStrings(bool in_appendix) const
 
 Counters::Counters() : appendix_(false), subfloat_(false), longtable_(false)
 {
-	layout_stack_.push_back(0);
+	layout_stack_.push_back(nullptr);
 	counter_stack_.push_back(from_ascii(""));
 }
 
@@ -265,14 +265,12 @@ int Counters::value(docstring const & ctr) const
 }
 
 
-void Counters::resetSlaves(docstring const & ctr)
+void Counters::resetSlaves(docstring const & count)
 {
-	CounterList::iterator it = counterList_.begin();
-	CounterList::iterator const end = counterList_.end();
-	for (; it != end; ++it) {
-		if (it->second.master() == ctr) {
-			it->second.reset();
-			resetSlaves(it->first);
+	for (auto & ctr : counterList_) {
+		if (ctr.second.master() == count) {
+			ctr.second.reset();
+			resetSlaves(ctr.first);
 		}
 	}
 }
@@ -315,14 +313,12 @@ void Counters::reset()
 	appendix_ = false;
 	subfloat_ = false;
 	current_float_.erase();
-	CounterList::iterator it = counterList_.begin();
-	CounterList::iterator const end = counterList_.end();
-	for (; it != end; ++it)
-		it->second.reset();
+	for (auto & ctr : counterList_)
+		ctr.second.reset();
 	counter_stack_.clear();
 	counter_stack_.push_back(from_ascii(""));
 	layout_stack_.clear();
-	layout_stack_.push_back(0);
+	layout_stack_.push_back(nullptr);
 }
 
 
@@ -330,11 +326,9 @@ void Counters::reset(docstring const & match)
 {
 	LASSERT(!match.empty(), return);
 
-	CounterList::iterator it = counterList_.begin();
-	CounterList::iterator end = counterList_.end();
-	for (; it != end; ++it) {
-		if (it->first.find(match) != string::npos)
-			it->second.reset();
+	for (auto & ctr : counterList_) {
+		if (ctr.first.find(match) != string::npos)
+			ctr.second.reset();
 	}
 }
 
@@ -344,12 +338,10 @@ bool Counters::remove(docstring const & cnt)
 	bool retval = counterList_.erase(cnt);
 	if (!retval)
 		return false;
-	CounterList::iterator it = counterList_.begin();
-	CounterList::iterator end = counterList_.end();
-	for (; it != end; ++it) {
-		if (it->second.checkAndRemoveMaster(cnt))
+	for (auto & ctr : counterList_) {
+		if (ctr.second.checkAndRemoveMaster(cnt))
 			LYXERR(Debug::TCLASS, "Removed master counter `" +
-					to_utf8(cnt) + "' from counter: " + to_utf8(it->first));
+					to_utf8(cnt) + "' from counter: " + to_utf8(ctr.first));
 	}
 	return retval;
 }
@@ -357,11 +349,9 @@ bool Counters::remove(docstring const & cnt)
 
 void Counters::copy(Counters & from, Counters & to, docstring const & match)
 {
-	CounterList::iterator it = counterList_.begin();
-	CounterList::iterator end = counterList_.end();
-	for (; it != end; ++it) {
-		if (it->first.find(match) != string::npos || match == "") {
-			to.set(it->first, from.value(it->first));
+	for (auto const & ctr : counterList_) {
+		if (ctr.first.find(match) != string::npos || match == "") {
+			to.set(ctr.first, from.value(ctr.first));
 		}
 	}
 }
diff --git a/src/Counters.h b/src/Counters.h
index 536dcc1..89383bc 100644
--- a/src/Counters.h
+++ b/src/Counters.h
@@ -193,7 +193,7 @@ public:
 	/// Also for updateBuffer().
 	/// Call this when entering things like footnotes, where there is now
 	/// no "last layout" and we want to restore the "last layout" on exit.
-	void clearLastLayout() { layout_stack_.push_back(0); }
+	void clearLastLayout() { layout_stack_.push_back(nullptr); }
 	/// Call this when exiting things like footnotes.
 	void restoreLastLayout() { layout_stack_.pop_back(); }
 	///


More information about the lyx-cvs mailing list