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
| #include <iostream>
template <int Year>
struct is_bissextile {
static const int value = (Year % 4 == 0 && Year % 100 != 0)
|| Year % 400 == 0;
};
template <int Month, int Year, int Result>
struct DAYS_TO_MONTH {
static const int days_in_month = ( Month == 4 || Month == 6 || Month == 9 || Month == 11 ) ? 30 : 31;
static const int value = DAYS_TO_MONTH<Month-1, Year, Result + days_in_month>::value;
};
template <int Year, int Result>
struct DAYS_TO_MONTH<2, Year, Result> {
static const int value = Result + 59 + is_bissextile<Year>::value;
};
template <int Year, int Result>
struct DAYS_TO_MONTH<0, Year, Result> {
static const int value = Result;
};
template <int Day, int Month, int Year>
struct DAY_OF_THE_YEAR {
static const int value = DAYS_TO_MONTH<Month-1, Year, Day>::value;
};
int main() {
std::cout << DAY_OF_THE_YEAR<31,12,1982>::value; // 365
} |
Partager