In C++11, a range-based for loop has the following general syntax:
for ( range_declaration : range_expression ) loop_statement
To exemplify the various ways of using a range-based for loops, we will use the following functions that return sequences of elements:
std::vector<int> getRates()
{
return std::vector<int> {1, 1, 2, 3, 5, 8, 13};
}
std::multimap<int, bool> getRates2()
{
return std::multimap<int, bool> {
{ 1, true },
{ 1, true },
{ 2, false },
{ 3, true },
{ 5, true },
{ 8, false },
{ 13, true }
};
}