Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows specific fix for min max MACROS (Can be dropped into any project no additional external MACROS needed) #603

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions include/date/date.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ class year
CONSTCD11 explicit operator int() const NOEXCEPT;
CONSTCD11 bool ok() const NOEXCEPT;

static CONSTCD11 year min() NOEXCEPT { return year{-32767}; }
static CONSTCD11 year max() NOEXCEPT { return year{32767}; }
static CONSTCD11 year (min)() NOEXCEPT { return year{-32767}; }
static CONSTCD11 year (max)() NOEXCEPT { return year{32767}; }
};

CONSTCD11 bool operator==(const year& x, const year& y) NOEXCEPT;
Expand Down Expand Up @@ -1167,7 +1167,7 @@ struct no_overflow
static const std::intmax_t n2 = R2::num / gcd_n1_n2;
static const std::intmax_t d2 = R2::den / gcd_d1_d2;
#ifdef __cpp_constexpr
static const std::intmax_t max = std::numeric_limits<std::intmax_t>::max();
static const std::intmax_t max = (std::numeric_limits<std::intmax_t>::max)();
#else
static const std::intmax_t max = LLONG_MAX;
#endif
Expand Down Expand Up @@ -1631,7 +1631,7 @@ inline
bool
year::ok() const NOEXCEPT
{
return y_ != std::numeric_limits<short>::min();
return y_ != (std::numeric_limits<short>::min)();
}

CONSTCD11
Expand Down Expand Up @@ -6107,7 +6107,7 @@ read_signed(std::basic_istream<CharT, Traits>& is, unsigned m = 1, unsigned M =
{
if (c == '-' || c == '+')
(void)is.get();
auto x = static_cast<int>(read_unsigned(is, std::max(m, 1u), M));
auto x = static_cast<int>(read_unsigned(is, (std::max)(m, 1u), M));
if (!is.fail())
{
if (c == '-')
Expand Down Expand Up @@ -6328,20 +6328,20 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
auto modified = CharT{};
auto width = -1;

CONSTDATA int not_a_year = numeric_limits<short>::min();
CONSTDATA int not_a_year = (numeric_limits<short>::min)();
CONSTDATA int not_a_2digit_year = 100;
CONSTDATA int not_a_century = not_a_year / 100;
CONSTDATA int not_a_month = 0;
CONSTDATA int not_a_day = 0;
CONSTDATA int not_a_hour = numeric_limits<int>::min();
CONSTDATA int not_a_hour = (numeric_limits<int>::min)();
CONSTDATA int not_a_hour_12_value = 0;
CONSTDATA int not_a_minute = not_a_hour;
CONSTDATA Duration not_a_second = Duration::min();
CONSTDATA Duration not_a_second = (Duration::min)();
CONSTDATA int not_a_doy = -1;
CONSTDATA int not_a_weekday = 8;
CONSTDATA int not_a_week_num = 100;
CONSTDATA int not_a_ampm = -1;
CONSTDATA minutes not_a_offset = minutes::min();
CONSTDATA minutes not_a_offset = (minutes::min)();

int Y = not_a_year; // c, F, Y *
int y = not_a_2digit_year; // D, x, y *
Expand Down Expand Up @@ -7446,7 +7446,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
goto broken;
G = tG;
}
if (Y < static_cast<int>(year::min()) || Y > static_cast<int>(year::max()))
if (Y < static_cast<int>((year::min)()) || Y > static_cast<int>((year::max)()))
Y = not_a_year;
bool computed = false;
if (G != not_a_year && V != not_a_week_num && wd != not_a_weekday)
Expand Down
12 changes: 6 additions & 6 deletions include/date/islamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ class year
CONSTCD11 explicit operator int() const NOEXCEPT;
CONSTCD11 bool ok() const NOEXCEPT;

static CONSTCD11 year min() NOEXCEPT;
static CONSTCD11 year max() NOEXCEPT;
static CONSTCD11 year (min)() NOEXCEPT;
static CONSTCD11 year (max)() NOEXCEPT;
};

CONSTCD11 bool operator==(const year& x, const year& y) NOEXCEPT;
Expand Down Expand Up @@ -1079,17 +1079,17 @@ CONSTCD11 inline bool year::ok() const NOEXCEPT {return true;}
CONSTCD11
inline
year
year::min() NOEXCEPT
(year::min)() NOEXCEPT
{
return year{std::numeric_limits<short>::min()};
return year{(std::numeric_limits<short>::min)()};
}

CONSTCD11
inline
year
year::max() NOEXCEPT
(year::max)() NOEXCEPT
{
return year{std::numeric_limits<short>::max()};
return year{(std::numeric_limits<short>::max)()};
}

CONSTCD11
Expand Down
16 changes: 8 additions & 8 deletions include/date/iso_week.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ class year
CONSTCD11 explicit operator int() const NOEXCEPT;
CONSTCD11 bool ok() const NOEXCEPT;

static CONSTCD11 year min() NOEXCEPT;
static CONSTCD11 year max() NOEXCEPT;
static CONSTCD11 year (min)() NOEXCEPT;
static CONSTCD11 year (max)() NOEXCEPT;
};

