In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how C++ uses function templates to infer class template parameter types". The explanation in this article is simple and clear and easy to learn and understand. Please follow the editor's train of thought slowly and deeply. Let's study and learn "C++ how to use function templates to infer class template parameter types"!
T.44: use function templates to infer class template parameter types (if possible)
Reason (reason)
Writing the template argument types explicitly can be tedious and unnecessarily verbose.
Display input template parameter types are lengthy and unnecessary.
Example (sample)
Tuple T1 = {1, "Hamlet", 3.14}; / / explicit type
Auto T2 = make_tuple (1, "Ophelia" s, 3.14); / / better; deduced type
Note the use of the s suffix to ensure that the string is a std::string, rather than a C-style string.
Note that you can ensure that string is a std::string rather than a C-style string by using the s suffix.
Note (Note)
Since you can trivially write a make_T function, so could the compiler. Thus, make_T functions might become redundant in the future.
You can write make_T functions directly, and so can the compiler. So the make_T function may become redundant in the future.
Exception (exception)
Sometimes there isn't a good way of getting the template arguments deduced and sometimes, you want to specify the arguments explicitly:
Sometimes, there is no appropriate way to implement template parameter inference, or it is possible that you want to explicitly define parameter types.
Vector v = {1,2,3,7.9,15.99}
List lst;Note (Note)
Note that Che 17 will make this rule redundant by allowing the template arguments to be deduced directly from constructor arguments: Template parameter deduction for constructors (Rev. 3). For example:
Note that template argument 17 will make this rule redundant because it allows template parameters to be inferred directly from constructor parameters: template parameter inference (Rev.3) for constructors. For example:
Tuple T1 = {1, "Hamlet" s, 3.14}; / / deduced: tupleEnforcement (implementation recommendation)
Flag uses where an explicitly specialized type exactly matches the types of the arguments used.
The tag shows an exact match between the defined type and the parameters actually used.
Thank you for your reading, the above is the content of "how C++ uses function templates to infer class template parameter types". After the study of this article, I believe you have a deeper understanding of how C++ uses function templates to infer class template parameter types, and the specific use still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.