GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::chrono::year::is_leap(3) C++ Standard Libary std::chrono::year::is_leap(3)

std::chrono::year::is_leap - std::chrono::year::is_leap


constexpr bool is_leap() const noexcept; (since C++20)


Determines if *this represents a leap year in the proleptic Gregorian calendar.


*this represents a leap year if the stored year value


* is divisible by 4 and not divisible by 100; or
* is divisible by 400.


true if *this represents a leap year, otherwise false.

// Run this code


#include <iostream>
#include <chrono>


int main()
{
using namespace std::chrono_literals;
for (const std::chrono::year y : {2020y, 2021y, 2000y, 3000y}) {
if (const int iy{ static_cast<int>(y) }; y.is_leap()) {
std::cout << iy << " is a leap year because it is divisible by "
<< (iy % 400 == 0 ? "400\n" : "4 and not divisible by 100\n");
} else {
std::cout << iy << " is not a leap year\n";
}
}
}


2020 is a leap year because it is divisible by 4 and not divisible by 100
2021 is not a leap year
2000 is a leap year because it is divisible by 400
3000 is not a leap year

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.