ok.pass.cpp (2014B)
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 month_day; 13 14 // constexpr bool ok() const noexcept; 15 // Returns: true if m_.ok() is true, 1d <= d_, and d_ is less than or equal to the 16 // number of days in month m_; otherwise returns false. 17 // When m_ == February, the number of days is considered to be 29. 18 19 #include <chrono> 20 #include <type_traits> 21 #include <cassert> 22 23 #include "test_macros.h" 24 25 int main() 26 { 27 using day = std::chrono::day; 28 using month = std::chrono::month; 29 using month_day = std::chrono::month_day; 30 31 ASSERT_NOEXCEPT( std::declval<const month_day>().ok()); 32 ASSERT_SAME_TYPE(bool, decltype(std::declval<const month_day>().ok())); 33 34 static_assert(!month_day{}.ok(), ""); 35 static_assert( month_day{std::chrono::May, day{2}}.ok(), ""); 36 37 assert(!(month_day(std::chrono::April, day{0}).ok())); 38 39 assert( (month_day{std::chrono::March, day{1}}.ok())); 40 for (unsigned i = 1; i <= 12; ++i) 41 { 42 const bool is31 = i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12; 43 assert(!(month_day{month{i}, day{ 0}}.ok())); 44 assert( (month_day{month{i}, day{ 1}}.ok())); 45 assert( (month_day{month{i}, day{10}}.ok())); 46 assert( (month_day{month{i}, day{29}}.ok())); 47 assert( (month_day{month{i}, day{30}}.ok()) == (i != 2)); 48 assert( (month_day{month{i}, day{31}}.ok()) == is31); 49 assert(!(month_day{month{i}, day{32}}.ok())); 50 } 51 52 // If the month is not ok, all the days are bad 53 for (unsigned i = 1; i <= 35; ++i) 54 assert(!(month_day{month{13}, day{i}}.ok())); 55 }