comparisons.pass.cpp (3222B)
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 operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept; 15 // Returns: x.year() == y.year() && x.month_day_last() == y.month_day_last(). 16 // 17 // constexpr bool operator< (const year_month_day_last& x, const year_month_day_last& y) noexcept; 18 // Returns: 19 // If x.year() < y.year(), returns true. 20 // Otherwise, if x.year() > y.year(), returns false. 21 // Otherwise, returns x.month_day_last() < y.month_day_last() 22 23 #include <chrono> 24 #include <type_traits> 25 #include <cassert> 26 27 #include "test_macros.h" 28 #include "test_comparisons.h" 29 30 int main() 31 { 32 using year = std::chrono::year; 33 using month = std::chrono::month; 34 using month_day_last = std::chrono::month_day_last; 35 using year_month_day_last = std::chrono::year_month_day_last; 36 37 AssertComparisons6AreNoexcept<year_month_day_last>(); 38 AssertComparisons6ReturnBool<year_month_day_last>(); 39 40 constexpr month January = std::chrono::January; 41 constexpr month February = std::chrono::February; 42 43 static_assert( testComparisons6( 44 year_month_day_last{year{1234}, month_day_last{January}}, 45 year_month_day_last{year{1234}, month_day_last{January}}, 46 true, false), ""); 47 48 // different month 49 static_assert( testComparisons6( 50 year_month_day_last{year{1234}, month_day_last{January}}, 51 year_month_day_last{year{1234}, month_day_last{February}}, 52 false, true), ""); 53 54 // different year 55 static_assert( testComparisons6( 56 year_month_day_last{year{1234}, month_day_last{January}}, 57 year_month_day_last{year{1235}, month_day_last{January}}, 58 false, true), ""); 59 60 // different month 61 static_assert( testComparisons6( 62 year_month_day_last{year{1234}, month_day_last{January}}, 63 year_month_day_last{year{1234}, month_day_last{February}}, 64 false, true), ""); 65 66 // different year and month 67 static_assert( testComparisons6( 68 year_month_day_last{year{1234}, month_day_last{February}}, 69 year_month_day_last{year{1235}, month_day_last{January}}, 70 false, true), ""); 71 72 // same year, different months 73 for (unsigned i = 1; i < 12; ++i) 74 for (unsigned j = 1; j < 12; ++j) 75 assert((testComparisons6( 76 year_month_day_last{year{1234}, month_day_last{month{i}}}, 77 year_month_day_last{year{1234}, month_day_last{month{j}}}, 78 i == j, i < j ))); 79 80 // same month, different years 81 for (int i = 1000; i < 20; ++i) 82 for (int j = 1000; j < 20; ++j) 83 assert((testComparisons6( 84 year_month_day_last{year{i}, month_day_last{January}}, 85 year_month_day_last{year{j}, month_day_last{January}}, 86 i == j, i < j ))); 87 }