From 32d6313607e299abcc812616aad54abf3a7a250a Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 1 May 2017 19:55:49 +0100 Subject: [PATCH] Improve example for ES.45 Fixes #895 --- CppCoreGuidelines.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index c9f4be7..7bbfa48 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -11076,9 +11076,11 @@ Unnamed constants embedded in expressions are easily overlooked and often hard t No, we don't all know that there are 12 months, numbered 1..12, in a year. Better: - constexpr int month_count = 12; // months are numbered 1..12 + // months are indexed 1..12 + constexpr int first_month = 1; + constexpr int last_month = 12; - for (int m = first_month; m <= month_count; ++m) // better + for (int m = first_month; m <= last_month; ++m) // better cout << month[m] << '\n'; Better still, don't expose constants: