From 28828ff448ed038a96bb8a8a7981ed8bbd2f7fac Mon Sep 17 00:00:00 2001 From: q66 Date: Wed, 27 May 2015 00:49:35 +0100 Subject: [PATCH] fix swap_ranges api to correctly handle differently sized ranges --- octa/algorithm.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/octa/algorithm.h b/octa/algorithm.h index 3d58c07..15614a6 100644 --- a/octa/algorithm.h +++ b/octa/algorithm.h @@ -366,12 +366,13 @@ namespace octa { } template - R2 swap_ranges(R1 range1, R2 range2) { - for (; !range1.empty(); range1.pop_first()) { + Pair swap_ranges(R1 range1, R2 range2) { + while (!range1.empty() && !range2.empty()) { swap(range1.first(), range2.first()); + range1.pop_first(); range2.pop_first(); } - return range2; + return Pair(range1, range2); } template