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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
#pragma once
#ifdef new
#undef new
#endif
#include <algorithm>
using std::all_of;
using std::binary_search;
using std::copy;
using std::equal;
using std::equal_range;
using std::fill;
using std::find;
using std::find_first_of;
using std::find_if;
using std::for_each;
using std::is_sorted;
using std::lexicographical_compare;
using std::lower_bound;
using std::max;
using std::max_element;
using std::min;
using std::next_permutation;
using std::nth_element;
using std::partial_sort;
using std::remove_if;
using std::replace;
using std::reverse;
using std::set_intersection;
using std::set_union;
using std::sort;
using std::stable_partition;
using std::stable_sort;
using std::swap;
using std::unique;
using std::upper_bound;
// Bug workaround, see http://connect.microsoft.com/VisualStudio/feedbackdetail/view/840578/algorithm-possible-c-compiler-bug-when-using-std-set-difference-with-custom-comperator
#ifdef _MSC_VER
namespace vs_bug
{
template<class InputIt1, class InputIt2, class OutputIt, class Compare>
OutputIt set_difference( InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first, Compare comp)
{
while (first1 != last1)
{
if (first2 == last2)
return std::copy(first1, last1, d_first);
if (comp(*first1, *first2))
*d_first++ = *first1++;
else
{
if (!comp(*first2, *first1))
++first1;
++first2;
}
}
return d_first;
}
template<class InputIt1, class InputIt2, class OutputIt>
OutputIt set_difference(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first)
{
while (first1 != last1)
{
if (first2 == last2)
return std::copy(first1, last1, d_first);
if (*first1 < *first2)
*d_first++ = *first1++;
else
{
if (! (*first2 < *first1))
++first1;
++first2;
}
}
return d_first;
}
} // namespace vc_bug
#else
using std::set_difference;
#endif
using std::distance;
using std::generate;
using std::pop_heap;
using std::push_heap;
using std::remove_copy_if;
using std::set_symmetric_difference;
using std::sort_heap;
using std::transform;
#ifdef DEBUG_NEW
#define new DEBUG_NEW
#endif
|