Skip to content

Commit 61556cf

Browse files
committed
Guard std::min calls against windows.h inclusion
1 parent 3c76dc6 commit 61556cf

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

include/gfx/timsort.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ template <typename RandomAccessIterator, typename Compare> class TimSort {
522522

523523
epilogue: // merge what is left from either cursor1 or cursor2
524524

525-
minGallop_ = std::min(minGallop, 1);
525+
minGallop_ = (std::min)(minGallop, 1);
526526

527527
if (len1 == 1) {
528528
GFX_TIMSORT_ASSERT(len2 > 0);
@@ -640,7 +640,7 @@ template <typename RandomAccessIterator, typename Compare> class TimSort {
640640

641641
epilogue: // merge what is left from either cursor1 or cursor2
642642

643-
minGallop_ = std::min(minGallop, 1);
643+
minGallop_ = (std::min)(minGallop, 1);
644644

645645
if (len2 == 1) {
646646
GFX_TIMSORT_ASSERT(len1 > 0);
@@ -688,7 +688,7 @@ template <typename RandomAccessIterator, typename Compare> class TimSort {
688688
diff_t runLen = countRunAndMakeAscending(cur, hi, compare);
689689

690690
if (runLen < minRun) {
691-
diff_t const force = std::min(nRemaining, minRun);
691+
diff_t const force = (std::min)(nRemaining, minRun);
692692
binarySort(cur, cur + force, cur + runLen, compare);
693693
runLen = force;
694694
}

tests/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,21 @@ add_executable(cxx_11_tests
9494
configure_tests(cxx_11_tests)
9595
target_compile_features(cxx_11_tests PRIVATE cxx_std_11)
9696

97+
# Windows-specific tests
98+
if (WIN32)
99+
add_executable(windows_tests
100+
main.cpp
101+
windows.cpp
102+
)
103+
configure_tests(windows_tests)
104+
target_compile_features(windows_tests PRIVATE cxx_std_98)
105+
endif()
106+
97107
include(CTest)
98108
include(ParseAndAddCatchTests)
99109

100110
ParseAndAddCatchTests(cxx_98_tests)
101111
ParseAndAddCatchTests(cxx_11_tests)
112+
if (WIN32)
113+
ParseAndAddCatchTests(windows_tests)
114+
endif()

tests/windows.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2011 Fuji, Goro (gfx) <[email protected]>.
3+
* Copyright (c) 2019 Morwenn.
4+
*
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
#include <algorithm>
8+
#include <deque>
9+
#include <stdexcept>
10+
#include <utility>
11+
#include <vector>
12+
#include <catch.hpp>
13+
#include <windows.h>
14+
#include <gfx/timsort.hpp>
15+
16+
TEST_CASE( "check inclusion of windows.h" ) {
17+
const int size = 100;
18+
19+
std::vector<int> vec;
20+
for (int i = 0; i < size; ++i) {
21+
vec.push_back(i);
22+
}
23+
24+
std::random_shuffle(vec.begin(), vec.end());
25+
gfx::timsort(vec.begin(), vec.end());
26+
27+
for (int i = 0; i < size; ++i) {
28+
CHECK(vec[i] == i);
29+
}
30+
}

0 commit comments

Comments
 (0)