From: Mikko Rasa Date: Fri, 17 Aug 2018 15:49:27 +0000 (+0300) Subject: Remove duplicates when merging choice conditions X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3169efbcaa882c427d9cc1bbb6dbd187efe98f45;p=poefilter.git Remove duplicates when merging choice conditions --- diff --git a/source/choicecondition.h b/source/choicecondition.h index 91b5e71..c2f7f0e 100644 --- a/source/choicecondition.h +++ b/source/choicecondition.h @@ -1,6 +1,7 @@ #ifndef CHOICECONDITION_H_ #define CHOICECONDITION_H_ +#include #include "condition.h" #include "filter.h" @@ -71,14 +72,13 @@ ChoiceCondition *ChoiceCondition::merge(const std::vector &co { if(dynamic_cast(&parent) && !conditions.empty()) { - ChoiceCondition *result = 0; + ChoiceCondition *result = new ChoiceCondition(std::vector()); for(std::vector::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) { const std::vector &v = static_cast *>(*i)->values; - if(!result) - result = new ChoiceCondition(v); - else - result->values.insert(result->values.end(), v.begin(), v.end()); + for(typename std::vector::const_iterator j=v.begin(); j!=v.end(); ++j) + if(Msp::find(result->values, *j)==result->values.end()) + result->values.push_back(*j); } return result; }