From 0771c714d69ebed451c235d78453e7aa2f9d006a Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Wed, 6 Feb 2008 23:46:23 +0100 Subject: [PATCH] Use std::vector<>::back() to make the code more readable. --- src/game.cpp | 10 +++++----- src/imageeffects.cpp | 4 ++-- src/index.cpp | 4 ++-- src/movelist.cpp | 6 +++--- src/movelist_textual.cpp | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index ef55797..f0cb04f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -212,7 +212,7 @@ void Game::undo() { Entry* e = fetch(a->index.prev()); Q_ASSERT(e); - int v = a->index.nested[a->index.nested.size()-1].variation; + int v = a->index.nested.back().variation; Q_ASSERT(e->variations.count(v) == 1); Q_ASSERT(e->variations[v].size() == 1); @@ -342,7 +342,7 @@ void Game::redo() { Entry* e = fetch(a->index.prev()); Q_ASSERT(e); - int v = a->index.nested[a->index.nested.size()-1].variation; + int v = a->index.nested.back().variation; Q_ASSERT(e->variations.count(v) == 0); History h; @@ -492,7 +492,7 @@ void Game::promoteVariation(const Index& _ix) { return; } Index ix = _ix; - int v = ix.nested[ix.nested.size()-1].variation; + int v = ix.nested.back().variation; ix.nested.pop_back(); promoteVariation(ix, v); @@ -530,7 +530,7 @@ void Game::removeVariation(const Index& _ix) { return; } Index ix = _ix; - int v = ix.nested[ix.nested.size()-1].variation; + int v = ix.nested.back().variation; ix.nested.pop_back(); removeVariation(ix, v); @@ -882,7 +882,7 @@ void Game::load(PositionPtr pos, const PGN& pgn) { ERROR("Unexpected end variation!"); break; } - current = var_stack[var_stack.size()-1]; + current = var_stack.back(); var_stack.pop_back(); } else if(boost::get(pgn[i])) { diff --git a/src/imageeffects.cpp b/src/imageeffects.cpp index 5f541c7..0887cb3 100644 --- a/src/imageeffects.cpp +++ b/src/imageeffects.cpp @@ -243,7 +243,7 @@ void floodFill(QImage& image, QPoint point, QColor color, } while(!lines.empty()) { - Line ll = lines[lines.size()-1]; + Line ll = lines.back(); lines.pop_back(); if(ll.x1>0) { @@ -308,7 +308,7 @@ void floodFillBlueThreshold(QImage& image, QPoint point, QColor color, unsigned } while(!lines.empty()) { - Line ll = lines[lines.size()-1]; + Line ll = lines.back(); lines.pop_back(); if(ll.x1>0) { diff --git a/src/index.cpp b/src/index.cpp index b0ccf44..d1b2ea9 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -47,7 +47,7 @@ int Index::totalNumMoves() const { } bool Index::atVariationStart() const { - return nested.size() && (nested[nested.size()-1].num_moves == 0); + return nested.size() && (nested.back().num_moves == 0); } Index Index::flipVariation(const Index& vstart, int v_id) const { @@ -195,7 +195,7 @@ std::pair Index::stepsTo(const Index& ix) const { } int Index::lastIndex() { - return nested.size() ? nested[nested.size()-1].num_moves : num_moves; + return nested.size() ? nested.back().num_moves : num_moves; } bool Index::mainLine() const { diff --git a/src/movelist.cpp b/src/movelist.cpp index 3cca971..054ed92 100644 --- a/src/movelist.cpp +++ b/src/movelist.cpp @@ -1179,9 +1179,9 @@ void Widget::setMove(const Index& index, return; } - if(index.nested.size() && index.nested[index.nested.size()-1].num_moves == 0) { + if(index.nested.size() && index.nested.back().num_moves == 0) { History var; - int v = index.nested[index.nested.size()-1].variation; + int v = index.nested.back().variation; var.push_back(e = EntryPtr( new Entry(turn, move, index, this)) ); (*vec)[at]->variations[v] = var; (*vec)[at]->braces[v] = BracePtr( new Brace( (*vec)[at].get(), v, this) ); @@ -1201,7 +1201,7 @@ void Widget::remove(const Index& index) { if(!e) return; - int v = index.nested[index.nested.size()-1].variation; + int v = index.nested.back().variation; if(!e->variations.count(v)) return; diff --git a/src/movelist_textual.cpp b/src/movelist_textual.cpp index e0e2473..7c40c3c 100644 --- a/src/movelist_textual.cpp +++ b/src/movelist_textual.cpp @@ -288,7 +288,7 @@ void Textual::setMove(const Index& index, int turn, const DecoratedMove& move, } } else { - Index pi = index.prev(index.nested[index.nested.size()-1].num_moves); + Index pi = index.prev(index.nested.back().num_moves); parent = document.getElementById("vr_"+pi); if(parent.isNull()) { std::cout << " --> Error in Textual::setMove, no variation?!?!?" << std::endl; -- 2.11.4.GIT