Skip to content

Commit 4101964

Browse files
authored
fixes potential conflict with some windows macro redefinitions of min and max in the validators. (#642)
1 parent c1e2ab4 commit 4101964

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

include/CLI/Validators.hpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -467,35 +467,35 @@ class Range : public Validator {
467467
/// Note that the constructor is templated, but the struct is not, so C++17 is not
468468
/// needed to provide nice syntax for Range(a,b).
469469
template <typename T>
470-
Range(T min, T max, const std::string &validator_name = std::string{}) : Validator(validator_name) {
470+
Range(T min_val, T max_val, const std::string &validator_name = std::string{}) : Validator(validator_name) {
471471
if(validator_name.empty()) {
472472
std::stringstream out;
473-
out << detail::type_name<T>() << " in [" << min << " - " << max << "]";
473+
out << detail::type_name<T>() << " in [" << min_val << " - " << max_val << "]";
474474
description(out.str());
475475
}
476476

477-
func_ = [min, max](std::string &input) {
477+
func_ = [min_val, max_val](std::string &input) {
478478
T val;
479479
bool converted = detail::lexical_cast(input, val);
480-
if((!converted) || (val < min || val > max))
481-
return std::string("Value ") + input + " not in range " + std::to_string(min) + " to " +
482-
std::to_string(max);
480+
if((!converted) || (val < min_val || val > max_val))
481+
return std::string("Value ") + input + " not in range " + std::to_string(min_val) + " to " +
482+
std::to_string(max_val);
483483

484-
return std::string();
484+
return std::string{};
485485
};
486486
}
487487

488488
/// Range of one value is 0 to value
489489
template <typename T>
490-
explicit Range(T max, const std::string &validator_name = std::string{})
491-
: Range(static_cast<T>(0), max, validator_name) {}
490+
explicit Range(T max_val, const std::string &validator_name = std::string{})
491+
: Range(static_cast<T>(0), max_val, validator_name) {}
492492
};
493493

494494
/// Check for a non negative number
495-
const Range NonNegativeNumber(std::numeric_limits<double>::max(), "NONNEGATIVE");
495+
const Range NonNegativeNumber((std::numeric_limits<double>::max)(), "NONNEGATIVE");
496496

497497
/// Check for a positive valued number (val>0.0), min() her is the smallest positive number
498-
const Range PositiveNumber(std::numeric_limits<double>::min(), std::numeric_limits<double>::max(), "POSITIVE");
498+
const Range PositiveNumber((std::numeric_limits<double>::min)(), (std::numeric_limits<double>::max)(), "POSITIVE");
499499

500500
/// Produce a bounded range (factory). Min and max are inclusive.
501501
class Bound : public Validator {
@@ -504,28 +504,28 @@ class Bound : public Validator {
504504
///
505505
/// Note that the constructor is templated, but the struct is not, so C++17 is not
506506
/// needed to provide nice syntax for Range(a,b).
507-
template <typename T> Bound(T min, T max) {
507+
template <typename T> Bound(T min_val, T max_val) {
508508
std::stringstream out;
509-
out << detail::type_name<T>() << " bounded to [" << min << " - " << max << "]";
509+
out << detail::type_name<T>() << " bounded to [" << min_val << " - " << max_val << "]";
510510
description(out.str());
511511

512-
func_ = [min, max](std::string &input) {
512+
func_ = [min_val, max_val](std::string &input) {
513513
T val;
514514
bool converted = detail::lexical_cast(input, val);
515515
if(!converted) {
516516
return std::string("Value ") + input + " could not be converted";
517517
}
518-
if(val < min)
519-
input = detail::to_string(min);
520-
else if(val > max)
521-
input = detail::to_string(max);
518+
if(val < min_val)
519+
input = detail::to_string(min_val);
520+
else if(val > max_val)
521+
input = detail::to_string(max_val);
522522

523523
return std::string{};
524524
};
525525
}
526526

527527
/// Range of one value is 0 to value
528-
template <typename T> explicit Bound(T max) : Bound(static_cast<T>(0), max) {}
528+
template <typename T> explicit Bound(T max_val) : Bound(static_cast<T>(0), max_val) {}
529529
};
530530

531531
namespace detail {

0 commit comments

Comments
 (0)