1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
10
11 // <chrono>
12 // class year_month_weekday_last;
13
14 // constexpr bool ok() const noexcept;
15 // Returns: y_.ok() && m_.ok() && wdl_.ok().
16
17 #include <chrono>
18 #include <type_traits>
19 #include <cassert>
20
21 #include "test_macros.h"
22
main()23 int main()
24 {
25 using year = std::chrono::year;
26 using month = std::chrono::month;
27 using weekday = std::chrono::weekday;
28 using weekday_last = std::chrono::weekday_last;
29 using year_month_weekday_last = std::chrono::year_month_weekday_last;
30
31 constexpr month January = std::chrono::January;
32 constexpr weekday Tuesday = std::chrono::Tuesday;
33
34 ASSERT_NOEXCEPT( std::declval<const year_month_weekday_last>().ok());
35 ASSERT_SAME_TYPE(bool, decltype(std::declval<const year_month_weekday_last>().ok()));
36
37 static_assert(!year_month_weekday_last{year{-32768}, month{}, weekday_last{weekday{}}}.ok(), ""); // All three bad
38
39 static_assert(!year_month_weekday_last{year{-32768}, January, weekday_last{Tuesday}}.ok(), ""); // Bad year
40 static_assert(!year_month_weekday_last{year{2019}, month{}, weekday_last{Tuesday}}.ok(), ""); // Bad month
41 static_assert(!year_month_weekday_last{year{2019}, January, weekday_last{weekday{7}}}.ok(), ""); // Bad day
42
43 static_assert(!year_month_weekday_last{year{-32768}, month{}, weekday_last{Tuesday}}.ok(), ""); // Bad year & month
44 static_assert(!year_month_weekday_last{year{2019}, month{}, weekday_last{weekday{7}}}.ok(), ""); // Bad month & day
45 static_assert(!year_month_weekday_last{year{-32768}, January, weekday_last{weekday{7}}}.ok(), ""); // Bad year & day
46
47 static_assert( year_month_weekday_last{year{2019}, January, weekday_last{Tuesday}}.ok(), ""); // All OK
48
49 for (unsigned i = 0; i <= 50; ++i)
50 {
51 year_month_weekday_last ym{year{2019}, January, weekday_last{Tuesday}};
52 assert((ym.ok() == weekday_last{Tuesday}.ok()));
53 }
54
55 for (unsigned i = 0; i <= 50; ++i)
56 {
57 year_month_weekday_last ym{year{2019}, January, weekday_last{weekday{i}}};
58 assert((ym.ok() == weekday_last{weekday{i}}.ok()));
59 }
60
61 for (unsigned i = 0; i <= 50; ++i)
62 {
63 year_month_weekday_last ym{year{2019}, month{i}, weekday_last{Tuesday}};
64 assert((ym.ok() == month{i}.ok()));
65 }
66
67 const int ymax = static_cast<int>(year::max());
68 for (int i = ymax - 100; i <= ymax + 100; ++i)
69 {
70 year_month_weekday_last ym{year{i}, January, weekday_last{Tuesday}};
71 assert((ym.ok() == year{i}.ok()));
72 }
73 }
74