comparisons.pass.cpp (3126B)
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; 13 14 // constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept; 15 // Returns: x.month() == y.month() && x.day() == y.day(). 16 // 17 18 #include <chrono> 19 #include <type_traits> 20 #include <cassert> 21 22 #include "test_macros.h" 23 #include "test_comparisons.h" 24 25 int main() 26 { 27 using month_weekday = std::chrono::month_weekday; 28 using month = std::chrono::month; 29 using weekday_indexed = std::chrono::weekday_indexed; 30 using weekday = std::chrono::weekday; 31 32 constexpr weekday Sunday = std::chrono::Sunday; 33 constexpr weekday Monday = std::chrono::Monday; 34 35 AssertComparisons2AreNoexcept<month_weekday>(); 36 AssertComparisons2ReturnBool<month_weekday>(); 37 38 static_assert( testComparisons2( 39 month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}}, 40 month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}}, 41 true), ""); 42 43 static_assert( testComparisons2( 44 month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}}, 45 month_weekday{std::chrono::January, weekday_indexed{Sunday, 2}}, 46 false), ""); 47 48 static_assert( testComparisons2( 49 month_weekday{std::chrono::January, weekday_indexed{Sunday, 1}}, 50 month_weekday{std::chrono::February, weekday_indexed{Sunday, 1}}, 51 false), ""); 52 53 static_assert( testComparisons2( 54 month_weekday{std::chrono::January, weekday_indexed{Monday, 1}}, 55 month_weekday{std::chrono::January, weekday_indexed{Sunday, 2}}, 56 false), ""); 57 58 static_assert( testComparisons2( 59 month_weekday{std::chrono::January, weekday_indexed{Monday, 1}}, 60 month_weekday{std::chrono::February, weekday_indexed{Sunday, 1}}, 61 false), ""); 62 63 // same day, different months 64 for (unsigned i = 1; i < 12; ++i) 65 for (unsigned j = 1; j < 12; ++j) 66 assert((testComparisons2( 67 month_weekday{month{i}, weekday_indexed{Sunday, 1}}, 68 month_weekday{month{j}, weekday_indexed{Sunday, 1}}, 69 i == j))); 70 71 // same month, different weeks 72 for (unsigned i = 1; i < 5; ++i) 73 for (unsigned j = 1; j < 5; ++j) 74 assert((testComparisons2( 75 month_weekday{month{2}, weekday_indexed{Sunday, i}}, 76 month_weekday{month{2}, weekday_indexed{Sunday, j}}, 77 i == j))); 78 79 // same month, different days 80 for (unsigned i = 0; i < 6; ++i) 81 for (unsigned j = 0; j < 6; ++j) 82 assert((testComparisons2( 83 month_weekday{month{2}, weekday_indexed{weekday{i}, 2}}, 84 month_weekday{month{2}, weekday_indexed{weekday{j}, 2}}, 85 i == j))); 86 }