Can range based for loop work over a range

前端 未结 4 1034
醉梦人生
醉梦人生 2021-01-04 21:04

If I have range (pair of 2 iterators) is there a way to write \"for each\" loop for that uses range, not a raw array or container.

Something like this:



        
4条回答
  •  心在旅途
    2021-01-04 21:45

    What std::equal_range returns is simply a std::pair. The standard doesn't cover any method to iterate over such things.

    What you may want to read is Alexandrescu's "Iterators must go" presentation. Here is the video. An excellent read on a more elegant way to iterate containers using Ranges.

    Ranges are implemented in his Loki library.

提交回复
热议问题