From 2a022458dcd4ca3a03884d10f5085b35b1b1daad Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 23 Sep 2021 15:55:43 -0700 Subject: [PATCH] fixes potential conflict with some windows macro redefinitions of min and max in the validators. --- include/CLI/Validators.hpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/include/CLI/Validators.hpp b/include/CLI/Validators.hpp index e84586222..3c8b2f420 100644 --- a/include/CLI/Validators.hpp +++ b/include/CLI/Validators.hpp @@ -467,35 +467,35 @@ class Range : public Validator { /// Note that the constructor is templated, but the struct is not, so C++17 is not /// needed to provide nice syntax for Range(a,b). template - Range(T min, T max, const std::string &validator_name = std::string{}) : Validator(validator_name) { + Range(T min_val, T max_val, const std::string &validator_name = std::string{}) : Validator(validator_name) { if(validator_name.empty()) { std::stringstream out; - out << detail::type_name() << " in [" << min << " - " << max << "]"; + out << detail::type_name() << " in [" << min_val << " - " << max_val << "]"; description(out.str()); } - func_ = [min, max](std::string &input) { + func_ = [min_val, max_val](std::string &input) { T val; bool converted = detail::lexical_cast(input, val); - if((!converted) || (val < min || val > max)) - return std::string("Value ") + input + " not in range " + std::to_string(min) + " to " + - std::to_string(max); + if((!converted) || (val < min_val || val > max_val)) + return std::string("Value ") + input + " not in range " + std::to_string(min_val) + " to " + + std::to_string(max_val); - return std::string(); + return std::string{}; }; } /// Range of one value is 0 to value template - explicit Range(T max, const std::string &validator_name = std::string{}) - : Range(static_cast(0), max, validator_name) {} + explicit Range(T max_val, const std::string &validator_name = std::string{}) + : Range(static_cast(0), max_val, validator_name) {} }; /// Check for a non negative number -const Range NonNegativeNumber(std::numeric_limits::max(), "NONNEGATIVE"); +const Range NonNegativeNumber((std::numeric_limits::max)(), "NONNEGATIVE"); /// Check for a positive valued number (val>0.0), min() her is the smallest positive number -const Range PositiveNumber(std::numeric_limits::min(), std::numeric_limits::max(), "POSITIVE"); +const Range PositiveNumber((std::numeric_limits::min)(), (std::numeric_limits::max)(), "POSITIVE"); /// Produce a bounded range (factory). Min and max are inclusive. class Bound : public Validator { @@ -504,28 +504,28 @@ class Bound : public Validator { /// /// Note that the constructor is templated, but the struct is not, so C++17 is not /// needed to provide nice syntax for Range(a,b). - template Bound(T min, T max) { + template Bound(T min_val, T max_val) { std::stringstream out; - out << detail::type_name() << " bounded to [" << min << " - " << max << "]"; + out << detail::type_name() << " bounded to [" << min_val << " - " << max_val << "]"; description(out.str()); - func_ = [min, max](std::string &input) { + func_ = [min_val, max_val](std::string &input) { T val; bool converted = detail::lexical_cast(input, val); if(!converted) { return std::string("Value ") + input + " could not be converted"; } - if(val < min) - input = detail::to_string(min); - else if(val > max) - input = detail::to_string(max); + if(val < min_val) + input = detail::to_string(min_val); + else if(val > max_val) + input = detail::to_string(max_val); return std::string{}; }; } /// Range of one value is 0 to value - template explicit Bound(T max) : Bound(static_cast(0), max) {} + template explicit Bound(T max_val) : Bound(static_cast(0), max_val) {} }; namespace detail {