In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "what is the variable template parameter in the difficulty analysis of the new C++ standard". In the operation of actual cases, many people will encounter such a dilemma. Next, 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!
Preface
C++ 's new feature-variable template parameters (variadic templates) is one of the most powerful new features of C++. It highly generalizes the parameters and can represent 0 to any number of parameters of any type. Compared with Category 98amp 03, class templates and function templates can only contain a fixed number of template parameters, variable template parameters is undoubtedly a great improvement. However, because the variable template parameters are abstract and require some skills to use, it is also one of the most difficult features in C++ to understand and master. Although it is difficult to master variable template parameters, it is one of the most interesting features in Cellular template 11.
Expansion of variable template parameters
The semantics of the variable parameter template is the same as that of the ordinary template, except that it is slightly different in writing. When declaring a variable parameter template, you need to put an ellipsis "..." after typename or class. For example, we often declare a variable template parameter: template
Template void f (T... Args)
The role of the ellipsis:
1. Declare a parameter package T... Args, this parameter package can contain 0 to any template parameters; 2. On the right side of the template definition, you can expand the parameter package into a separate parameter.
The parameter of the ellipsis is called the "parameter package", which contains 0 to N (N > = 0) template parameters. We can not get every parameter in the parameter package args directly, we can only obtain each parameter in the parameter package by expanding the parameter package, which is one of the main characteristics of using variable template parameters, and it is also the biggest difficulty, that is, how to expand variable template parameters.
Variable template parameter classification:
1. Variable template parameter function
two。 Variable template parameter class
Print the number of parameters of the variable template parameter function
# include # include using namespace std; template void print (Type... data) {cout
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: 226
*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.