From e7bc9f0c6b6dfc40eaa7817b812ab38d3017c440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Thu, 4 Jun 2015 11:43:47 +0200 Subject: [PATCH] Use move-aware unique algorithm --- test/string_test.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/test/string_test.cpp b/test/string_test.cpp index 601e815..098c5f3 100644 --- a/test/string_test.cpp +++ b/test/string_test.cpp @@ -73,6 +73,32 @@ bool CheckEqualStringVector(StrVector1 *strvect1, StrVector2 *strvect2) strvect2->begin(), comp); } +template +ForwardIt unique(ForwardIt first, ForwardIt const last) +{ + if(first == last){ + ForwardIt i = first; + //Find first adjacent pair + while(1){ + if(++i == last){ + return last; + } + else if(*first == *i){ + break; + } + ++first; + } + //Now overwrite skipping adjacent elements + while (++i != last) { + if (!(*first == *i)) { + *(++first) = boost::move(*i); + } + } + ++first; + } + return first; +} + template struct string_literals; @@ -323,9 +349,9 @@ int string_test() if(!CheckEqualStringVector(boostStringVect, stdStringVect)) return 1; - boostStringVect->erase(std::unique(boostStringVect->begin(), boostStringVect->end()), + boostStringVect->erase((unique)(boostStringVect->begin(), boostStringVect->end()), boostStringVect->end()); - stdStringVect->erase(std::unique(stdStringVect->begin(), stdStringVect->end()), + stdStringVect->erase((unique)(stdStringVect->begin(), stdStringVect->end()), stdStringVect->end()); if(!CheckEqualStringVector(boostStringVect, stdStringVect)) return 1;