62 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;12 13// constexpr weekday_indexed operator[](unsigned index) const noexcept;14// constexpr weekday_last operator[](last_spec) const noexcept;15 16 17#include <chrono>18#include <cassert>19#include <type_traits>20#include <utility>21 22#include "test_macros.h"23#include "../../euclidian.h"24 25int main(int, char**)26{27 using weekday = std::chrono::weekday;28 using weekday_last = std::chrono::weekday_last;29 using weekday_indexed = std::chrono::weekday_indexed;30 31 constexpr weekday Sunday = std::chrono::Sunday;32 33 ASSERT_NOEXCEPT( std::declval<weekday>()[1U]);34 ASSERT_SAME_TYPE(weekday_indexed, decltype(std::declval<weekday>()[1U]));35 36 ASSERT_NOEXCEPT( std::declval<weekday>()[std::chrono::last]);37 ASSERT_SAME_TYPE(weekday_last, decltype(std::declval<weekday>()[std::chrono::last]));38 39 static_assert(Sunday[2].weekday() == Sunday, "");40 static_assert(Sunday[2].index () == 2, "");41 42 for (unsigned i = 0; i <= 6; ++i)43 {44 weekday wd(i);45 weekday_last wdl = wd[std::chrono::last];46 assert(wdl.weekday() == wd);47 assert(wdl.ok());48 }49 50 for (unsigned i = 0; i <= 6; ++i)51 for (unsigned j = 1; j <= 5; ++j)52 {53 weekday wd(i);54 weekday_indexed wdi = wd[j];55 assert(wdi.weekday() == wd);56 assert(wdi.index() == j);57 assert(wdi.ok());58 }59 60 return 0;61}62