boost counting_range不包括迭代最后一个值

时间:2017-03-21 18:04:53

标签: for-loop boost for-range

我有这段代码:

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));
        }
    }
}

注意我已经将for个循环分别设置为 0 - 6 1 - 12 。我发现他们必须 0 - 7 1 - 13 。它迭代 UPTO 最后一个数字,它的鼻子包括最后一个数字本身!

所以这是误导性的:

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

请确认。

0 个答案:

没有答案