| 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_indexed; |
| 12 |
|
| 13 |
// constexpr bool ok() const noexcept; |
| 14 |
// Returns: wd_.ok() && 1 <= index_ && index_ <= 5 |
| 15 |
|
| 16 |
#include <chrono> |
| 17 |
#include <type_traits> |
| 18 |
#include <cassert> |
| 19 |
|
| 20 |
#include "test_macros.h" |
| 21 |
|
| 22 |
int main(int, char**) |
| 23 |
{ |
| 24 |
using weekday = std::chrono::weekday; |
| 25 |
using weekday_indexed = std::chrono::weekday_indexed; |
| 26 |
|
| 27 |
ASSERT_NOEXCEPT( std::declval<const weekday_indexed>().ok()); |
| 28 |
ASSERT_SAME_TYPE(bool, decltype(std::declval<const weekday_indexed>().ok())); |
| 29 |
|
| 30 |
static_assert(!weekday_indexed{}.ok(), ""); |
| 31 |
static_assert( weekday_indexed{std::chrono::Sunday, 2}.ok(), ""); |
| 32 |
|
| 33 |
assert(!(weekday_indexed(std::chrono::Tuesday, 0).ok())); |
| 34 |
for (unsigned i = 1; i <= 5; ++i) |
| 35 |
{ |
| 36 |
weekday_indexed wdi(std::chrono::Tuesday, i); |
| 37 |
assert( wdi.ok()); |
| 38 |
} |
| 39 |
|
| 40 |
for (unsigned i = 6; i <= 20; ++i) |
| 41 |
{ |
| 42 |
weekday_indexed wdi(std::chrono::Tuesday, i); |
| 43 |
assert(!wdi.ok()); |
| 44 |
} |
| 45 |
|
| 46 |
// Not a valid weekday |
| 47 |
assert(!(weekday_indexed(weekday{9U}, 1).ok())); |
| 48 |
|
| 49 |
return 0; |
| 50 |
} |