Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the insert of Clear11 container

Shulou Source: shulou.com Published: 2022-06-01 19:11:52 09月30日 Update

This article introduces the knowledge of "how to use the insert of Clear11 container". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

From Central98 to Clear11

The insert method declaration in Clipper 98

Iterator insert (iterator position

Const value_type& val); void insert (iterator position

Size_type n

Const value_type& val); template

Void insert (iterator position

InputIterator first

InputIterator last)

The insert method in Clipper 11

Iterator insert (const_iterator position

Const value_type& val); iterator insert (const_iterator position

Size_type n

Const value_type& val); template

Iterator insert (const_iterator position

InputIterator first

InputIterator last); iterator insert (const_iterator position

Value_type&& val); iterator insert (const_iterator position

Initializer_list il)

Detail comparison

Add a single element

Iterator insert (const_iterator position

Const value_type& val)

The only change is that the parameter type of position has changed, with the same functionality but increased support for const_iterator. This change applies to all insert methods, which are not explained below.

Populate multiple elements

Iterator insert (const_iterator position

Size_type n

Const value_type& val)

This method can populate n val at a specified location. In addition to the parameters, the return value of the method changes from void to iterator, returning the location of the last added element. With this return value, it is convenient to populate the element in the same place. For example, the following code:

Std::list demo {1, 2, 3, 4, 5, 6}

Auto position = std::find (demo.begin (), demo.end (), 3)

For (int I = 0; I < 5; + + I) {

Position = demo.insert (position, 2, I)

}

For (int var: demo) {

Std::cout

Tags: Methods code elements support location content changes output containers parameters data more knowledge examples results caching mobile practical same learned Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL OPPO Reno Shulou Technology Huawei Shulou Information