Welcome to mirror list, hosted at ThFree Co, Russian Federation.

set_operations.hpp « base - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ed4a430fc927d119a6026c309b26929becc37ff4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once
#include "base.hpp"
#include "../std/algorithm.hpp"

// Similar to set_difference(), but if element is present n times in the first sequence and once in
// the second sequence, all n copies are filtered, insted of one.
template<typename Iter1T, typename Iter2T, typename OutIterT, typename LessT>
OutIterT SetDifferenceUnlimited(Iter1T beg1, Iter1T end1,
                                Iter2T beg2, Iter2T end2,
                                OutIterT out, LessT lessCompare)
  {
    while (beg1 != end1 && beg2 != end2)
    {
      if (lessCompare(*beg1, *beg2))
      {
        *out = *beg1;
        ++beg1;
        ++out;
      }
      else if (lessCompare(*beg2, *beg1))
      {
        ++beg2;
      }
      else
      {
        ++beg1;
        // This is the difference between set_difference and this function:
        // In set_difference the commented line should be present.
        // ++beg2;
      }
    }
    return copy(beg1, end1, out);
  }