Youtube - Back to Basics - Name Lookup and Overload Resolution in C++ - Mateusz Pusz - CppCon 2022

Back to Basics - Name Lookup and Overload Resolution in C++ - Mateusz Pusz - CppCon 2022

Transcription

 https://www.youtube.com/watch?v=iDX2d7poJnI&feature=youtu.be
 01:49

Pasted image 20231205165346.png

Pasted image 20231205165451.png
Pasted image 20231205165458.png
Pasted image 20231205165531.png

 03:02

Pasted image 20231205165659.png

 05:16

Pasted image 20231205165927.png

Unqualified name lookup

 14:36
Warning

  • [#] Unqualified name lookup examines the scopes, until it finds at least one declaration of any kind (does not have to be a function) with a matching name, at which time scopes traversing stops and no further scopes are examined.

Pasted image 20231205174054.png
Mas, se comentar func(int) compila normalmente
Pasted image 20231205174146.png

Pasted image 20231205175634.png

 17:21

Pasted image 20231205175728.png
PROBLEMA
Pasted image 20231205175744.png

Warning

unqualified name search in other scope too

 20:12

Pasted image 20231205184125.png

Argument-Dependent Lookup (ADL) or Konig lookup

#doubt Argument-Dependent Lookup (ADL) or Konig lookup

 20:25

Pasted image 20231205184358.png

Argument-Dependent Lookup (ADL) or Konig lookup

  • [#] Argument-Dependent Lookup (ADL) or Konig lookup is a set of rules for the lookup of unqualified function names. The algorithm tells the compiler to not just look at local scope, but also the namespaces that contain the argument's type. Unqualified function names are additionally looked up in the namespace of their arguments.

Warning

using expande antes da Argument-Dependent Lookup (ADL) or Konig lookup

Pasted image 20231205205821.png

hidden friend - friend nĂŁo faz parte oficialmente do namespace N2
Pasted image 20231205210859.png
Pasted image 20231205211738.png

 26:33

Pasted image 20231205211807.png
Pasted image 20231206175026.png

 28:03

Pasted image 20231206175047.png

 29:40

Pasted image 20231206175328.png

 30:35

Pasted image 20231206180016.png

 30:41

Pasted image 20231206180734.png

 32:02

Pasted image 20231206192058.png
Pasted image 20231206192103.png

 33:47

Pasted image 20231206193237.png

 35:09

Pasted image 20231206201353.png
![[cpp_patterns#Generic frameworks with customization points]]

 35:14
All work as expected

Pasted image 20231206201418.png

 37:34

Pasted image 20231206203842.png
Pasted image 20231206205251.png

 41:38

Pasted image 20231206205538.png

 42:11

#best-practices usar std::range::swap ao invés de std::swap

 44:15

Pasted image 20231206221208.png

 45:33

Pasted image 20231208111207.png

 53:36

Pasted image 20231208111739.png

Warning

#error-prone #best-practices Avoid functions templates specializations. When occurs overload resolution, the compiler select at first the best-matching in this order: (1) non-template, (2) primary function template, only after that, (3) specialization function template (even though specialization would be itself a perfect match! ). Specializations function templpate are not overloaded.

#recommended assistir este vĂ­deo
Pasted image 20231208123150.png