aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/include/__chrono/year.h
blob: c7f0027eba7b4e9dd6c2e6e9a0c5eba7e3eb3578 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___CHRONO_YEAR_H
#define _LIBCPP___CHRONO_YEAR_H

#include <__chrono/duration.h>
#include <__config>
#include <limits>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#  pragma GCC system_header
#endif

_LIBCPP_PUSH_MACROS
#include <__undef_macros>

#if _LIBCPP_STD_VER > 17

_LIBCPP_BEGIN_NAMESPACE_STD

namespace chrono
{

class year {
private:
    short __y;
public:
    _LIBCPP_HIDE_FROM_ABI year() = default;
    _LIBCPP_HIDE_FROM_ABI explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {}

    _LIBCPP_HIDE_FROM_ABI inline constexpr year& operator++()    noexcept { ++__y; return *this; }
    _LIBCPP_HIDE_FROM_ABI inline constexpr year  operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; }
    _LIBCPP_HIDE_FROM_ABI inline constexpr year& operator--()    noexcept { --__y; return *this; }
    _LIBCPP_HIDE_FROM_ABI inline constexpr year  operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; }
    _LIBCPP_HIDE_FROM_ABI        constexpr year& operator+=(const years& __dy) noexcept;
    _LIBCPP_HIDE_FROM_ABI        constexpr year& operator-=(const years& __dy) noexcept;
    _LIBCPP_HIDE_FROM_ABI inline constexpr year operator+() const noexcept { return *this; }
    _LIBCPP_HIDE_FROM_ABI inline constexpr year operator-() const noexcept { return year{-__y}; }

    _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); }
    _LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator int() const noexcept { return __y; }
    _LIBCPP_HIDE_FROM_ABI        constexpr bool ok() const noexcept;
    _LIBCPP_HIDE_FROM_ABI static inline constexpr year min() noexcept { return year{-32767}; }
    _LIBCPP_HIDE_FROM_ABI static inline constexpr year max() noexcept { return year{ 32767}; }
};


_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const year& __lhs, const year& __rhs) noexcept
{ return static_cast<int>(__lhs) == static_cast<int>(__rhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const year& __lhs, const year& __rhs) noexcept
{ return !(__lhs == __rhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator< (const year& __lhs, const year& __rhs) noexcept
{ return static_cast<int>(__lhs)  < static_cast<int>(__rhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator> (const year& __lhs, const year& __rhs) noexcept
{ return __rhs < __lhs; }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator<=(const year& __lhs, const year& __rhs) noexcept
{ return !(__rhs < __lhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator>=(const year& __lhs, const year& __rhs) noexcept
{ return !(__lhs < __rhs); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
year operator+ (const year& __lhs, const years& __rhs) noexcept
{ return year(static_cast<int>(__lhs) + __rhs.count()); }

_LIBCPP_HIDE_FROM_ABI inline constexpr
year operator+ (const years& __lhs, const year& __rhs) noexcept
{ return __rhs + __lhs; }

_LIBCPP_HIDE_FROM_ABI inline constexpr
year operator- (const year& __lhs, const years& __rhs) noexcept
{ return __lhs + -__rhs; }

_LIBCPP_HIDE_FROM_ABI inline constexpr
years operator-(const year& __lhs, const year& __rhs) noexcept
{ return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; }


_LIBCPP_HIDE_FROM_ABI inline constexpr
year& year::operator+=(const years& __dy) noexcept
{ *this = *this + __dy; return *this; }

_LIBCPP_HIDE_FROM_ABI inline constexpr
year& year::operator-=(const years& __dy) noexcept
{ *this = *this - __dy; return *this; }

_LIBCPP_HIDE_FROM_ABI constexpr bool year::ok() const noexcept {
  static_assert(static_cast<int>(std::numeric_limits<decltype(__y)>::max()) == static_cast<int>(max()));
  return static_cast<int>(min()) <= __y;
}

} // namespace chrono

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP_STD_VER > 17

_LIBCPP_POP_MACROS

#endif // _LIBCPP___CHRONO_YEAR_H