Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the mobile iterator of Clover 11?

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "what is the mobile iterator of Craft 11". Many people will encounter this 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!

Tracer bullets with high achievements and hard work

To illustrate whether to move the iterator or continue to invite tracer projectiles:

The class itself is simple: in each constructor, the assignment operator outputs log information.

Handing over individual data

The least efficient way

Code:

Program output:

As you can see, two constructors and one assignment are performed. By looking at the code, you can see that the copy action happened twice.

Improve efficiency by moving

Of course, we can reduce the assignment operation by calling the copy constructor, but after Clipper 11, we can use the move operation to more thoroughly improve the efficiency of program execution:

Code:

Program output:

As you can see, a constructor and a move constructor are executed. By looking at the code, you can see that the copy action only happened once. This change can undoubtedly greatly improve the efficiency of code execution.

Transfer multiple data

Simple approach

Without thinking about it, the code is roughly as follows:

Program output:

Constructor, default constructor, and copy constructor are executed 4 times respectively. Of course, the corresponding string copy operation is also carried out at the same time.

Mobile iterator

Code example:

The problem is similar to that of a single instance, with two redundant operations: the default constructor and the string copy. In response to the above questions, Clear11 gives the following answers:

The code first uses allocator to get the memory space of the saved object in advance without calling the initialization function.

Then use unitialize_copy to iterate over the constructor of each object. There are two more cases: if you simply use the usual iterator, the copy constructor will be called; and the make_move_iterator adapter used in this example tells the compiler that the iterative object can be moved, so the move constructor is called.

This iterator that can generate right-value references is the mobile iterator.

Program output:

As you can see, it achieves the same efficiency as a single instance.

This is the end of the content of "what is the Mobile iterator of Craft 11". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report