Debian Codegraph @

libcxx/test/std/time/time.cal/time.cal.weekday/time.cal.weekday.members/iso_encoding.pass.cpp

raw
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 weekday;
12
13 // constexpr unsigned iso_encoding() const noexcept;
14 // Returns the underlying weekday, _except_ that returns '7' for Sunday (zero)
15 // See [time.cal.wd.members]
16
17 #include <chrono>
18 #include <cassert>
19 #include <type_traits>
20 #include <utility>
21
22 #include "test_macros.h"
23
24 using weekday = std::chrono::weekday;
25
26 constexpr bool test() {
27 // This is different than all the other tests, because the '7' gets converted to
28 // a zero in the constructor, but then back to '7' by iso_encoding().
29 for (unsigned i = 0; i <= 10; ++i) {
30 weekday wd(i);
31 assert(wd.iso_encoding() == (i == 0 ? 7 : i));
32 }
33
34 return true;
35 }
36
37 int main(int, char**) {
38 ASSERT_NOEXCEPT(std::declval<weekday&>().iso_encoding());
39 ASSERT_SAME_TYPE(unsigned, decltype(std::declval<weekday&>().iso_encoding()));
40
41 test();
42 static_assert(test());
43
44 return 0;
45 }