Lower_bound () and upper_bound () in STL ()

Source: Internet
Author: User
C ++ STL

Iterator lower_bound (const key_type & Key );

 

Iterator upper_bound (const key_type & Key );

Function Functions

Iterator lower_bound (const key_type & Key): returns an iterator pointingKey value>= Key.

Iterator upper_bound (const key_type & Key): returns an iterator pointingKey Value> Key.

 

Lower_bound () function

First version:

Template <class forwarditerator, class type>

Forwarditerator

Lower_bound (forwarditerator first,

Forwarditerator last, const type & value );

 

Version 2:

Template <class forwarditerator, class type, class compare>

Forwarditerator

Lower_bound (forwarditerator first,

Forwarditerator last, const type & value,

Compare comp );

Function Introduction

Lower_bound () returns an iterator that points toOrdered sequenceCan insert value, without disrupting the first position of the container order, and this position marksGreater than or equalValue.

 

For example, there are the following sequences:

 

IA [] = };

 

Use Value 21 to call lower_bound () and return an iterator pointing to 22. Call lower_bound () with the value 22, and return an iterator pointing to 22. The first version uses the underlying <(less than) operator, and the second version performs sorting and comparison based on comp.

Notes

Before calling lower_bound, you must determine the sequence as an ordered sequence; otherwise, an error occurs in the call. The first version is sorted by the underlying <(less than) operator, and the second version is sorted by comp.

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.