diff --git a/mutation_partition.cc b/mutation_partition.cc index 03ac188670..4486c5040a 100644 --- a/mutation_partition.cc +++ b/mutation_partition.cc @@ -834,6 +834,23 @@ void row::reserve(column_id last_column) } } +template +auto row::with_both_ranges(const row& other, Func&& func) const { + if (_type == storage_type::vector) { + if (other._type == storage_type::vector) { + return func(get_range_vector(), other.get_range_vector()); + } else { + return func(get_range_vector(), other.get_range_set()); + } + } else { + if (other._type == storage_type::vector) { + return func(get_range_set(), other.get_range_vector()); + } else { + return func(get_range_set(), other.get_range_set()); + } + } +} + bool row::operator==(const row& other) const { if (size() != other.size()) { return false; @@ -842,19 +859,9 @@ bool row::operator==(const row& other) const { auto cells_equal = [] (std::pair c1, std::pair c2) { return c1.first == c2.first && c1.second == c2.second; }; - if (_type == storage_type::vector) { - if (other._type == storage_type::vector) { - return boost::equal(get_range_vector(), other.get_range_vector(), cells_equal); - } else { - return boost::equal(get_range_vector(), other.get_range_set(), cells_equal); - } - } else { - if (other._type == storage_type::vector) { - return boost::equal(get_range_set(), other.get_range_vector(), cells_equal); - } else { - return boost::equal(get_range_set(), other.get_range_set(), cells_equal); - } - } + return with_both_ranges(other, [&] (auto r1, auto r2) { + return boost::equal(r1, r2, cells_equal); + }); } row::row() { diff --git a/mutation_partition.hh b/mutation_partition.hh index 71b69f02c7..68b16d6f10 100644 --- a/mutation_partition.hh +++ b/mutation_partition.hh @@ -156,6 +156,8 @@ private: return std::pair(c.id(), c.cell()); }); } + template + auto with_both_ranges(const row& other, Func&& func) const; void vector_to_set(); public: