1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // UNSUPPORTED: c++03, c++11, c++14, c++17 9 10 // <chrono> 11 // class year_month; 12 13 // constexpr year_month operator/(const year& y, const month& m) noexcept; 14 // Returns: {y, m}. 15 // 16 // constexpr year_month operator/(const year& y, int m) noexcept; 17 // Returns: y / month(m). 18 19 20 21 #include <chrono> 22 #include <type_traits> 23 #include <cassert> 24 25 #include "test_macros.h" 26 27 int main(int, char**) 28 { 29 using month = std::chrono::month; 30 using year = std::chrono::year; 31 using year_month = std::chrono::year_month; 32 33 constexpr month February = std::chrono::February; 34 35 { // operator/(const year& y, const month& m) 36 ASSERT_NOEXCEPT ( year{2018}/February); 37 ASSERT_SAME_TYPE(year_month, decltype(year{2018}/February)); 38 39 static_assert((year{2018}/February).year() == year{2018}, ""); 40 static_assert((year{2018}/February).month() == month{2}, ""); 41 for (int i = 1000; i <= 1030; ++i) 42 for (unsigned j = 1; j <= 12; ++j) 43 { 44 year_month ym = year{i}/month{j}; 45 assert(static_cast<int>(ym.year()) == i); 46 assert(static_cast<unsigned>(ym.month()) == j); 47 } 48 } 49 50 51 { // operator/(const year& y, const int m) 52 ASSERT_NOEXCEPT ( year{2018}/4); 53 ASSERT_SAME_TYPE(year_month, decltype(year{2018}/4)); 54 55 static_assert((year{2018}/2).year() == year{2018}, ""); 56 static_assert((year{2018}/2).month() == month{2}, ""); 57 58 for (int i = 1000; i <= 1030; ++i) 59 for (unsigned j = 1; j <= 12; ++j) 60 { 61 year_month ym = year{i}/j; 62 assert(static_cast<int>(ym.year()) == i); 63 assert(static_cast<unsigned>(ym.month()) == j); 64 } 65 } 66 67 return 0; 68 } 69