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 #include "test_comparisons.h" 27 28 int main(int, char**) 29 { 30 using month = std::chrono::month; 31 using year = std::chrono::year; 32 using year_month = std::chrono::year_month; 33 34 constexpr month February = std::chrono::February; 35 36 { // operator/(const year& y, const month& m) 37 ASSERT_NOEXCEPT ( year{2018}/February); 38 ASSERT_SAME_TYPE(year_month, decltype(year{2018}/February)); 39 40 static_assert((year{2018}/February).year() == year{2018}, ""); 41 static_assert((year{2018}/February).month() == month{2}, ""); 42 for (int i = 1000; i <= 1030; ++i) 43 for (unsigned j = 1; j <= 12; ++j) 44 { 45 year_month ym = year{i}/month{j}; 46 assert(static_cast<int>(ym.year()) == i); 47 assert(static_cast<unsigned>(ym.month()) == j); 48 } 49 } 50 51 52 { // operator/(const year& y, const int m) 53 ASSERT_NOEXCEPT ( year{2018}/4); 54 ASSERT_SAME_TYPE(year_month, decltype(year{2018}/4)); 55 56 static_assert((year{2018}/2).year() == year{2018}, ""); 57 static_assert((year{2018}/2).month() == month{2}, ""); 58 59 for (int i = 1000; i <= 1030; ++i) 60 for (unsigned j = 1; j <= 12; ++j) 61 { 62 year_month ym = year{i}/j; 63 assert(static_cast<int>(ym.year()) == i); 64 assert(static_cast<unsigned>(ym.month()) == j); 65 } 66 } 67 68 return 0; 69 } 70