In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "C++ variable parameter template deployment way is what", the article explains the content is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "C++ variable parameter template is what is the way to expand it!"
Variable parameter template (variadic templates) is one of the new powerful features of Category 11. It highly generalizes the template parameters and can represent 0 to any number of parameters of any type. Compared with the "antiquities" of these templates and function templates, which can only contain a fixed number of template parameters, variable template parameters are undoubtedly a great improvement.
If you are new to the variable parameter template, you may feel more abstract and not easy to use. The expansion of the template parameters is usually necessary when using the variable parameter template, so this article enumerates some common template deployment methods to help us have a preliminary understanding of the variable parameter template.
Definition of variable parameter template
The definition of a variable parameter template is similar to that of a normal template, which needs to be written with an ellipsis after typename or class. Here is a common variable parameter function template:
Template void func (T... Args) {/.}
The above function template parameter args is preceded by an ellipsis, so it is a variable template parameter called template parameter package (template parameter pack), which contains 0 to N template parameters, and we cannot directly obtain every parameter in args, we can only obtain each parameter in the parameter package by expanding the parameter package, which is also the focus of this article.
Expansion of parameter package
The way of parameter package deployment is keeping pace with the development of C++ language. We take the implementation of a variable parameter format print function as an example to list some common ways:
Recursive function expansion
# include void FormatPrint () {std::cout FormatPrint (), the output is as follows:
> albert@home-pc:/mnt/d/data/cpp/testtemplate$ good + testtemplate.cpp-- std=c++11albert@home-pc:/mnt/d/data/cpp/testtemplate$. / a.out [1] [2] [3] [4] [good] [2] [hello] [4] [110]
Comma expression expansion
# include template void FormatPrint (Args... Args) {(void) std::initializer_list {(std::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: 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.