constexpr bool ok() const noexcept;
(since C++20)Checks if the year value stored in *this is in the valid range, i.e., [
-32767,
32767]
.
true if the year value stored in *this is in the range [
-32767,
32767]
. Otherwise false.
See the implementations in libstdc++, libc++, and Howard Hinnant's date.h.
class Year { short year_; // exposition-only public: bool ok() const noexcept { return year_ != std::numeric_limits<short>::min(); } /*...*/ };[edit] Example
#include <chrono> #include <iomanip> #include <iostream> int main() { std::cout << "input year â internal value â ok()\n" << std::boolalpha; for (const int i : {2020, 0x8000, 0x8001, 0xFFFF, 0x18000}) { const std::chrono::year y{i}; std::cout << std::setw(10) << i << " â " << std::setw(14) << static_cast<int>(y) << " â " << y.ok() << '\n'; } }
Possible output:
input year â internal value â ok() 2020 â 2020 â true 32768 â -32768 â false 32769 â -32767 â true 65535 â -1 â true 98304 â -32768 â false
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4