Youtube - CppCon 2014 Scott Meyers Type Deduction and Why You Care

CppCon 2014: Scott Meyers "Type Deduction and Why You Care"

```toc min_depth: 2 max_depth: 6 ```
 https://www.youtube.com/watch?v=wQxj20X-tIU

Transcrição

 01:22

Pasted image 20231205061157.png

Rules for typing deduction

  1. If you have a pointer type or reference you deduce for
  2. on the other side, you passed by value
 03:59

Pasted image 20231205061751.png

C+ 11

 04:12

Pasted image 20231205062108.png

C++ 14

 05:32

Pasted image 20231205062258.png

 09:40

Pasted image 20231205062635.png

deduced type=tipo determinado
Param type=tipo do parâmetro da função
Geralmente ambos são diferentes

 12:08

Pasted image 20231205064047.png

 14:31

Pasted image 20231205064154.png

 15:010

Pasted image 20231205064337.png

Universal References

 17:06

Pasted image 20231205064542.png

Reference collapsing

Pasted image 20231205065531.png

Pasted image 20231205065541.png

Resumo para templates que usam universal reference:
lvalue => lvalue reference
rvalue =>rvalue reference

by-value parameters

 21:22

Pasted image 20231205070014.png

non-reference non-pointer autos

 22:36

Pasted image 20231205070149.png

 24:55

Pasted image 20231205085334.png

Repare que neste caso somente o ponteiro const foi ignorado.
By value => top level const is ignored
By reference is not ignored, o const é mantido.

Special Cases

 28:43

Pasted image 20231205090541.png

auto Type Deduction

 29:18

Pasted image 20231205090601.png

Auto Type Deduction

 31:13

Pasted image 20231205090935.png
ERRATA: era para ser int quando tem um elemento

Lambda Capture Type Deduction

 38:20

Pasted image 20231205092407.png

 39:07

Template type deduction, ams não ignora const

 39:58

Pasted image 20231205093623.png

lambda Capture Type Deduction

 41:16

Pasted image 20231205093751.png

lambda Capture Type Deduction (mutable)

 42:29

Pasted image 20231205095304.png

 43:33

Pasted image 20231205095446.png

 45:06

Pasted image 20231205095636.png

 46:25

Pasted image 20231205095750.png

 46:48

Pasted image 20231205095852.png

 47:58

Pasted image 20231205100311.png

Não use typeid
 49:54

Pasted image 20231205101020.png

Observe que os resultados com boost e typeid foram diferentes, apesar de não termos mudado o código.

 50:23

Pasted image 20231205133744.png

 51:25

Pasted image 20231205134003.png

 52:20

Pasted image 20231205134102.png

 54:42

Pasted image 20231205134723.png

 56:13

Pasted image 20231205134906.png

 57:58

Pasted image 20231205135053.png

 01:00:23

Pasted image 20231205135344.png

 01:00:37

Pasted image 20231206221410.png

#best-practices quando você escreve códigos usando decltype sem que ter muito cuidade como escreve o seu código, veja no exemplo acima, apenas a inclusão de 1 parêntese modificou o retorno da função

#best-practices Não use tipos dedutíveis para retorno da função, pois conduz a erros bastante difíceis de depurar, como o código acima. Exceção lambdas function no C++11

#to-check
Pasted image 20231206222646.png

Pasted image 20231206222756.png