forked from HowardHinnant/date
Try disabling construction of weekday from int.
Also fix bug in round for negatives.
This commit is contained in:
19
date.h
19
date.h
@@ -318,6 +318,7 @@ class weekday
|
||||
unsigned char wd_;
|
||||
public:
|
||||
explicit CONSTCD11 weekday(unsigned wd) noexcept;
|
||||
explicit weekday(int) = delete;
|
||||
CONSTCD11 weekday(const day_point& dp) noexcept;
|
||||
|
||||
weekday& operator++() noexcept;
|
||||
@@ -813,7 +814,7 @@ inline
|
||||
To
|
||||
round(const std::chrono::duration<Rep, Period>& d)
|
||||
{
|
||||
To t0 = std::chrono::duration_cast<To>(d);
|
||||
To t0 = floor<To>(d);
|
||||
To t1 = t0 + To{1};
|
||||
auto diff0 = d - t0;
|
||||
auto diff1 = t1 - d;
|
||||
@@ -1454,13 +1455,13 @@ operator<<(std::ostream& os, const weekday& wd)
|
||||
return os;
|
||||
}
|
||||
|
||||
CONSTDATA weekday sun{0};
|
||||
CONSTDATA weekday mon{1};
|
||||
CONSTDATA weekday tue{2};
|
||||
CONSTDATA weekday wed{3};
|
||||
CONSTDATA weekday thu{4};
|
||||
CONSTDATA weekday fri{5};
|
||||
CONSTDATA weekday sat{6};
|
||||
CONSTDATA weekday sun{0u};
|
||||
CONSTDATA weekday mon{1u};
|
||||
CONSTDATA weekday tue{2u};
|
||||
CONSTDATA weekday wed{3u};
|
||||
CONSTDATA weekday thu{4u};
|
||||
CONSTDATA weekday fri{5u};
|
||||
CONSTDATA weekday sat{6u};
|
||||
|
||||
// weekday_indexed
|
||||
|
||||
@@ -1469,7 +1470,7 @@ inline
|
||||
weekday
|
||||
weekday_indexed::weekday() const noexcept
|
||||
{
|
||||
return date::weekday{wd_};
|
||||
return date::weekday{static_cast<unsigned>(wd_)};
|
||||
}
|
||||
|
||||
CONSTCD11 inline unsigned weekday_indexed::index() const noexcept {return index_;}
|
||||
|
@@ -32,8 +32,8 @@ main()
|
||||
{
|
||||
using namespace date;
|
||||
|
||||
static_assert( aug/fri[2] == month_weekday{month{8}, weekday_indexed{weekday{5}, 2}}, "");
|
||||
static_assert( 8/fri[2] == month_weekday{month{8}, weekday_indexed{weekday{5}, 2}}, "");
|
||||
static_assert(fri[2]/aug == month_weekday{month{8}, weekday_indexed{weekday{5}, 2}}, "");
|
||||
static_assert(fri[2]/8 == month_weekday{month{8}, weekday_indexed{weekday{5}, 2}}, "");
|
||||
static_assert( aug/fri[2] == month_weekday{month{8}, weekday_indexed{weekday{5u}, 2}}, "");
|
||||
static_assert( 8/fri[2] == month_weekday{month{8}, weekday_indexed{weekday{5u}, 2}}, "");
|
||||
static_assert(fri[2]/aug == month_weekday{month{8}, weekday_indexed{weekday{5u}, 2}}, "");
|
||||
static_assert(fri[2]/8 == month_weekday{month{8}, weekday_indexed{weekday{5u}, 2}}, "");
|
||||
}
|
||||
|
@@ -32,8 +32,8 @@ main()
|
||||
{
|
||||
using namespace date;
|
||||
|
||||
static_assert( aug/fri[last] == month_weekday_last{month{8}, weekday_last{weekday{5}}}, "");
|
||||
static_assert( 8/fri[last] == month_weekday_last{month{8}, weekday_last{weekday{5}}}, "");
|
||||
static_assert(fri[last]/aug == month_weekday_last{month{8}, weekday_last{weekday{5}}}, "");
|
||||
static_assert(fri[last]/8 == month_weekday_last{month{8}, weekday_last{weekday{5}}}, "");
|
||||
static_assert( aug/fri[last] == month_weekday_last{month{8}, weekday_last{weekday{5u}}}, "");
|
||||
static_assert( 8/fri[last] == month_weekday_last{month{8}, weekday_last{weekday{5u}}}, "");
|
||||
static_assert(fri[last]/aug == month_weekday_last{month{8}, weekday_last{weekday{5u}}}, "");
|
||||
static_assert(fri[last]/8 == month_weekday_last{month{8}, weekday_last{weekday{5u}}}, "");
|
||||
}
|
||||
|
@@ -33,9 +33,9 @@ main()
|
||||
{
|
||||
using namespace date;
|
||||
|
||||
static_assert(2015_y/aug/fri[2] == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5}, 2}}, "");
|
||||
static_assert( 2015_y/(aug/fri[2]) == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5}, 2}}, "");
|
||||
static_assert( 2015/(aug/fri[2]) == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5}, 2}}, "");
|
||||
static_assert(aug/fri[2]/2015_y == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5}, 2}}, "");
|
||||
static_assert(aug/fri[2]/2015 == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5}, 2}}, "");
|
||||
static_assert(2015_y/aug/fri[2] == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5u}, 2}}, "");
|
||||
static_assert( 2015_y/(aug/fri[2]) == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5u}, 2}}, "");
|
||||
static_assert( 2015/(aug/fri[2]) == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5u}, 2}}, "");
|
||||
static_assert(aug/fri[2]/2015_y == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5u}, 2}}, "");
|
||||
static_assert(aug/fri[2]/2015 == year_month_weekday{year{2015}, month{8}, weekday_indexed{weekday{5u}, 2}}, "");
|
||||
}
|
||||
|
@@ -33,9 +33,9 @@ main()
|
||||
{
|
||||
using namespace date;
|
||||
|
||||
static_assert( 2015_y/aug/fri[last] == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5}}}, "");
|
||||
static_assert( 2015_y/(aug/fri[last]) == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5}}}, "");
|
||||
static_assert( 2015/(aug/fri[last]) == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5}}}, "");
|
||||
static_assert(aug/fri[last]/2015_y == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5}}}, "");
|
||||
static_assert(aug/fri[last]/2015 == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5}}}, "");
|
||||
static_assert( 2015_y/aug/fri[last] == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5u}}}, "");
|
||||
static_assert( 2015_y/(aug/fri[last]) == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5u}}}, "");
|
||||
static_assert( 2015/(aug/fri[last]) == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5u}}}, "");
|
||||
static_assert(aug/fri[last]/2015_y == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5u}}}, "");
|
||||
static_assert(aug/fri[last]/2015 == year_month_weekday_last{year{2015}, month{8}, weekday_last{weekday{5u}}}, "");
|
||||
}
|
||||
|
@@ -81,16 +81,16 @@ static_assert( std::is_nothrow_constructible<unsigned, date::weekday>{}, "");
|
||||
static_assert(!std::is_convertible<unsigned, date::weekday>{}, "");
|
||||
static_assert( std::is_convertible<date::day_point, date::weekday>{}, "");
|
||||
static_assert(!std::is_convertible<date::weekday, unsigned>{}, "");
|
||||
static_assert(static_cast<unsigned>(date::weekday{1}) == 1, "");
|
||||
static_assert(static_cast<unsigned>(date::weekday{1u}) == 1, "");
|
||||
|
||||
static_assert( date::weekday{0}.ok(), "");
|
||||
static_assert( date::weekday{1}.ok(), "");
|
||||
static_assert( date::weekday{2}.ok(), "");
|
||||
static_assert( date::weekday{3}.ok(), "");
|
||||
static_assert( date::weekday{4}.ok(), "");
|
||||
static_assert( date::weekday{5}.ok(), "");
|
||||
static_assert( date::weekday{6}.ok(), "");
|
||||
static_assert(!date::weekday{7}.ok(), "");
|
||||
static_assert( date::weekday{0u}.ok(), "");
|
||||
static_assert( date::weekday{1u}.ok(), "");
|
||||
static_assert( date::weekday{2u}.ok(), "");
|
||||
static_assert( date::weekday{3u}.ok(), "");
|
||||
static_assert( date::weekday{4u}.ok(), "");
|
||||
static_assert( date::weekday{5u}.ok(), "");
|
||||
static_assert( date::weekday{6u}.ok(), "");
|
||||
static_assert(!date::weekday{7u}.ok(), "");
|
||||
|
||||
void
|
||||
test_weekday_arithmetic()
|
||||
@@ -157,13 +157,13 @@ main()
|
||||
{
|
||||
using namespace date;
|
||||
|
||||
static_assert(sun == weekday{0}, "");
|
||||
static_assert(mon == weekday{1}, "");
|
||||
static_assert(tue == weekday{2}, "");
|
||||
static_assert(wed == weekday{3}, "");
|
||||
static_assert(thu == weekday{4}, "");
|
||||
static_assert(fri == weekday{5}, "");
|
||||
static_assert(sat == weekday{6}, "");
|
||||
static_assert(sun == weekday{0u}, "");
|
||||
static_assert(mon == weekday{1u}, "");
|
||||
static_assert(tue == weekday{2u}, "");
|
||||
static_assert(wed == weekday{3u}, "");
|
||||
static_assert(thu == weekday{4u}, "");
|
||||
static_assert(fri == weekday{5u}, "");
|
||||
static_assert(sat == weekday{6u}, "");
|
||||
|
||||
static_assert(!(sun != sun), "");
|
||||
static_assert( sun != mon, "");
|
||||
|
Reference in New Issue
Block a user