Skip to content

Commit

Permalink
fixes potential conflict with some windows macro redefinitions of min…
Browse files Browse the repository at this point in the history
… and max in the validators.
  • Loading branch information
phlptp committed Sep 23, 2021
1 parent c1e2ab4 commit 1d08fff
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions include/CLI/Validators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
Range(T min, T max, const std::string &validator_name = std::string{}) : Validator(validator_name) {
Range(T minVal, T maxVal, const std::string &validator_name = std::string{}) : Validator(validator_name) {
if(validator_name.empty()) {
std::stringstream out;
out << detail::type_name<T>() << " in [" << min << " - " << max << "]";
out << detail::type_name<T>() << " in [" << minVal << " - " << maxVal << "]";
description(out.str());
}

func_ = [min, max](std::string &input) {
func_ = [minVal, maxVal](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 < minVal || val > maxVal))
return std::string("Value ") + input + " not in range " + std::to_string(minVal) + " to " +
std::to_string(maxVal);

return std::string();
return std::string{};
};
}

/// Range of one value is 0 to value
template <typename T>
explicit Range(T max, const std::string &validator_name = std::string{})
: Range(static_cast<T>(0), max, validator_name) {}
explicit Range(T maxVal, const std::string &validator_name = std::string{})
: Range(static_cast<T>(0), maxVal, validator_name) {}
};

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

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

/// Produce a bounded range (factory). Min and max are inclusive.
class Bound : public Validator {
Expand All @@ -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 <typename T> Bound(T min, T max) {
template <typename T> Bound(T minVal, T maxVal) {
std::stringstream out;
out << detail::type_name<T>() << " bounded to [" << min << " - " << max << "]";
out << detail::type_name<T>() << " bounded to [" << minVal << " - " << maxVal << "]";
description(out.str());

func_ = [min, max](std::string &input) {
func_ = [minVal, maxVal](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 < minVal)
input = detail::to_string(minVal);
else if(val > maxVal)
input = detail::to_string(maxVal);

return std::string{};
};
}

/// Range of one value is 0 to value
template <typename T> explicit Bound(T max) : Bound(static_cast<T>(0), max) {}
template <typename T> explicit Bound(T maxVal) : Bound(static_cast<T>(0), maxVal) {}
};

namespace detail {
Expand Down

0 comments on commit 1d08fff

Please sign in to comment.