Q:

How to access a range/interval of keys in an ordered map in C++? 

I am trying to write an if-condition where I want to execute code depending on which elements of a map are accessed, e.g. for a map with 100 elements only for elements 26 to 74.  But I do not want to address specific keys but rather a certain fraction of the map.  Should I do this with the [] operator?  I tried 
if(map.size()/4 < iterator < map.size()*3/4){}

but this does not work.  

A:

Just get iterators to the beginning and end of the range you want to inspect like
auto it = std::next(map.begin(), map.size() / 4);
auto end = std::next(map.begin(), map.size() * 3 / 4);

and then you can iterate that range like
for (; it ! = end; ++it)
{
    // do stuff here
}

You don't even need the end iterator if you want to you a counter.   This saves you the cost of advancing the end iterator through the map which could make a difference, especially on larger maps.   That would look like
auto it = std::next(map.begin(), map.size() / 4);
auto end = map.size() / 2;
for (size_t counter = 0; counter < end; ++it, ++counter)
{
    // do stuff here
}

