libcxx

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

month_weekday_last.pass.cpp (3657B)


      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_weekday_last;
     13 
     14 // constexpr month_weekday_last
     15 //   operator/(const month& m, const weekday_last& wdl) noexcept;
     16 // Returns: {m, wdl}.
     17 //
     18 // constexpr month_weekday_last
     19 //   operator/(int m, const weekday_last& wdl) noexcept;
     20 // Returns: month(m) / wdl.
     21 //
     22 // constexpr month_weekday_last
     23 //   operator/(const weekday_last& wdl, const month& m) noexcept;
     24 // Returns: m / wdl.
     25 //
     26 // constexpr month_weekday_last
     27 //   operator/(const weekday_last& wdl, int m) noexcept;
     28 // Returns: month(m) / wdl.
     29 
     30 
     31 
     32 
     33 #include <chrono>
     34 #include <type_traits>
     35 #include <cassert>
     36 
     37 #include "test_macros.h"
     38 #include "test_comparisons.h"
     39 
     40 int main()
     41 {
     42     using month_weekday      = std::chrono::month_weekday;
     43     using month              = std::chrono::month;
     44     using weekday            = std::chrono::weekday;
     45     using weekday_last       = std::chrono::weekday_last;
     46     using month_weekday_last = std::chrono::month_weekday_last;
     47 
     48     constexpr weekday Tuesday = std::chrono::Tuesday;
     49     constexpr month February = std::chrono::February;
     50     constexpr std::chrono::last_spec last = std::chrono::last;
     51 
     52     { // operator/(const month& m, const weekday_last& wdi) (and switched)
     53         ASSERT_NOEXCEPT (February/Tuesday[last]);
     54         ASSERT_SAME_TYPE(month_weekday_last, decltype(February/Tuesday[last]));
     55         ASSERT_NOEXCEPT (Tuesday[last]/February);
     56         ASSERT_SAME_TYPE(month_weekday_last, decltype(Tuesday[last]/February));
     57 
     58     //  Run the example
     59         {
     60         constexpr month_weekday_last wdi = February/Tuesday[last];
     61         static_assert(wdi.month()        == February,      "");
     62         static_assert(wdi.weekday_last() == Tuesday[last], "");
     63         }
     64 
     65         for (int i = 1; i <= 12; ++i)
     66             for (unsigned j = 0; j <= 6; ++j)
     67             {
     68                 month m(i);
     69                 weekday_last wdi = weekday{j}[last];
     70                 month_weekday_last mwd1 = m/wdi;
     71                 month_weekday_last mwd2 = wdi/m;
     72                 assert(mwd1.month() == m);
     73                 assert(mwd1.weekday_last() == wdi);
     74                 assert(mwd2.month() == m);
     75                 assert(mwd2.weekday_last() == wdi);
     76                 assert(mwd1 == mwd2);
     77             }
     78     }
     79 
     80 
     81     { // operator/(int m, const weekday_last& wdi) (and switched)
     82         ASSERT_NOEXCEPT (2/Tuesday[2]);
     83         ASSERT_SAME_TYPE(month_weekday_last, decltype(2/Tuesday[last]));
     84         ASSERT_NOEXCEPT (Tuesday[2]/2);
     85         ASSERT_SAME_TYPE(month_weekday_last, decltype(Tuesday[last]/2));
     86 
     87     //  Run the example
     88         {
     89         constexpr month_weekday wdi = 2/Tuesday[3];
     90         static_assert(wdi.month()           == February,   "");
     91         static_assert(wdi.weekday_indexed() == Tuesday[3], "");
     92         }
     93 
     94         for (int i = 1; i <= 12; ++i)
     95             for (unsigned j = 0; j <= 6; ++j)
     96             {
     97                 weekday_last wdi = weekday{j}[last];
     98                 month_weekday_last mwd1 = i/wdi;
     99                 month_weekday_last mwd2 = wdi/i;
    100                 assert(mwd1.month() == month(i));
    101                 assert(mwd1.weekday_last() == wdi);
    102                 assert(mwd2.month() == month(i));
    103                 assert(mwd2.weekday_last() == wdi);
    104                 assert(mwd1 == mwd2);
    105             }
    106     }
    107 }