当前位置:网站首页>Variable parameter expression
Variable parameter expression
2022-06-11 13:30:00 【Hair like snow ty】
There is a template function as follows
template<typename...T>
auto print_result(T... args)
{
(cout << ... << args) << " end " << endl;
return (... + args);
}
int main()
{
cout << print_result(10, 20, 30, 40) << endl;
system("pause");
return 0;
}
result :
Now there is a need , You want the value of each parameter to expand the original 2 times , Then we add each other . To solve this problem , A better way is to introduce an intermediate function template , as follows :
template<typename...T>
auto print_calc(T... args)
{
return print_result(2 * args ...);
}
In the above example 2args… This way of writing , It's actually a variable parameter expression , Equivalent to print_result(210,220,230,2*40);
int main()
{
cout << print_result(10, 20, 30, 40) << endl;
cout << print_calc(10, 20, 30, 40) << endl;
system("pause");
return 0;
}
result :
边栏推荐
- On the continuing Life of Distributed Locks - - Distributed Locks Based on redis
- InfoQ 极客传媒 15 周年庆征文|移动端开发之动态排行【MUI+Flask+MongoDB】
- Introduction to common fonts
- QQ pulls up Alipay H5 payment function
- vim二次替换
- AGV机器人RFID传感器CK-G06A与西门子1200PLC应用手册
- On the life extension of distributed locks -- redis based distributed locks
- cadence SPB17.4 - group operation(add to group, view group list, delete group)
- NFT市场怎么样 为什么NFT能如此火爆 怎么搭建NFT平台
- Flink 从实时计算到流式数仓,下一步去往哪里?
猜你喜欢

历史上的今天:Apple II 问世;微软收购 GECAD;发明“软件工程”一词的科技先驱出生...

二十八-三维点云实时和离线生成二维栅格、三维栅格地图

常用字体介绍
![[signal processing] digital signal processing matlab design with GUI interface and report](/img/bd/7bcb03b5619998dda4c07bbf6d6436.png)
[signal processing] digital signal processing matlab design with GUI interface and report

Teatalk · online speech record | complete! It is important to select the right data migration strategy for safe cloud deployment

看不懂Kotlin源码?从Contracts 函数说起~

Some transformation thoughts of programmers after they are 35 years old
![InfoQ geek media's 15th anniversary essay solicitation - dynamic ranking of mobile terminal development [mui+flask+mongodb]](/img/92/50a92eb6b5c2ac3f58c499796a1e8c.png)
InfoQ geek media's 15th anniversary essay solicitation - dynamic ranking of mobile terminal development [mui+flask+mongodb]

Today in history: Apple II comes out; Microsoft acquires gecad; The scientific and technological pioneer who invented the word "software engineering" was born

The application of machine learning in database cardinality estimation
随机推荐
Checkout design in SAP Spartacus
InfoQ geek media's 15th anniversary essay solicitation - dynamic ranking of mobile terminal development [mui+flask+mongodb]
看不懂Kotlin源码?从Contracts 函数说起~
Microsoft exposes another "scandal": watching VR porn in the office, "the father of hololens" is about to leave!
JDBC connection pool is used for batch import. 5million data are run each time, but various problems will occur in the middle
关于#php#的问题:php写的原来的部署环境是在phpstudy里面进行部署的,php+MySQL+Apache但是由于每次都得保证电脑开着
阿里一面,谈谈策略模式在项目中的使用
tf. Data (II) -- parallelization tf data. Dataset generator
Hashicopy之nomad应用编排方案07(提交Job)
Kubernetes binary installation (v1.20.15) (VI) deploying worknode nodes
为什么每运行一部都显示一次数据库已存在,都要删除数据库,然后才能成功,每运行一部都要删除一次数据库,重新运行整体才成功.
Introduction to common fonts
Application choreography nomad vs. kubernetes
苹果将造搜索引擎?
SQL: how to use the data of purchase order and sales order to calculate commodity cost by moving weighted average method
vim二次替换
Network information system emergency response
[signal processing] digital signal processing matlab design with GUI interface and report
【Multisim仿真】555闪灯实验
[the path of system analyst] collection of wrong topics of system analyst