Path: blob/main/contrib/llvm-project/libcxx/include/__chrono/year.h
35262 views
// -*- C++ -*-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//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___CHRONO_YEAR_H10#define _LIBCPP___CHRONO_YEAR_H1112#include <__chrono/duration.h>13#include <__config>14#include <compare>15#include <limits>1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)18# pragma GCC system_header19#endif2021_LIBCPP_PUSH_MACROS22#include <__undef_macros>2324#if _LIBCPP_STD_VER >= 202526_LIBCPP_BEGIN_NAMESPACE_STD2728namespace chrono {2930class year {31private:32short __y_;3334public:35year() = default;36_LIBCPP_HIDE_FROM_ABI explicit inline constexpr year(int __val) noexcept : __y_(static_cast<short>(__val)) {}3738_LIBCPP_HIDE_FROM_ABI inline constexpr year& operator++() noexcept {39++__y_;40return *this;41}42_LIBCPP_HIDE_FROM_ABI inline constexpr year operator++(int) noexcept {43year __tmp = *this;44++(*this);45return __tmp;46}47_LIBCPP_HIDE_FROM_ABI inline constexpr year& operator--() noexcept {48--__y_;49return *this;50}51_LIBCPP_HIDE_FROM_ABI inline constexpr year operator--(int) noexcept {52year __tmp = *this;53--(*this);54return __tmp;55}56_LIBCPP_HIDE_FROM_ABI constexpr year& operator+=(const years& __dy) noexcept;57_LIBCPP_HIDE_FROM_ABI constexpr year& operator-=(const years& __dy) noexcept;58_LIBCPP_HIDE_FROM_ABI inline constexpr year operator+() const noexcept { return *this; }59_LIBCPP_HIDE_FROM_ABI inline constexpr year operator-() const noexcept { return year{-__y_}; }6061_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_leap() const noexcept {62return __y_ % 4 == 0 && (__y_ % 100 != 0 || __y_ % 400 == 0);63}64_LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator int() const noexcept { return __y_; }65_LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept;66_LIBCPP_HIDE_FROM_ABI static inline constexpr year min() noexcept { return year{-32767}; }67_LIBCPP_HIDE_FROM_ABI static inline constexpr year max() noexcept { return year{32767}; }68};6970_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const year& __lhs, const year& __rhs) noexcept {71return static_cast<int>(__lhs) == static_cast<int>(__rhs);72}7374_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const year& __lhs, const year& __rhs) noexcept {75return static_cast<int>(__lhs) <=> static_cast<int>(__rhs);76}7778_LIBCPP_HIDE_FROM_ABI inline constexpr year operator+(const year& __lhs, const years& __rhs) noexcept {79return year(static_cast<int>(__lhs) + __rhs.count());80}8182_LIBCPP_HIDE_FROM_ABI inline constexpr year operator+(const years& __lhs, const year& __rhs) noexcept {83return __rhs + __lhs;84}8586_LIBCPP_HIDE_FROM_ABI inline constexpr year operator-(const year& __lhs, const years& __rhs) noexcept {87return __lhs + -__rhs;88}8990_LIBCPP_HIDE_FROM_ABI inline constexpr years operator-(const year& __lhs, const year& __rhs) noexcept {91return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)};92}9394_LIBCPP_HIDE_FROM_ABI inline constexpr year& year::operator+=(const years& __dy) noexcept {95*this = *this + __dy;96return *this;97}9899_LIBCPP_HIDE_FROM_ABI inline constexpr year& year::operator-=(const years& __dy) noexcept {100*this = *this - __dy;101return *this;102}103104_LIBCPP_HIDE_FROM_ABI constexpr bool year::ok() const noexcept {105static_assert(static_cast<int>(std::numeric_limits<decltype(__y_)>::max()) == static_cast<int>(max()));106return static_cast<int>(min()) <= __y_;107}108109} // namespace chrono110111_LIBCPP_END_NAMESPACE_STD112113#endif // _LIBCPP_STD_VER >= 20114115_LIBCPP_POP_MACROS116117#endif // _LIBCPP___CHRONO_YEAR_H118119120