ok.pass.cpp (2977B)
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; 13 14 // constexpr bool ok() const noexcept; 15 // Returns: m_.ok() && y_.ok(). 16 17 #include <chrono> 18 #include <type_traits> 19 #include <cassert> 20 21 #include "test_macros.h" 22 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_indexed = std::chrono::weekday_indexed; 29 using year_month_weekday = std::chrono::year_month_weekday; 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>().ok()); 35 ASSERT_SAME_TYPE(bool, decltype(std::declval<const year_month_weekday>().ok())); 36 37 static_assert(!year_month_weekday{}.ok(), ""); 38 39 static_assert(!year_month_weekday{year{-32768}, month{}, weekday_indexed{}}.ok(), ""); // All three bad 40 41 static_assert(!year_month_weekday{year{-32768}, January, weekday_indexed{Tuesday, 1}}.ok(), ""); // Bad year 42 static_assert(!year_month_weekday{year{2019}, month{}, weekday_indexed{Tuesday, 1}}.ok(), ""); // Bad month 43 static_assert(!year_month_weekday{year{2019}, January, weekday_indexed{} }.ok(), ""); // Bad day 44 45 static_assert(!year_month_weekday{year{-32768}, month{}, weekday_indexed{Tuesday, 1}}.ok(), ""); // Bad year & month 46 static_assert(!year_month_weekday{year{2019}, month{}, weekday_indexed{} }.ok(), ""); // Bad month & day 47 static_assert(!year_month_weekday{year{-32768}, January, weekday_indexed{} }.ok(), ""); // Bad year & day 48 49 static_assert( year_month_weekday{year{2019}, January, weekday_indexed{Tuesday, 1}}.ok(), ""); // All OK 50 51 for (unsigned i = 0; i <= 50; ++i) 52 { 53 year_month_weekday ym{year{2019}, January, weekday_indexed{Tuesday, i}}; 54 assert((ym.ok() == weekday_indexed{Tuesday, i}.ok())); 55 } 56 57 for (unsigned i = 0; i <= 50; ++i) 58 { 59 year_month_weekday ym{year{2019}, January, weekday_indexed{weekday{i}, 1}}; 60 assert((ym.ok() == weekday_indexed{weekday{i}, 1}.ok())); 61 } 62 63 for (unsigned i = 0; i <= 50; ++i) 64 { 65 year_month_weekday ym{year{2019}, month{i}, weekday_indexed{Tuesday, 1}}; 66 assert((ym.ok() == month{i}.ok())); 67 } 68 69 const int ymax = static_cast<int>(year::max()); 70 for (int i = ymax - 100; i <= ymax + 100; ++i) 71 { 72 year_month_weekday ym{year{i}, January, weekday_indexed{Tuesday, 1}}; 73 assert((ym.ok() == year{i}.ok())); 74 } 75 }