当前位置:网站首页>Clause 33: decltype is used for auto & type formal parameters, with std:: forward
Clause 33: decltype is used for auto & type formal parameters, with std:: forward
2022-06-13 04:56:00 【CCSUZB】
Pantomorphism lambda The formula is C++14 One of the characteristics of :lambda Can be used in formal parameters auto:
auto f = [](auto x) {
return func(normalize(x));};
Above lambda Type of x The only action taken is to forward to normalize. If normalize Treat left and right values differently , Then we can say lambda Style writing is problematic . The correct way to write is to put x Perfect forward to normalize, Two changes are required in the code :1:x Change to universal quotation ,2: Use std::forward
auto f = [](auto && x)
{
return func(normalize(std::forward<???>(x)));};
The above says ??? How to implement it ? That is, pass it on to std::forward What type of formal parameter should be of .
General situation , When using perfect forwarding , You are in a accept type parameter T In the template function of , So you write std::forward<T> Just go . And in generics lambda in , No type parameters available T.
The solution is that we are lambda Can be detected by x The type of , To determine whether the passed in argument is Left value or right value .decltype It can be done .
auto f = [](auto && x)
{
return func(normalize(std::forward<decltype<x>>(x)));};
边栏推荐
- 2022 question bank and answers for operation certificate examination of safety production management personnel in road transport enterprises
- 2022氯化工艺操作证考试题库及模拟考试
- Clause 26: avoid overloading universal reference types
- 2021tami/ image processing: exploiting deep generative priority for versatile image restoration and manipulation
- Internet people a few years ago vs Internet people today
- Trust programming - linked lists: use struct to implement linked lists, use heap to merge K ascending linked lists, and customize display
- Design system based on MVC using javeswingjdbc
- Powershell 加域 Add-Computer模块
- Swiper plug-in
- C disk lossless move file
猜你喜欢
随机推荐
详解OpenCV的函数cv::add(),并附各种情况的示例代码和运行结果
Section 2 - branch and loop statements
[try to hack] upload labs (temporarily write to 12)
QT interface rendering style
Colab使用教程(超级详细版)及Colab Pro/Pro+评测
Brick story
[JS solution] leedcode 117 Populate the next right node pointer II for each node
Autumn wind, dust, youth
The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes
Kaggle time series tutorial
What is the difference between ROM, ram and flash? SRAM、DRAM、PROM、EPROM、EEPROM
What is the saturate operation in opencv
SQL notes
Embedded hardware: electronic components (1) resistance capacitance inductance
利用Javeswingjdbc基於mvc設計系統
[untitled]
Tita绩效宝:远程一对一面谈的问题
Chinese trumpet creeper
2022氯化工艺操作证考试题库及模拟考试
Spread your wings and soar



![[LeetCode]-二分查找](/img/7f/7d1f616c491c6fb0be93f591da6df1.png)