CONSTCD11 bool operator==(const year& x, const year& y) NOEXCEPT;
Expand Down Expand Up @@ -600,12 +600,12 @@ inline year& year::operator+=(const years& y) NOEXCEPT {*this = *this + y; retur
inline year& year::operator-=(const years& y) NOEXCEPT {*this = *this - y; return *this;}

CONSTCD11 inline year::operator int() const NOEXCEPT {return y_;}
CONSTCD11 inline bool year::ok() const NOEXCEPT {return min() <= *this && *this <= max();}
CONSTCD11 inline bool year::ok() const NOEXCEPT {return (min)() <= *this && *this <= (max)();}

CONSTCD11
inline
year
year::min() NOEXCEPT
(year::min)() NOEXCEPT
{
using std::chrono::seconds;
using std::chrono::minutes;
Expand All @@ -614,14 +614,14 @@ year::min() NOEXCEPT
static_assert(sizeof(seconds)*CHAR_BIT >= 41, "seconds may overflow");
static_assert(sizeof(hours)*CHAR_BIT >= 30, "hours may overflow");
return sizeof(minutes)*CHAR_BIT < 34 ?
year{1970} + duration_cast<years>(minutes::min()) :
year{std::numeric_limits<short>::min()};
year{1970} + duration_cast<years>((minutes::min)()) :
year{(std::numeric_limits<short>::min)()};
}

CONSTCD11
inline
year
year::max() NOEXCEPT
(year::max)() NOEXCEPT
{
using std::chrono::seconds;
using std::chrono::minutes;
Expand All @@ -631,7 +631,7 @@ year::max() NOEXCEPT
static_assert(sizeof(hours)*CHAR_BIT >= 30, "hours may overflow");
return sizeof(minutes)*CHAR_BIT < 34 ?
year{1969} + duration_cast<years>(minutes::max()) :
year{std::numeric_limits<short>::max()};
year{(std::numeric_limits<short>::max)()};
}

CONSTCD11
Expand Down
12 changes: 6 additions & 6 deletions include/date/julian.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ class year
CONSTCD11 explicit operator int() const NOEXCEPT;
CONSTCD11 bool ok() const NOEXCEPT;

static CONSTCD11 year min() NOEXCEPT;
static CONSTCD11 year max() NOEXCEPT;
static CONSTCD11 year (min)() NOEXCEPT;
static CONSTCD11 year (max)() NOEXCEPT;
};

CONSTCD11 bool operator==(const year& x, const year& y) NOEXCEPT;
Expand Down Expand Up @@ -1073,17 +1073,17 @@ CONSTCD11 inline bool year::ok() const NOEXCEPT {return true;}
CONSTCD11
inline
year
year::min() NOEXCEPT
(year::min)() NOEXCEPT
{
return year{std::numeric_limits<short>::min()};
return year{(std::numeric_limits<short>::min)()};
}

CONSTCD11
inline
year
year::max() NOEXCEPT
(year::max)() NOEXCEPT
{
return year{std::numeric_limits<short>::max()};
return year{(std::numeric_limits<short>::max)()};
}

CONSTCD11
Expand Down
8 changes: 4 additions & 4 deletions include/date/ptz.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ time_zone::get_info(date::sys_time<Duration> st) const
}
else // constant offset
{
r.begin = sys_days{year::min()/January/1};
r.end = sys_days{year::max()/December/last};
r.begin = sys_days{(year::min)()/January/1};
r.end = sys_days{(year::max)()/December/last};
r.abbrev = std_abbrev_;
}
return r;
Expand Down Expand Up @@ -445,8 +445,8 @@ time_zone::get_info(date::local_time<Duration> tp) const
}
else // constant offset
{
r.first.begin = sys_days{year::min()/January/1};
r.first.end = sys_days{year::max()/December/last};
r.first.begin = sys_days{(year::min)()/January/1};
r.first.end = sys_days{(year::max)()/December/last};
r.first.abbrev = std_abbrev_;
r.first.offset = offset_;
}
Expand Down
12 changes: 6 additions & 6 deletions include/date/solar_hijri.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ class year
CONSTCD11 explicit operator int() const NOEXCEPT;
CONSTCD11 bool ok() const NOEXCEPT;

static CONSTCD11 year min() NOEXCEPT;
static CONSTCD11 year max() NOEXCEPT;
static CONSTCD11 year (min)() NOEXCEPT;
static CONSTCD11 year (max)() NOEXCEPT;
};

CONSTCD11 bool operator==(const year& x, const year& y) NOEXCEPT;
Expand Down Expand Up @@ -1104,17 +1104,17 @@ CONSTCD11 inline bool year::ok() const NOEXCEPT {return true;}
CONSTCD11
inline
year
year::min() NOEXCEPT
(year::min)() NOEXCEPT
{
return year{std::numeric_limits<short>::min()};
return year{(std::numeric_limits<short>::min)()};
}

CONSTCD11
inline
year
year::max() NOEXCEPT
(year::max)() NOEXCEPT
{
return year{std::numeric_limits<short>::max()};
return year{(std::numeric_limits<short>::max)()};
}

