diff options
author | Alex Zolotarev <alex@maps.me> | 2014-10-14 13:14:55 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:30:57 +0300 |
commit | 0ddcff0b07566260e1e00990f70555110fb5cfa7 (patch) | |
tree | 32d542f1b9d9f6dcdc4e800b4ac5b3d6ee62b2c8 /std/algorithm.hpp | |
parent | 9ad4f6585c45443815b7ab9a691a7c47eefe6012 (diff) |
[msvc][win] Fixed compilation issues
Diffstat (limited to 'std/algorithm.hpp')
-rw-r--r-- | std/algorithm.hpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/std/algorithm.hpp b/std/algorithm.hpp index 986607a72d..761271018b 100644 --- a/std/algorithm.hpp +++ b/std/algorithm.hpp @@ -31,7 +31,53 @@ using std::replace; using std::reverse; using std::set_union; using std::set_intersection; +// 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::set_symmetric_difference; using std::transform; using std::push_heap; |