brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.8 KiB · 31888b3 Raw
112 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 month_weekday;12 13// constexpr month_weekday14//   operator/(const month& m, const weekday_indexed& wdi) noexcept;15// Returns: {m, wdi}.16//17// constexpr month_weekday18//   operator/(int m, const weekday_indexed& wdi) noexcept;19// Returns: month(m) / wdi.20//21// constexpr month_weekday22//   operator/(const weekday_indexed& wdi, const month& m) noexcept;23// Returns: m / wdi. constexpr month_weekday24//25// constexpr month_weekday26//   operator/(const weekday_indexed& wdi, int m) noexcept;27// Returns: month(m) / wdi.28 29//30// [Example:31// constexpr auto mwd = February/Tuesday[3]; // mwd is the third Tuesday of February of an as yet unspecified year32//      static_assert(mwd.month() == February);33//      static_assert(mwd.weekday_indexed() == Tuesday[3]);34// -end example]35 36#include <chrono>37#include <type_traits>38#include <cassert>39 40#include "test_macros.h"41 42int main(int, char**)43{44    using month_weekday   = std::chrono::month_weekday;45    using month           = std::chrono::month;46    using weekday         = std::chrono::weekday;47    using weekday_indexed = std::chrono::weekday_indexed;48 49    constexpr weekday Tuesday = std::chrono::Tuesday;50    constexpr month February = std::chrono::February;51 52    { // operator/(const month& m, const weekday_indexed& wdi) (and switched)53        ASSERT_NOEXCEPT (February/Tuesday[2]);54        ASSERT_SAME_TYPE(month_weekday, decltype(February/Tuesday[2]));55        ASSERT_NOEXCEPT (Tuesday[2]/February);56        ASSERT_SAME_TYPE(month_weekday, decltype(Tuesday[2]/February));57 58    //  Run the example59        {60        constexpr month_weekday wdi = February/Tuesday[3];61        static_assert(wdi.month()           == February,   "");62        static_assert(wdi.weekday_indexed() == Tuesday[3], "");63        }64 65        for (int i = 1; i <= 12; ++i)66            for (unsigned j = 0; j <= 6; ++j)67                for (unsigned k = 1; k <= 5; ++k)68                {69                    month m(i);70                    weekday_indexed wdi = weekday{j}[k];71                    month_weekday mwd1 = m/wdi;72                    month_weekday mwd2 = wdi/m;73                    assert(mwd1.month() == m);74                    assert(mwd1.weekday_indexed() == wdi);75                    assert(mwd2.month() == m);76                    assert(mwd2.weekday_indexed() == wdi);77                    assert(mwd1 == mwd2);78                }79    }80 81 82    { // operator/(int m, const weekday_indexed& wdi) (and switched)83        ASSERT_NOEXCEPT (2/Tuesday[2]);84        ASSERT_SAME_TYPE(month_weekday, decltype(2/Tuesday[2]));85        ASSERT_NOEXCEPT (Tuesday[2]/2);86        ASSERT_SAME_TYPE(month_weekday, decltype(Tuesday[2]/2));87 88    //  Run the example89        {90        constexpr month_weekday wdi = 2/Tuesday[3];91        static_assert(wdi.month()           == February,   "");92        static_assert(wdi.weekday_indexed() == Tuesday[3], "");93        }94 95        for (int i = 1; i <= 12; ++i)96            for (unsigned j = 0; j <= 6; ++j)97                for (unsigned k = 1; k <= 5; ++k)98                {99                    weekday_indexed wdi = weekday{j}[k];100                    month_weekday mwd1 = i/wdi;101                    month_weekday mwd2 = wdi/i;102                    assert(mwd1.month() == month(i));103                    assert(mwd1.weekday_indexed() == wdi);104                    assert(mwd2.month() == month(i));105                    assert(mwd2.weekday_indexed() == wdi);106                    assert(mwd1 == mwd2);107                }108    }109 110  return 0;111}112