CONSTCD11
Expand Down
4 changes: 2 additions & 2 deletions include/date/tz_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ struct zonelet
local_seconds until_loc_;
std::chrono::minutes initial_save_{0};
std::string initial_abbrev_;
std::pair<const Rule*, date::year> first_rule_{nullptr, date::year::min()};
std::pair<const Rule*, date::year> last_rule_{nullptr, date::year::max()};
std::pair<const Rule*, date::year> first_rule_{nullptr, (date::year::min)()};
std::pair<const Rule*, date::year> last_rule_{nullptr, (date::year::max)()};

~zonelet();
zonelet();
Expand Down
29 changes: 13 additions & 16 deletions src/tz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
// more than we need and do it early so windows.h doesn't get included
// without these macros having been defined.
// min/max macros interfere with the C++ versions.
# ifndef NOMINMAX
# define NOMINMAX
# endif
// We don't need all that Windows has to offer.
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
Expand Down Expand Up @@ -329,8 +326,8 @@ get_download_gz_file(const std::string& version)
#endif // !USE_OS_TZDB

// These can be used to reduce the range of the database to save memory
CONSTDATA auto min_year = date::year::min();
CONSTDATA auto max_year = date::year::max();
CONSTDATA auto min_year = (date::year::min)();
CONSTDATA auto max_year = (date::year::max)();

CONSTDATA auto min_day = date::January/1;
CONSTDATA auto max_day = date::December/31;
Expand Down Expand Up @@ -1112,7 +1109,7 @@ detail::Rule::Rule(const std::string& s)
in >> word;
if (word == "min")
{
starting_year_ = year::min();
starting_year_ = (year::min)();
}
else
throw std::runtime_error("Didn't find expected word: " + word);
Expand Down Expand Up @@ -1562,7 +1559,7 @@ find_rule_for_zone(const std::pair<const Rule*, const Rule*>& eqr,
auto r = eqr.first;
auto ry = r->starting_year();
auto prev_save = minutes{0};
auto prev_year = year::min();
auto prev_year = (year::min)();
const Rule* prev_rule = nullptr;
while (r != nullptr)
{
Expand All @@ -1588,7 +1585,7 @@ find_rule_for_zone(const std::pair<const Rule*, const Rule*>& eqr,
auto r = eqr.first;
auto ry = r->starting_year();
auto prev_save = minutes{0};
auto prev_year = year::min();
auto prev_year = (year::min)();
const Rule* prev_rule = nullptr;
while (r != nullptr)
{
Expand Down Expand Up @@ -1627,7 +1624,7 @@ find_rule(const std::pair<const Rule*, date::year>& first_rule,
using namespace date;
auto r = first_rule.first;
auto ry = first_rule.second;
sys_info x{sys_days(year::min()/min_day), sys_days(year::max()/max_day),
sys_info x{sys_days((year::min)()/min_day), sys_days((year::max)()/max_day),
seconds{0}, initial_save, initial_abbrev};
while (r != nullptr)
{
Expand Down Expand Up @@ -2137,7 +2134,7 @@ time_zone::load_sys_info(std::vector<detail::transition>::const_iterator i) cons
}
else
{
r.begin = sys_days(year::min()/min_day);
r.begin = sys_days((year::min)()/min_day);
r.end = i+1 != transitions_.end() ? i[1].timepoint :
sys_seconds(sys_days(year::max()/max_day));
r.offset = i[0].info->offset;
Expand Down Expand Up @@ -2419,8 +2416,8 @@ time_zone::adjust_infos(const std::vector<Rule>& rules)
}
else
{
z.first_rule_ = std::make_pair(nullptr, year::min());
z.last_rule_ = std::make_pair(nullptr, year::max());
z.first_rule_ = std::make_pair(nullptr, (year::min)());
z.last_rule_ = std::make_pair(nullptr, (year::max)());
}
}
}
Expand All @@ -2434,9 +2431,9 @@ time_zone::adjust_infos(const std::vector<Rule>& rules)
#ifndef NDEBUG
if (z.first_rule_.first == nullptr)
{
assert(z.first_rule_.second == year::min());
assert(z.first_rule_.second == (year::min)());
assert(z.last_rule_.first == nullptr);
assert(z.last_rule_.second == year::max());
assert(z.last_rule_.second == (year::max)());
}
else
{
Expand Down Expand Up @@ -2539,7 +2536,7 @@ time_zone::get_info_impl(sys_seconds tp, int tz_int) const
if (i != zonelets_.begin())
r.begin = i[-1].until_utc_;
else
r.begin = sys_days(year::min()/min_day);
r.begin = sys_days((year::min)()/min_day);
r.end = i->until_utc_;
r.offset = i->gmtoff_ + i->u.save_;
r.save = i->u.save_;
Expand All @@ -2549,7 +2546,7 @@ time_zone::get_info_impl(sys_seconds tp, int tz_int) const
if (i != zonelets_.begin())
r.begin = i[-1].until_utc_;
else
r.begin = sys_days(year::min()/min_day);
r.begin = sys_days((year::min)()/min_day);
r.end = i->until_utc_;
r.offset = i->gmtoff_;
}
Expand Down