• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 weekday_indexed;
13 
14 //                     weekday_indexed() = default;
15 //  constexpr weekday_indexed(const chrono::weekday& wd, unsigned index) noexcept;
16 //
17 //  Effects: Constructs an object of type weekday_indexed by initializing wd_ with wd and index_ with index.
18 //    The values held are unspecified if !wd.ok() or index is not in the range [1, 5].
19 //
20 //  constexpr chrono::weekday weekday() const noexcept;
21 //  constexpr unsigned        index()   const noexcept;
22 //  constexpr bool ok()                 const noexcept;
23 
24 #include <chrono>
25 #include <type_traits>
26 #include <cassert>
27 
28 #include "test_macros.h"
29 
main()30 int main()
31 {
32     using weekday  = std::chrono::weekday;
33     using weekday_indexed = std::chrono::weekday_indexed;
34 
35     ASSERT_NOEXCEPT(weekday_indexed{});
36     ASSERT_NOEXCEPT(weekday_indexed(weekday{1}, 1));
37 
38     constexpr weekday_indexed wdi0{};
39     static_assert( wdi0.weekday() == weekday{}, "");
40     static_assert( wdi0.index() == 0,           "");
41     static_assert(!wdi0.ok(),                   "");
42 
43     constexpr weekday_indexed wdi1{std::chrono::Sunday, 2};
44     static_assert( wdi1.weekday() == std::chrono::Sunday, "");
45     static_assert( wdi1.index() == 2,                     "");
46     static_assert( wdi1.ok(),                             "");
47 
48     for (unsigned i = 1; i <= 5; ++i)
49     {
50         weekday_indexed wdi(std::chrono::Tuesday, i);
51         assert( wdi.weekday() == std::chrono::Tuesday);
52         assert( wdi.index() == i);
53         assert( wdi.ok());
54     }
55 
56     for (unsigned i = 6; i <= 20; ++i)
57     {
58         weekday_indexed wdi(std::chrono::Tuesday, i);
59         assert(!wdi.ok());
60     }
61 }
62