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