comparisons.pass.cpp (2226B)
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; 13 14 // constexpr bool operator==(const month_day& x, const month_day& y) noexcept; 15 // Returns: x.month() == y.month() && x.day() == y.day(). 16 // 17 // constexpr bool operator< (const month_day& x, const month_day& y) noexcept; 18 // Returns: 19 // If x.month() < y.month() returns true. 20 // Otherwise, if x.month() > y.month() returns false. 21 // Otherwise, returns x.day() < y.day(). 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 day = std::chrono::day; 33 using month = std::chrono::month; 34 using month_day = std::chrono::month_day; 35 36 AssertComparisons6AreNoexcept<month_day>(); 37 AssertComparisons6ReturnBool<month_day>(); 38 39 static_assert( testComparisons6( 40 month_day{std::chrono::January, day{1}}, 41 month_day{std::chrono::January, day{1}}, 42 true, false), ""); 43 44 static_assert( testComparisons6( 45 month_day{std::chrono::January, day{1}}, 46 month_day{std::chrono::January, day{2}}, 47 false, true), ""); 48 49 static_assert( testComparisons6( 50 month_day{std::chrono::January, day{1}}, 51 month_day{std::chrono::February, day{1}}, 52 false, true), ""); 53 54 // same day, different months 55 for (unsigned i = 1; i < 12; ++i) 56 for (unsigned j = 1; j < 12; ++j) 57 assert((testComparisons6( 58 month_day{month{i}, day{1}}, 59 month_day{month{j}, day{1}}, 60 i == j, i < j ))); 61 62 // same month, different days 63 for (unsigned i = 1; i < 31; ++i) 64 for (unsigned j = 1; j < 31; ++j) 65 assert((testComparisons6( 66 month_day{month{2}, day{i}}, 67 month_day{month{2}, day{j}}, 68 i == j, i < j ))); 69 70 }