Use std::prev and std::next where applicable

This commit is contained in:
Thomas Goyne 2012-11-28 20:36:03 -08:00
parent 174a992974
commit 0b19908e7b
5 changed files with 13 additions and 21 deletions

View file

@ -85,9 +85,7 @@ std::string const& MRUManager::GetEntry(std::string const& key, const size_t ent
if (entry >= map->size()) if (entry >= map->size())
throw MRUErrorIndexOutOfRange("Requested element index is out of range."); throw MRUErrorIndexOutOfRange("Requested element index is out of range.");
MRUListMap::const_iterator index = map->begin(); return *next(map->begin(), entry);
advance(index, entry);
return *index;
} }
void MRUManager::Flush() { void MRUManager::Flush() {

View file

@ -610,8 +610,7 @@ static void duplicate_lines(agi::Context *c, bool shift) {
// And the last line in this contiguous selection // And the last line in this contiguous selection
entryIter insert_pos = find_if_not(start, end, sel); entryIter insert_pos = find_if_not(start, end, sel);
entryIter last = insert_pos; entryIter last = std::prev(insert_pos);
--last;
// Duplicate each of the selected lines, inserting them in a block // Duplicate each of the selected lines, inserting them in a block
// after the selected block // after the selected block

View file

@ -164,10 +164,8 @@ void Spline::DecodeFromAss(wxString str) {
} }
void Spline::MovePoint(iterator curve,int point,Vector2D pos) { void Spline::MovePoint(iterator curve,int point,Vector2D pos) {
iterator prev = curve; iterator prev = std::prev(curve, curve != begin());
if (curve != begin()) --prev; iterator next = std::next(curve);
iterator next = curve;
++next;
if (next != end() && next->type == SplineCurve::POINT) if (next != end() && next->type == SplineCurve::POINT)
next = end(); next = end();
@ -279,14 +277,12 @@ void Spline::Smooth(float smooth) {
if (size() < 3) return; if (size() < 3) return;
// Smooth curve // Smooth curve
iterator cur_curve = end(); for (iterator cur = begin(); cur != end(); ++cur) {
--cur_curve; iterator prev_curve = prev(cur == begin() ? cur : end());
for (iterator cur = begin(); cur != end(); ) { iterator next_curve = next(cur);
iterator prev_curve = cur_curve; if (next_curve == end())
cur_curve = cur; next_curve = begin();
++cur;
iterator next_curve = cur == end() ? begin() : cur;
cur_curve->Smooth(prev_curve->p1, next_curve->EndPoint(), smooth); cur->Smooth(prev_curve->p1, next_curve->EndPoint(), smooth);
} }
} }

View file

@ -235,7 +235,7 @@ void VisualToolDrag::MakeFeatures(AssDialogue *diag, feature_iterator pos) {
feat.line = diag; feat.line = diag;
feat.parent = features.end(); feat.parent = features.end();
features.insert(pos, feat); features.insert(pos, feat);
feature_iterator cur = pos; --cur; feature_iterator cur = prev(pos);
feat.parent = cur; feat.parent = cur;
if (selection.count(diag)) if (selection.count(diag))
sel_features.insert(cur); sel_features.insert(cur);
@ -252,7 +252,7 @@ void VisualToolDrag::MakeFeatures(AssDialogue *diag, feature_iterator pos) {
feat.time = t2; feat.time = t2;
feat.line = diag; feat.line = diag;
features.insert(pos, feat); features.insert(pos, feat);
feat.parent->parent = --pos; ++pos; feat.parent->parent = prev(pos);
} }
// Create org feature // Create org feature

View file

@ -223,8 +223,7 @@ bool VisualToolVectorClip::InitializeDrag(feature_iterator feature) {
feature->curve->p2 = feature->curve->p4; feature->curve->p2 = feature->curve->p4;
} }
else { else {
Spline::iterator next = feature->curve; Spline::iterator next = std::next(feature->curve);
next++;
if (next != spline.end()) { if (next != spline.end()) {
if (feature->curve->type == SplineCurve::POINT) { if (feature->curve->type == SplineCurve::POINT) {
next->p1 = next->EndPoint(); next->p1 = next->EndPoint();