libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

ok.pass.cpp (1873B)


      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_day_last;
     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 month_day_last      = std::chrono::month_day_last;
     28     using year_month_day_last = std::chrono::year_month_day_last;
     29 
     30     constexpr month January = std::chrono::January;
     31 
     32     ASSERT_NOEXCEPT(                std::declval<const year_month_day_last>().ok());
     33     ASSERT_SAME_TYPE(bool, decltype(std::declval<const year_month_day_last>().ok()));
     34 
     35     static_assert(!year_month_day_last{year{-32768}, month_day_last{month{}}}.ok(), ""); // both bad
     36     static_assert(!year_month_day_last{year{-32768}, month_day_last{January}}.ok(), ""); // Bad year
     37     static_assert(!year_month_day_last{year{2019},   month_day_last{month{}}}.ok(), ""); // Bad month
     38     static_assert( year_month_day_last{year{2019},   month_day_last{January}}.ok(), ""); // All OK
     39 
     40     for (unsigned i = 0; i <= 50; ++i)
     41     {
     42         year_month_day_last ym{year{2019}, month_day_last{month{i}}};
     43         assert( ym.ok() == month{i}.ok());
     44     }
     45 
     46     const int ymax = static_cast<int>(year::max());
     47     for (int i = ymax - 100; i <= ymax + 100; ++i)
     48     {
     49         year_month_day_last ym{year{i}, month_day_last{January}};
     50         assert( ym.ok() == year{i}.ok());
     51     }
     52 }