home | help
std::chrono::year::ok(3)       C++ Standard Libary	std::chrono::year::ok(3)

NAME
     std::chrono::year::ok - std::chrono::year::ok

Synopsis
	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].

Return value
	true  if the year value stored in *this is in the range [-32767, 32767].
     Otherwise
	false.

Possible implementation
	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_lim-
     its<short>::min(); }

	    /*...*/
	};

Example
     // Run this code

      #include <chrono>
      #include <iomanip>
      #include <iostream>

      int main()
      {
	  std::cout << "input year a internal value a 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 << " a "
			<< std::setw(14) << static_cast<int>(y) << " a "
			<< y.ok() << '\n';
	  }
      }

Possible output:
      input year a internal value a ok()
	    2020 a	     2020 a true
	   32768 a	   -32768 a false
	   32769 a	   -32767 a true
	   65535 a	       -1 a true
	   98304 a	   -32768 a false

http://cppreference.com 	   2024.06.10		std::chrono::year::ok(3)

home | help