Notes about STL's interval _range

Source: Internet
Author: User

The pai_range Algorithm in STL returns a pair value range,
Vector <int> vec;
... // Vec initialize
Pair <vector <int >:: iterator, vector <int >:: iterator> range;
Range = pai_range (vec. begin (), vec. end (), value );
Range. first is the position of the smallest iterator that can insert values without changing the original sorting order, range. second is the maximum iterator location where values can be inserted without changing the original sorting order.
Actually, if value exists in vec, range. first is the iterator in vec pointing to the first value position, and range. second is the iterator pointing to the first position greater than the value in vec. if the search value is the last value in the container, range. second is container. end (). if there is no value in vec, range returns a 0 range, that is, range. first = range. second = point to the iterator (which may be vec) where the first value is greater than value. end, if all values in vec are smaller than value ).

Description on sgi.
Note that every _range may return an empty range; that is, it may return a pair both of whose elements are the same iterator.
Performance_range returns an empty range if and only if the range [first, last) contains no elements equivalent to value.
In this case it follows that there is only one position where value cocould be inserted without violating the range's
Ordering, so the return value is a pair both of whose elements are iterators that point to that position.
Description on http://www.cplusplus.com/reference/algorithm/equal_range/
If value is not equivalent to any value in the range, the subrange returned has a length of zero, with both iterators
Pointing to the nearest value greater than value, if any, or to last, if value compares greater than all the elements
In the range.
(However, relevant instructions are not found in the "c ++ standard library self-repair Tutorial and Reference Manual". It should be reasonable to say that there should be instructions, maybe they did not see them too quickly .)
It can be seen from the above that no value exists in vec. If you want to insert the value into vec, you can use range. insert second position (regardless of range. whether second points to), but for other purposes, consider the range when the value does not exist in the container. first = range. second.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.