• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 month_weekday_last;
12 
13 // constexpr bool ok() const noexcept;
14 //  Returns: m_.ok() && wdl_.ok().
15 
16 #include <chrono>
17 #include <type_traits>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 
main(int,char **)22 int main(int, char**)
23 {
24     using month              = std::chrono::month;
25     using weekday            = std::chrono::weekday;
26     using weekday_last       = std::chrono::weekday_last;
27     using month_weekday_last = std::chrono::month_weekday_last;
28 
29     constexpr month January            = std::chrono::January;
30     constexpr weekday Tuesday          = std::chrono::Tuesday;
31     constexpr weekday_last lastTuesday = weekday_last{Tuesday};
32 
33     ASSERT_NOEXCEPT(                std::declval<const month_weekday_last>().ok());
34     ASSERT_SAME_TYPE(bool, decltype(std::declval<const month_weekday_last>().ok()));
35 
36     static_assert(!month_weekday_last{month{}, lastTuesday}.ok(),               ""); // Bad month
37     static_assert(!month_weekday_last{January, weekday_last{weekday{12}}}.ok(), ""); // Bad month
38     static_assert( month_weekday_last{January, lastTuesday}.ok(),               ""); // Both OK
39 
40     for (unsigned i = 0; i <= 50; ++i)
41     {
42         month_weekday_last mwdl{month{i}, lastTuesday};
43         assert( mwdl.ok() == month{i}.ok());
44     }
45 
46     for (unsigned i = 0; i <= 50; ++i)
47     {
48         month_weekday_last mwdl{January, weekday_last{weekday{i}}};
49         assert( mwdl.ok() == weekday_last{weekday{i}}.ok());
50     }
51 
52   return 0;
53 }
54