In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the "example analysis of the emplace members of the Craft 11 container". In the daily operation, I believe that many people have doubts in the example analysis of the emplace members of the container. The editor has consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts of the emplace members of the container. Next, please follow the editor to study!
Consider the following Rect classes:
Struct Rect
{
Rect (int l, int t, int r, int b)
: left {l}, top {t}
, right {r}, bottom {b}
{}
Int left
Int top
Int right
Int bottom
}
When you need to add a Rect object to a container, the code looks something like this:
Std::list rlist
Rlist.push_front (Rect (10,10,20,20))
When you call push_front, you first construct a temporary Rect object and pass it to the push_front method, and then, inside the push_front, you copy a Rect object and add it to the container. A create action and a copy action occur throughout the process to add the contents of the object to the list.
Emplace member
In order to reduce the number of copy actions, of course, you can use the right value to refer to the parameter's member function. In addition, emplace membership 11 provides another method: members of the client. Using this member, you can directly pass the parameters used to generate the object, and leave the creation process of the object to the container to execute:
Std::list rlist
Rlist.emplace_front (10, 10, 20, 20)
The usage is very simple, as long as the parameters are the same as those of the element constructor.
In addition to emplace_front, clipping 11 also provides emplace and emplace_bak methods, corresponding to insert and push_back methods, respectively.
Emplace semantics
In order to better understand and explain emplace, first go to Baidu to check, the results are as follows:
At this point, the study on the "example analysis of emplace members of Clear11 container" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.