C + + standard library function Equal_range ()

Source: Internet
Author: User

First, the elements in the container (vector) are ordered. The use of container element types as built-in types is not spoken here, because it is easier.

Focus on the use of the container element type when it is a custom type. When we pass the value of the type of the data member of the custom type to the third parameter of Equal_range, I have to define a public one with the constructor for the passed-in parameter. The purpose is to make the value of the type implicitly convertible to the custom type. Therefore, a constructor with the type parameter cannot be explicit. Such as:

1 classs{2  Public:3SConst string&s) {}4      stringISBN ()5 {6              returnBookno_;7 }8 .......9 Private:Ten     stringBookno_; One }; A  - BOOLCompConsts& RHS,Consts&LHS) - { the      returnRHS.ISBN () <LHS.ISBN (); - } -  - intMain () + { -Vector<s>vec{s1,s2,....}; +Auto Range (Vec.cbegin (), Vec.cend ()," Love", comp); A ............... at}

Where "Love" is the value to be passed in comp compared to the element in Vec, but comp's formal parameter is const s& so "Love" must be able to convert to S type.

C + + standard library function Equal_range ()

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.