Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 791 Bytes

equal_range.md

File metadata and controls

21 lines (17 loc) · 791 Bytes

equal_range

Description : Returns the bounds of the subrange that includes all the elements of the range [first, last) with values equivalent to passed value.

Example:

    std::vector<int> vec = {1, 2, 3, 1, 6, 1};
    // equal_range requires a sorted input {1, 1, 1, 2, 3, 6}
    std::sort(vec.begin(), vec.end());

    // returns pair of iterators for positions 0 and 2:
    // {1, 1, 1, 2, 3, 6}
    //  ^        ^
    auto equalRangeIt = std::equal_range(vec.begin(), vec.end(), 1); 
    for (auto it = equalRangeIt.first; it != equalRangeIt.second; ++it) {
        std::cout << " Position: " << (it - vec.begin()) << " = " << *it << std::endl;
    }

See Sample code Run Code