当前位置:网站首页>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)));};
边栏推荐
- PostgreSQL Guide: Insider exploration (Chapter 7 heap tuples and index only scanning) - Notes
- Infinite cycle scrolling code Alibaba international station store decoration code base map scrolling black translucent display effect custom content decoration code full screen display
- What is the saturate operation in opencv
- 2022 chlorination process operation certificate examination question bank and simulation examination
- 2022年氧化工艺操作证考试题库及模拟考试
- How to implement a custom jdbc driver in only four steps?
- Section 3 - functions
- PowerDesigner easy to use
- 自动评教脚本使用的配置
- Recommended temporary online image compression tool
猜你喜欢

Solution to sudden font change in word document editing

Win8.1和Win10各自的優勢

Section 8 - Practical commissioning techniques
![[LeetCode]-二分查找](/img/7f/7d1f616c491c6fb0be93f591da6df1.png)
[LeetCode]-二分查找

Advanced C - Section 2 - pointers

Cesium:CesiumLab制作影像切片与切片加载

Several methods of identifying equivalent circuit of circuit drawing

Converting MySQL data to PostgreSQL with Navicat

The games that you've tasted

QT interface rendering style
随机推荐
QT using layout manager is invalid or abnormal
Section 6 - pointers
Cesium:cesiumlab makes image slices and loads slices
Force buckle 25 A group of K flipped linked lists
Gradient descent, learning rate
[JS solution] leedcode 117 Populate the next right node pointer II for each node
JS, how to add grid style
Crawler scrapy framework learning 2
E - Lucky Numbers
Clause 26: avoid overloading universal reference types
Colab使用教程(超级详细版)及Colab Pro/Pro+评测
Crawler scrapy framework learning 1
Develop go using vscode
Test question bank and online simulation test for special operation certificate of construction scaffolder (special type of construction work) in 2022
RuoYi-Cloud启动教程(手把手图文)
Tita绩效宝:远程一对一面谈的问题
Explain the role of key attribute in V-for
josephus problem
[LeetCode]-滑动窗口
约瑟夫问题