#include #include using namespace std; //length::value is the number of days in month MONTH (1 to 12 inclusive). template struct length; template <> struct length< 1> {enum {value = 31};}; //january template <> struct length< 2> {enum {value = 28};}; //february template <> struct length< 3> {enum {value = 31};}; //march template <> struct length< 4> {enum {value = 30};}; //april template <> struct length< 5> {enum {value = 31};}; //may template <> struct length< 6> {enum {value = 30};}; //june template <> struct length< 7> {enum {value = 31};}; //july template <> struct length< 8> {enum {value = 31};}; //august template <> struct length< 9> {enum {value = 30};}; //september template <> struct length<10> {enum {value = 31};}; //october template <> struct length<11> {enum {value = 30};}; //november template <> struct length<12> {enum {value = 31};}; //december //j::month is the month (1 to 12 inclusive) and j::day is the day //of the month (1 to 31 inclusive) of Julian date J (1 to 365 inclusive). template class j { enum { d = j::day, m = j::month, same_month = d < length::value }; public: enum { month = same_month ? m : m + 1, day = same_month ? d + 1 : 1 }; }; template <> class j<1> { //Julian date 1 is january 1. public: enum { month = 1, day = 1 }; }; int main() { cout << j< 1>::month << " " << j< 1>::day << "\n" //january 1 << j< 31>::month << " " << j< 31>::day << "\n" //january 31 << j< 32>::month << " " << j< 32>::day << "\n" //february 1 << j<365>::month << " " << j<365>::day << "\n"; //december 31 return EXIT_SUCCESS; }