From cde1231e06e14f5884fd8e00555e944ed2709008 Mon Sep 17 00:00:00 2001 From: T-640 <71297562+T-640@users.noreply.github.com> Date: Wed, 18 Oct 2023 08:48:57 +0400 Subject: [PATCH 1/2] Update svector.h Fixes clash with Windows "min" and "max" macros --- include/ankerl/svector.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/ankerl/svector.h b/include/ankerl/svector.h index 93ff91a..fa13009 100644 --- a/include/ankerl/svector.h +++ b/include/ankerl/svector.h @@ -134,7 +134,7 @@ class header { template struct storage : public header { static constexpr auto alignment_of_t = std::alignment_of_v; - static constexpr auto max_alignment = std::max(std::alignment_of_v
, std::alignment_of_v); + static constexpr auto max_alignment = (std::max)(std::alignment_of_v
, std::alignment_of_v); static constexpr auto offset_to_data = detail::round_up(sizeof(header), alignment_of_t); static_assert(max_alignment <= __STDCPP_DEFAULT_NEW_ALIGNMENT__); @@ -164,7 +164,7 @@ struct storage : public header { throw std::bad_alloc(); } mem += offset_to_data; - if (static_cast(mem) > static_cast(std::numeric_limits::max())) { + if (static_cast(mem) > static_cast((std::numeric_limits::max)())) { throw std::bad_alloc(); } @@ -317,7 +317,7 @@ class svector { // got an overflow, set capacity to max new_capacity = max_size(); } - return std::min(new_capacity, max_size()); + return (std::min)(new_capacity, max_size()); } template @@ -846,7 +846,7 @@ class svector { } [[nodiscard]] static auto max_size() -> size_t { - return std::numeric_limits::max(); + return (std::numeric_limits::max)(); } void swap(svector& other) { From 47d2f4255152fbcb546ace72133587e9cbd743c4 Mon Sep 17 00:00:00 2001 From: Martin Leitner-Ankerl Date: Mon, 27 Jul 2026 17:18:04 +0200 Subject: [PATCH 2/2] Cover the remaining min/max sites and restore space indentation Follow-up to the original fix: * erase() and the move helper still called std::min unparenthesized at lines 408, 469 and 472, so without NOMINMAX still failed to compile for anyone using erase()/insert(). Simulating the Windows min/max macros, main produced 9 errors and the original patch left 3; now it compiles clean. * The four touched lines used tabs, but .clang-format sets UseTab: Never, so the lint job rejected them. Converted to spaces. std::max(1, starting_capacity) at line 310 deliberately stays as is: an explicit template argument makes 'max' be followed by '<' rather than '(', so the function-like macro is never invoked. Co-Authored-By: Claude Opus 5 --- include/ankerl/svector.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/ankerl/svector.h b/include/ankerl/svector.h index fa13009..27ceb05 100644 --- a/include/ankerl/svector.h +++ b/include/ankerl/svector.h @@ -134,7 +134,7 @@ class header { template struct storage : public header { static constexpr auto alignment_of_t = std::alignment_of_v; - static constexpr auto max_alignment = (std::max)(std::alignment_of_v
, std::alignment_of_v); + static constexpr auto max_alignment = (std::max)(std::alignment_of_v
, std::alignment_of_v); static constexpr auto offset_to_data = detail::round_up(sizeof(header), alignment_of_t); static_assert(max_alignment <= __STDCPP_DEFAULT_NEW_ALIGNMENT__); @@ -164,7 +164,7 @@ struct storage : public header { throw std::bad_alloc(); } mem += offset_to_data; - if (static_cast(mem) > static_cast((std::numeric_limits::max)())) { + if (static_cast(mem) > static_cast((std::numeric_limits::max)())) { throw std::bad_alloc(); } @@ -317,7 +317,7 @@ class svector { // got an overflow, set capacity to max new_capacity = max_size(); } - return (std::min)(new_capacity, max_size()); + return (std::min)(new_capacity, max_size()); } template @@ -405,7 +405,7 @@ class svector { auto erase_checked_end(T const* cfrom, T const* to) -> T* { auto* const erase_begin = const_cast(cfrom); // NOLINT(cppcoreguidelines-pro-type-const-cast) auto* const container_end = data() + size(); - auto* const erase_end = std::min(const_cast(to), container_end); // NOLINT(cppcoreguidelines-pro-type-const-cast) + auto* const erase_end = (std::min)(const_cast(to), container_end); // NOLINT(cppcoreguidelines-pro-type-const-cast) std::move(erase_end, container_end, erase_begin); auto const num_erased = std::distance(erase_begin, erase_end); @@ -466,10 +466,10 @@ class svector { // 1. uninitialized moves auto const num_moves = std::distance(source_begin, source_end); auto const target_end = target_begin + num_moves; - auto const num_uninitialized_move = std::min(num_moves, std::distance(source_end, target_end)); + auto const num_uninitialized_move = (std::min)(num_moves, std::distance(source_end, target_end)); std::uninitialized_move(source_end - num_uninitialized_move, source_end, target_end - num_uninitialized_move); std::move_backward(source_begin, source_end - num_uninitialized_move, target_end - num_uninitialized_move); - std::destroy(source_begin, std::min(source_end, target_begin)); + std::destroy(source_begin, (std::min)(source_end, target_begin)); } template @@ -846,7 +846,7 @@ class svector { } [[nodiscard]] static auto max_size() -> size_t { - return (std::numeric_limits::max)(); + return (std::numeric_limits::max)(); } void swap(svector& other) {