0

I have this code:

void CMeetingScheduleAssistantApp::InitDateTransArrays()
{
    if (theApp.UseTranslationINI() || theApp.GetProgramLanguage() == LANGUAGE_MALAGASY)
    {
        CString strKey;

        // Days of the week
        for (auto const &i : boost::counting_range(0, 7))
        //for (int i = 0; i <= 6; i++)
        {
            strKey.Format(_T("Day%d"), i);
            // AJT v17.1.3 Now use our own methods
            m_aryDateTrans[DATE_TRANS_DAY].Add(GetStringFromTranslationINI(_T("Days"), strKey));
            m_aryDateTrans[DATE_TRANS_DAY_SHORT].Add(GetStringFromTranslationINI(_T("DaysAbbreviated"), strKey));
        }

        // Months of the year
        for (auto const &i : boost::counting_range(1, 13))
        //for(int i = 1; i <= 12; i++)
        {
            strKey.Format(_T("Month%d"), i);
            // AJT v17.1.3 Now use our own methods
            m_aryDateTrans[DATE_TRANS_MONTH].Add(GetStringFromTranslationINI(_T("Months"), strKey));
            m_aryDateTrans[DATE_TRANS_MONTH_SHORT].Add(GetStringFromTranslationINI(_T("MonthsAbbreviated"), strKey));
        }
    }
}

Notice the for loops I had then set to 0 - 6 and 1 - 12 respectively. I found out that they had to be 0 - 7 and 1 - 13. It iterates UPTO the last number, it doe snot include the last number itself!

So this is misleading:

http://www.boost.org/doc/libs/1_63_0/libs/range/doc/html/range/reference/ranges/counting_range.html

Please confirm.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • 1
    From [docs](http://www.boost.org/doc/libs/1_63_0/libs/range/doc/html/range/concepts/overview.html): "A Range provides iterators for accessing a half-open range [first,one_past_last) of elements..." This fits with how you iterate in c++ in general -- e.g. containers give you `begin()` and `end()`, and you don't dereference the end iterator. | To be honest, seeing `for (int i = 0; i <= 6; i++)` in c++ is a bit odd to me -- I'd expect `for(int i(0); i < 7; ++i)`. – Dan Mašek Mar 21 '17 at 20:07
  • Thanks. You have a link to that? – Andrew Truckle Mar 21 '17 at 20:08
  • 1
    It's in the comment - the second word. In the docs it's "Range Concepts > Overview". – Dan Mašek Mar 21 '17 at 20:12
  • @DanMašek Thanks. – Andrew Truckle Mar 21 '17 at 20:13

0 Answers0