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