forked from OSchip/llvm-project
Implement change #4 of P1466: Change weekday to accept both 0 and 7 as Sunday. Add accessors 'c_encoding' and 'iso_encoding' to provide different interpretations of the weekday. Remove 'operator unsigned'
llvm-svn: 366981
This commit is contained in:
parent
272a9db115
commit
db99d3a2a2
|
@ -1810,7 +1810,7 @@ private:
|
|||
unsigned char __wd;
|
||||
public:
|
||||
weekday() = default;
|
||||
inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val)) {}
|
||||
inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val == 7 ? 0 : __val)) {}
|
||||
inline constexpr weekday(const sys_days& __sysd) noexcept
|
||||
: __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {}
|
||||
inline explicit constexpr weekday(const local_days& __locd) noexcept
|
||||
|
@ -1822,7 +1822,8 @@ public:
|
|||
inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; }
|
||||
constexpr weekday& operator+=(const days& __dd) noexcept;
|
||||
constexpr weekday& operator-=(const days& __dd) noexcept;
|
||||
inline explicit constexpr operator unsigned() const noexcept { return __wd; }
|
||||
inline constexpr unsigned c_encoding() const noexcept { return __wd; }
|
||||
inline constexpr unsigned iso_encoding() const noexcept { return __wd == 0u ? 7 : __wd; }
|
||||
inline constexpr bool ok() const noexcept { return __wd <= 6; }
|
||||
constexpr weekday_indexed operator[](unsigned __index) const noexcept;
|
||||
constexpr weekday_last operator[](last_spec) const noexcept;
|
||||
|
@ -1842,7 +1843,7 @@ unsigned char weekday::__weekday_from_days(int __days) noexcept
|
|||
|
||||
inline constexpr
|
||||
bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept
|
||||
{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
|
||||
{ return __lhs.c_encoding() == __rhs.c_encoding(); }
|
||||
|
||||
inline constexpr
|
||||
bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept
|
||||
|
@ -1850,7 +1851,7 @@ bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept
|
|||
|
||||
inline constexpr
|
||||
bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept
|
||||
{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }
|
||||
{ return __lhs.c_encoding() < __rhs.c_encoding(); }
|
||||
|
||||
inline constexpr
|
||||
bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept
|
||||
|
@ -1866,7 +1867,7 @@ bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept
|
|||
|
||||
constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept
|
||||
{
|
||||
auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + __rhs.count();
|
||||
auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();
|
||||
auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
|
||||
return weekday{static_cast<unsigned>(__mu - __yr * 7)};
|
||||
}
|
||||
|
@ -1879,7 +1880,7 @@ constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept
|
|||
|
||||
constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept
|
||||
{
|
||||
const int __wdu = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
|
||||
const int __wdu = __lhs.c_encoding() - __rhs.c_encoding();
|
||||
const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7;
|
||||
return days{__wdu - __wk * 7};
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ int main(int, char**)
|
|||
for (unsigned i = 1; i <= 50; ++i)
|
||||
{
|
||||
month_weekday_last mdl(January, weekday_last{weekday{i}});
|
||||
assert( static_cast<unsigned>(mdl.weekday_last().weekday()) == i);
|
||||
assert( mdl.weekday_last().weekday().c_encoding() == (i == 7 ? 0 : i));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -33,7 +33,7 @@ int main(int, char**)
|
|||
for (unsigned i = 0; i <= 6; ++i)
|
||||
{
|
||||
weekday_indexed wdi(weekday{i}, 2);
|
||||
assert( static_cast<unsigned>(wdi.weekday()) == i);
|
||||
assert( wdi.weekday().c_encoding() == i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -29,7 +29,7 @@ int main(int, char**)
|
|||
|
||||
static_assert( weekday_last{weekday{0}}.ok(), "");
|
||||
static_assert( weekday_last{weekday{1}}.ok(), "");
|
||||
static_assert(!weekday_last{weekday{7}}.ok(), "");
|
||||
static_assert(!weekday_last{weekday{8}}.ok(), "");
|
||||
|
||||
for (unsigned i = 0; i <= 255; ++i)
|
||||
assert(weekday_last{weekday{i}}.ok() == weekday{i}.ok());
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
|
||||
|
||||
// <chrono>
|
||||
// class weekday;
|
||||
|
||||
// constexpr unsigned c_encoding() const noexcept;
|
||||
|
||||
|
||||
#include <chrono>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
template <typename WD>
|
||||
constexpr bool testConstexpr()
|
||||
{
|
||||
WD wd{5};
|
||||
return wd.c_encoding() == 5;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
using weekday = std::chrono::weekday;
|
||||
|
||||
ASSERT_NOEXCEPT( std::declval<weekday&>().c_encoding());
|
||||
ASSERT_SAME_TYPE(unsigned, decltype(std::declval<weekday&>().c_encoding()));
|
||||
|
||||
static_assert(testConstexpr<weekday>(), "");
|
||||
|
||||
for (unsigned i = 0; i <= 10; ++i)
|
||||
{
|
||||
weekday wd(i);
|
||||
assert(wd.c_encoding() == (i == 7 ? 0 : i));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -42,7 +42,7 @@ int main(int, char**)
|
|||
constexpr weekday wd{sd};
|
||||
|
||||
static_assert( wd.ok(), "");
|
||||
static_assert(static_cast<unsigned>(wd) == 4, "");
|
||||
static_assert( wd.c_encoding() == 4, "");
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ int main(int, char**)
|
|||
constexpr weekday wd{sd};
|
||||
|
||||
static_assert( wd.ok(), "");
|
||||
static_assert(static_cast<unsigned>(wd) == 3, "");
|
||||
static_assert( wd.c_encoding() == 3, "");
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,7 +59,7 @@ int main(int, char**)
|
|||
constexpr weekday wd{sd};
|
||||
|
||||
static_assert( wd.ok(), "");
|
||||
static_assert(static_cast<unsigned>(wd) == 2, "");
|
||||
static_assert( wd.c_encoding() == 2, "");
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ int main(int, char**)
|
|||
weekday wd{sd};
|
||||
|
||||
assert( wd.ok());
|
||||
assert(static_cast<unsigned>(wd) == 3);
|
||||
assert( wd.c_encoding() == 3);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
// constexpr weekday(const sys_days& dp) noexcept;
|
||||
// explicit constexpr weekday(const local_days& dp) noexcept;
|
||||
//
|
||||
// explicit constexpr operator unsigned() const noexcept;
|
||||
// unsigned c_encoding() const noexcept;
|
||||
|
||||
// Effects: Constructs an object of type weekday by initializing m_ with m.
|
||||
// The value held is unspecified if d is not in the range [0, 255].
|
||||
// Effects: Constructs an object of type weekday by initializing wd_ with wd == 7 ? 0 : wd
|
||||
// The value held is unspecified if wd is not in the range [0, 255].
|
||||
|
||||
#include <chrono>
|
||||
#include <type_traits>
|
||||
|
@ -32,18 +32,18 @@ int main(int, char**)
|
|||
|
||||
ASSERT_NOEXCEPT(weekday{});
|
||||
ASSERT_NOEXCEPT(weekday(1));
|
||||
ASSERT_NOEXCEPT(static_cast<unsigned>(weekday(1)));
|
||||
ASSERT_NOEXCEPT(weekday(1).c_encoding());
|
||||
|
||||
constexpr weekday m0{};
|
||||
static_assert(static_cast<unsigned>(m0) == 0, "");
|
||||
static_assert(m0.c_encoding() == 0, "");
|
||||
|
||||
constexpr weekday m1{1};
|
||||
static_assert(static_cast<unsigned>(m1) == 1, "");
|
||||
static_assert(m1.c_encoding() == 1, "");
|
||||
|
||||
for (unsigned i = 0; i <= 255; ++i)
|
||||
{
|
||||
weekday m(i);
|
||||
assert(static_cast<unsigned>(m) == i);
|
||||
assert(m.c_encoding() == (i == 7 ? 0 : i));
|
||||
}
|
||||
|
||||
// TODO - sys_days and local_days ctor tests
|
||||
|
|
|
@ -42,7 +42,7 @@ int main(int, char**)
|
|||
constexpr weekday wd{sd};
|
||||
|
||||
static_assert( wd.ok(), "");
|
||||
static_assert(static_cast<unsigned>(wd) == 4, "");
|
||||
static_assert( wd.c_encoding() == 4, "");
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ int main(int, char**)
|
|||
constexpr weekday wd{sd};
|
||||
|
||||
static_assert( wd.ok(), "");
|
||||
static_assert(static_cast<unsigned>(wd) == 3, "");
|
||||
static_assert( wd.c_encoding() == 3, "");
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,7 +59,7 @@ int main(int, char**)
|
|||
constexpr weekday wd{sd};
|
||||
|
||||
static_assert( wd.ok(), "");
|
||||
static_assert(static_cast<unsigned>(wd) == 2, "");
|
||||
static_assert( wd.c_encoding() == 2, "");
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ int main(int, char**)
|
|||
weekday wd{sd};
|
||||
|
||||
assert( wd.ok());
|
||||
assert(static_cast<unsigned>(wd) == 3);
|
||||
assert( wd.c_encoding() == 3);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -25,9 +25,9 @@ template <typename WD>
|
|||
constexpr bool testConstexpr()
|
||||
{
|
||||
WD wd{1};
|
||||
if (static_cast<unsigned>(--wd) != 0) return false;
|
||||
if (static_cast<unsigned>(wd--) != 0) return false;
|
||||
if (static_cast<unsigned>(wd) != 6) return false;
|
||||
if ((--wd).c_encoding() != 0) return false;
|
||||
if ((wd--).c_encoding() != 0) return false;
|
||||
if ((wd).c_encoding() != 6) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -45,9 +45,9 @@ int main(int, char**)
|
|||
for (unsigned i = 0; i <= 6; ++i)
|
||||
{
|
||||
weekday wd(i);
|
||||
assert((static_cast<unsigned>(--wd) == euclidian_subtraction<unsigned, 0, 6>(i, 1)));
|
||||
assert((static_cast<unsigned>(wd--) == euclidian_subtraction<unsigned, 0, 6>(i, 1)));
|
||||
assert((static_cast<unsigned>(wd) == euclidian_subtraction<unsigned, 0, 6>(i, 2)));
|
||||
assert(((--wd).c_encoding() == euclidian_subtraction<unsigned, 0, 6>(i, 1)));
|
||||
assert(((wd--).c_encoding() == euclidian_subtraction<unsigned, 0, 6>(i, 1)));
|
||||
assert(((wd) .c_encoding() == euclidian_subtraction<unsigned, 0, 6>(i, 2)));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -25,9 +25,9 @@ template <typename WD>
|
|||
constexpr bool testConstexpr()
|
||||
{
|
||||
WD wd{5};
|
||||
if (static_cast<unsigned>(++wd) != 6) return false;
|
||||
if (static_cast<unsigned>(wd++) != 6) return false;
|
||||
if (static_cast<unsigned>(wd) != 0) return false;
|
||||
if ((++wd).c_encoding() != 6) return false;
|
||||
if ((wd++).c_encoding() != 6) return false;
|
||||
if ((wd) .c_encoding() != 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -45,9 +45,9 @@ int main(int, char**)
|
|||
for (unsigned i = 0; i <= 6; ++i)
|
||||
{
|
||||
weekday wd(i);
|
||||
assert((static_cast<unsigned>(++wd) == euclidian_addition<unsigned, 0, 6>(i, 1)));
|
||||
assert((static_cast<unsigned>(wd++) == euclidian_addition<unsigned, 0, 6>(i, 1)));
|
||||
assert((static_cast<unsigned>(wd) == euclidian_addition<unsigned, 0, 6>(i, 2)));
|
||||
assert(((++wd).c_encoding() == euclidian_addition<unsigned, 0, 6>(i, 1)));
|
||||
assert(((wd++).c_encoding() == euclidian_addition<unsigned, 0, 6>(i, 1)));
|
||||
assert(((wd) .c_encoding() == euclidian_addition<unsigned, 0, 6>(i, 2)));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
|
||||
|
||||
// <chrono>
|
||||
// class weekday;
|
||||
|
||||
// constexpr unsigned iso_encoding() const noexcept;
|
||||
// Returns the underlying weekday, _except_ that returns '7' for Sunday (zero)
|
||||
// See [time.cal.wd.members]
|
||||
|
||||
#include <chrono>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
template <typename WD>
|
||||
constexpr bool testConstexpr()
|
||||
{
|
||||
WD wd{5};
|
||||
return wd.c_encoding() == 5;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
using weekday = std::chrono::weekday;
|
||||
|
||||
ASSERT_NOEXCEPT( std::declval<weekday&>().iso_encoding());
|
||||
ASSERT_SAME_TYPE(unsigned, decltype(std::declval<weekday&>().iso_encoding()));
|
||||
|
||||
static_assert(testConstexpr<weekday>(), "");
|
||||
|
||||
// This is different than all the other tests, because the '7' gets converted to
|
||||
// a zero in the constructor, but then back to '7' by iso_encoding().
|
||||
for (unsigned i = 0; i <= 10; ++i)
|
||||
{
|
||||
weekday wd(i);
|
||||
assert(wd.iso_encoding() == (i == 0 ? 7 : i));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -28,11 +28,12 @@ int main(int, char**)
|
|||
|
||||
static_assert( weekday{0}.ok(), "");
|
||||
static_assert( weekday{1}.ok(), "");
|
||||
static_assert(!weekday{7}.ok(), "");
|
||||
static_assert( weekday{7}.ok(), ""); // 7 is transmorgified into 0 in the ctor
|
||||
static_assert(!weekday{8}.ok(), "");
|
||||
|
||||
for (unsigned i = 0; i <= 6; ++i)
|
||||
for (unsigned i = 0; i <= 7; ++i)
|
||||
assert(weekday{i}.ok());
|
||||
for (unsigned i = 7; i <= 255; ++i)
|
||||
for (unsigned i = 8; i <= 255; ++i)
|
||||
assert(!weekday{i}.ok());
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -24,12 +24,12 @@ template <typename M, typename Ms>
|
|||
constexpr bool testConstexpr()
|
||||
{
|
||||
M m1{1};
|
||||
if (static_cast<unsigned>(m1 += Ms{ 1}) != 2) return false;
|
||||
if (static_cast<unsigned>(m1 += Ms{ 2}) != 4) return false;
|
||||
if (static_cast<unsigned>(m1 += Ms{ 4}) != 1) return false;
|
||||
if (static_cast<unsigned>(m1 -= Ms{ 1}) != 0) return false;
|
||||
if (static_cast<unsigned>(m1 -= Ms{ 2}) != 5) return false;
|
||||
if (static_cast<unsigned>(m1 -= Ms{ 4}) != 1) return false;
|
||||
if ((m1 += Ms{ 1}).c_encoding() != 2) return false;
|
||||
if ((m1 += Ms{ 2}).c_encoding() != 4) return false;
|
||||
if ((m1 += Ms{ 4}).c_encoding() != 1) return false;
|
||||
if ((m1 -= Ms{ 1}).c_encoding() != 0) return false;
|
||||
if ((m1 -= Ms{ 2}).c_encoding() != 5) return false;
|
||||
if ((m1 -= Ms{ 4}).c_encoding() != 1) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -49,15 +49,15 @@ int main(int, char**)
|
|||
for (unsigned i = 0; i <= 6; ++i)
|
||||
{
|
||||
weekday wd(i);
|
||||
assert((static_cast<unsigned>(wd += days{3}) == euclidian_addition<unsigned, 0, 6>(i, 3)));
|
||||
assert((static_cast<unsigned>(wd) == euclidian_addition<unsigned, 0, 6>(i, 3)));
|
||||
assert(((wd += days{3}).c_encoding() == euclidian_addition<unsigned, 0, 6>(i, 3)));
|
||||
assert(((wd) .c_encoding() == euclidian_addition<unsigned, 0, 6>(i, 3)));
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i <= 6; ++i)
|
||||
{
|
||||
weekday wd(i);
|
||||
assert((static_cast<unsigned>(wd -= days{4}) == euclidian_subtraction<unsigned, 0, 6>(i, 4)));
|
||||
assert((static_cast<unsigned>(wd) == euclidian_subtraction<unsigned, 0, 6>(i, 4)));
|
||||
assert(((wd -= days{4}).c_encoding() == euclidian_subtraction<unsigned, 0, 6>(i, 4)));
|
||||
assert(((wd) .c_encoding() == euclidian_subtraction<unsigned, 0, 6>(i, 4)));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -51,13 +51,13 @@ int main(int, char**)
|
|||
assert(std::chrono::Friday == std::chrono::weekday(5));
|
||||
assert(std::chrono::Saturday == std::chrono::weekday(6));
|
||||
|
||||
assert(static_cast<unsigned>(std::chrono::Sunday) == 0);
|
||||
assert(static_cast<unsigned>(std::chrono::Monday) == 1);
|
||||
assert(static_cast<unsigned>(std::chrono::Tuesday) == 2);
|
||||
assert(static_cast<unsigned>(std::chrono::Wednesday) == 3);
|
||||
assert(static_cast<unsigned>(std::chrono::Thursday) == 4);
|
||||
assert(static_cast<unsigned>(std::chrono::Friday) == 5);
|
||||
assert(static_cast<unsigned>(std::chrono::Saturday) == 6);
|
||||
assert(std::chrono::Sunday.c_encoding() == 0);
|
||||
assert(std::chrono::Monday.c_encoding() == 1);
|
||||
assert(std::chrono::Tuesday.c_encoding() == 2);
|
||||
assert(std::chrono::Wednesday.c_encoding() == 3);
|
||||
assert(std::chrono::Thursday.c_encoding() == 4);
|
||||
assert(std::chrono::Friday.c_encoding() == 5);
|
||||
assert(std::chrono::Saturday.c_encoding() == 6);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ int main(int, char**)
|
|||
{
|
||||
weekday wd = weekday{i} - days{j};
|
||||
assert(wd + days{j} == weekday{i});
|
||||
assert((static_cast<unsigned>(wd) == euclidian_subtraction<unsigned, 0, 6>(i, j)));
|
||||
assert((wd.c_encoding() == euclidian_subtraction<unsigned, 0, 6>(i, j)));
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i <= 6; ++i)
|
||||
|
|
|
@ -63,8 +63,8 @@ int main(int, char**)
|
|||
weekday wd1 = weekday{i} + days{j};
|
||||
weekday wd2 = days{j} + weekday{i};
|
||||
assert(wd1 == wd2);
|
||||
assert((static_cast<unsigned>(wd1) == euclidian_addition<unsigned, 0, 6>(i, j)));
|
||||
assert((static_cast<unsigned>(wd2) == euclidian_addition<unsigned, 0, 6>(i, j)));
|
||||
assert((wd1.c_encoding() == euclidian_addition<unsigned, 0, 6>(i, j)));
|
||||
assert((wd2.c_encoding() == euclidian_addition<unsigned, 0, 6>(i, j)));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -35,7 +35,7 @@ int main(int, char**)
|
|||
for (unsigned i = 1; i <= 50; ++i)
|
||||
{
|
||||
year_month_weekday ymwd0(year{1234}, month{2}, weekday_indexed{weekday{i}, 1});
|
||||
assert(static_cast<unsigned>(ymwd0.weekday()) == i);
|
||||
assert(ymwd0.weekday().c_encoding() == (i == 7 ? 0 : i));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -35,10 +35,11 @@ int main(int, char**)
|
|||
for (unsigned i = 1; i <= 50; ++i)
|
||||
{
|
||||
year_month_weekday ymwd0(year{1234}, month{2}, weekday_indexed{weekday{i}, 1});
|
||||
assert( static_cast<unsigned>(ymwd0.weekday_indexed().weekday()) == i);
|
||||
assert( ymwd0.weekday_indexed().weekday().c_encoding() == (i == 7 ? 0 : i));
|
||||
assert( static_cast<unsigned>(ymwd0.weekday_indexed().index()) == 1);
|
||||
|
||||
year_month_weekday ymwd1(year{1234}, month{2}, weekday_indexed{weekday{2}, i});
|
||||
assert( static_cast<unsigned>(ymwd1.weekday_indexed().weekday()) == 2);
|
||||
assert( ymwd1.weekday_indexed().weekday().c_encoding() == 2);
|
||||
assert( static_cast<unsigned>(ymwd1.weekday_indexed().index()) == i);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,11 +37,11 @@ int main(int, char**)
|
|||
|
||||
static_assert(!year_month_weekday_last{year{-32768}, January, weekday_last{Tuesday}}.ok(), ""); // Bad year
|
||||
static_assert(!year_month_weekday_last{year{2019}, month{}, weekday_last{Tuesday}}.ok(), ""); // Bad month
|
||||
static_assert(!year_month_weekday_last{year{2019}, January, weekday_last{weekday{7}}}.ok(), ""); // Bad day
|
||||
static_assert(!year_month_weekday_last{year{2019}, January, weekday_last{weekday{8}}}.ok(), ""); // Bad day
|
||||
|
||||
static_assert(!year_month_weekday_last{year{-32768}, month{}, weekday_last{Tuesday}}.ok(), ""); // Bad year & month
|
||||
static_assert(!year_month_weekday_last{year{2019}, month{}, weekday_last{weekday{7}}}.ok(), ""); // Bad month & day
|
||||
static_assert(!year_month_weekday_last{year{-32768}, January, weekday_last{weekday{7}}}.ok(), ""); // Bad year & day
|
||||
static_assert(!year_month_weekday_last{year{2019}, month{}, weekday_last{weekday{8}}}.ok(), ""); // Bad month & day
|
||||
static_assert(!year_month_weekday_last{year{-32768}, January, weekday_last{weekday{8}}}.ok(), ""); // Bad year & day
|
||||
|
||||
static_assert( year_month_weekday_last{year{2019}, January, weekday_last{Tuesday}}.ok(), ""); // All OK
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ int main(int, char**)
|
|||
for (unsigned i = 1; i <= 50; ++i)
|
||||
{
|
||||
year_month_weekday_last ymwdl(year{1}, month{1}, weekday_last{weekday{i}});
|
||||
assert(static_cast<unsigned>(ymwdl.weekday()) == i);
|
||||
assert(ymwdl.weekday().c_encoding() == (i == 7 ? 0 : i));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue