これについても、C++になったからといってとくに変わりませんので、基本は元ネタと同じようにすればOKです。ただし、若干そのままではうまくいかないところがありますので、その部分だけはケアしてあげることにしましょう。また、せっかくですのでconstexprを付けて定数式を得られるようにしましょう。
| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | constexpr bool is_summer_time(int month, int day, int w, int hour,                   int start_month, int start_n, int start_w, int start_hour,                   int end_month, int end_n, int end_w, int end_hour) {   if (month < start_month || end_month < month)     return false;   int w1 = (w + 36 - day) % 7;   if (month == start_month)   {     int dstday = nth_day_of_week_to_day(start_n, static_cast<day_of_week>(start_w), static_cast<day_of_week>(w1));     if(day < dstday || (day == dstday && hour < start_hour))       return false;   }   if (month == end_month)   {     int dstday = nth_day_of_week_to_day(end_n, static_cast<day_of_week>(end_w), static_cast<day_of_week>(w1));     if (day > dstday || (day == dstday && hour >= end_hour))       return false;   }   return true; } | 
元ネタではデバッグ用のコードや引数のエラーチェックが多数入っていました。それはそれでいいんですが、全体の見通しがききにくくなるので、思い切って全部削除して最低限のコードだけを残しました。また、内部で呼び出しているnth_day_of_week_to_day関数は10.3 ○月のN回目のW曜日は何日?で作成したものです。C言語ではint型から列挙型へは暗黙に変換できますが、C++では明示的に型変換する必要がありますので、上記ではキャストを行っています。






