In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use C++ 's std::forward". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use C++ 's std::forward.
For parameters that are passed only but not handled, use the template type TP&& and use std::forwardReason when passing (reason)
If the object is to be passed onward to other code and not directly used by this function, we want to make this function agnostic to the argument const-ness and rvalue-ness.
If the object is not used within this function but continues to be passed to other code, we hope that this function will not change the constant and right value properties of the parameter.
Translator's note:
Consider the following functions:
String f (string&& s) {if (s.size ()) s [0] = toupper (s [0]); return s}
When the right value reference is used as a parameter type, it is first initialized by the argument, and the result is that the argument is invalidated (the definition of the right value reference). Inside the function, because s has captured the contents of the argument, it can be used freely as a left value. But if you do not use it directly in the function body and want to continue to pass it to another function as a right value, you cannot directly use s as an argument (because it has become a left value reference). Instead, you can use forward to restore its right value property.
In this case, it is only in this case (the right reference parameter is passed but not used) that the TP parameter is defined as TP&& (where TP is the template type)-- this ignores and maintains the constant and right-value properties. So any code that uses TP&& declares that it doesn't care about the constant and right properties of the variable (because it has been ignored), but continues to pass that value (unchanged) to other code that doesn't care about the constant and right properties (because these properties are maintained). Because any temporary object passed from the caller remains valid during the function call (because the caller has a chance to destroy the object only after the function call), it is safe when TP&& is used as a parameter (inside the function). Parameters of type TP&& should essentially always be passed through std::forward in the body of the function.
Translator's note: eventually, it has to be used as a left value by a piece of code.
Exampletemplate inline auto invoke (F f, Args&&...) Args) {return f (forward (args)...);} at this point, I believe you have a better understanding of "how to use C++ 's std::forward". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.