libcxx

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

month_day_last.pass.cpp (3268B)


      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_last;
     13 
     14 // constexpr month_day_last
     15 //   operator/(const month& m, last_spec) noexcept;
     16 // Returns: month_day_last{m}.
     17 //
     18 // constexpr month_day_last
     19 //   operator/(int m, last_spec) noexcept;
     20 // Returns: month(m) / last.
     21 //
     22 // constexpr month_day_last
     23 //   operator/(last_spec, const month& m) noexcept;
     24 // Returns: m / last.
     25 //
     26 // constexpr month_day_last
     27 //   operator/(last_spec, int m) noexcept;
     28 // Returns: month(m) / last.
     29 //
     30 //
     31 // [Note: A month_day_last object can be constructed using the expression m/last or last/m,
     32 //     where m is an expression of type month. — end note]
     33 // [Example:
     34 //     constexpr auto mdl = February/last; // mdl is the last day of February of an as yet unspecified year
     35 //     static_assert(mdl.month() == February);
     36 // --end example]
     37 
     38 
     39 
     40 
     41 
     42 
     43 #include <chrono>
     44 #include <type_traits>
     45 #include <cassert>
     46 
     47 #include "test_macros.h"
     48 #include "test_comparisons.h"
     49 
     50 int main()
     51 {
     52     using month          = std::chrono::month;
     53     using month_day_last = std::chrono::month_day_last;
     54 
     55     constexpr month February = std::chrono::February;
     56     constexpr std::chrono::last_spec last = std::chrono::last;
     57 
     58     ASSERT_SAME_TYPE(month_day_last, decltype(last/February));
     59     ASSERT_SAME_TYPE(month_day_last, decltype(February/last));
     60 
     61 //  Run the example
     62     {
     63     constexpr auto mdl = February/std::chrono::last;
     64     static_assert(mdl.month() == February, "");
     65     }
     66 
     67     { // operator/(const month& m, last_spec) and switched
     68         ASSERT_NOEXCEPT (                         last/February);
     69         ASSERT_SAME_TYPE(month_day_last, decltype(last/February));
     70         ASSERT_NOEXCEPT (                         February/last);
     71         ASSERT_SAME_TYPE(month_day_last, decltype(February/last));
     72 
     73         static_assert((last/February).month() == February, "");
     74         static_assert((February/last).month() == February, "");
     75 
     76         for (unsigned i = 1; i < 12; ++i)
     77         {
     78             month m{i};
     79             month_day_last mdl1 = last/m;
     80             month_day_last mdl2 = m/last;
     81             assert(mdl1.month() == m);
     82             assert(mdl2.month() == m);
     83             assert(mdl1 == mdl2);
     84         }
     85     }
     86 
     87     { // operator/(int, last_spec) and switched
     88         ASSERT_NOEXCEPT (                         last/2);
     89         ASSERT_SAME_TYPE(month_day_last, decltype(last/2));
     90         ASSERT_NOEXCEPT (                         2/last);
     91         ASSERT_SAME_TYPE(month_day_last, decltype(2/last));
     92 
     93         static_assert((last/2).month() == February, "");
     94         static_assert((2/last).month() == February, "");
     95 
     96         for (unsigned i = 1; i < 12; ++i)
     97         {
     98             month m{i};
     99             month_day_last mdl1 = last/i;
    100             month_day_last mdl2 = i/last;
    101             assert(mdl1.month() == m);
    102             assert(mdl2.month() == m);
    103             assert(mdl1 == mdl2);
    104         }
    105     }
    106 
    107 }