- the worst feature of modern c++: default behavior di… · the worst feature of modern c++:...
TRANSCRIPT
![Page 1: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/1.jpg)
The worst feature of modern C++: default behavior
Marcin Grzebieluch
21.11.2017
grzebiel 21.11.2017 1 / 77
![Page 2: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/2.jpg)
The worst feature of modern C++: default behavior
Marcin Grzebieluch
21.11.2017
grzebiel 21.11.2017 2 / 77
![Page 3: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/3.jpg)
Questions
grzebiel 21.11.2017 3 / 77
![Page 4: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/4.jpg)
Plan
1 auto
2 decltype
3 default args
4 rvalue reference
5 syntax
grzebiel 21.11.2017 4 / 77
![Page 5: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/5.jpg)
1 auto
2 decltype
3 default args
4 rvalue reference
5 syntax
auto grzebiel 21.11.2017 5 / 77
![Page 6: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/6.jpg)
first use of c++11 auto1 #include <cassert>2 int& referenceToInt();34 void modifyFoo()5 {6 auto x = referenceToInt();7 x = 5;8 }9
10 int main()11 {12 modifyFoo();13 assert(referenceToInt() == 5);14 return 0;15 }
auto grzebiel 21.11.2017 6 / 77
![Page 7: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/7.jpg)
first use of c++11 auto1 #include <cassert>2 int& referenceToInt();34 void modifyFoo()5 {6 auto x = referenceToInt();7 x = 5;8 }9
10 int main()11 {12 modifyFoo();13 assert(referenceToInt() == 5);14 return 0;15 }
auto grzebiel 21.11.2017 6 / 77
![Page 8: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/8.jpg)
first use of c++11 auto1 #include <cassert>2 int& referenceToInt();34 void modifyFoo()5 {6 auto x = referenceToInt();7 x = 5;8 }9
10 int main()11 {12 modifyFoo();13 assert(referenceToInt() == 5);14 return 0;15 }
auto grzebiel 21.11.2017 6 / 77
![Page 9: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/9.jpg)
first use of c++11 auto1 #include <cassert>2 int& referenceToInt();34 void modifyFoo()5 {6 auto x = referenceToInt();7 x = 5;8 }9
10 int main()11 {12 modifyFoo();13 assert(referenceToInt() == 5);14 return 0;15 }
auto grzebiel 21.11.2017 6 / 77
![Page 10: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/10.jpg)
first use of c++11 auto1 #include <cassert>2 int& referenceToInt();34 void modifyFoo()5 {6 auto x = referenceToInt();7 x = 5;8 }9
10 int main()11 {12 modifyFoo();13 assert(referenceToInt() == 5);14 return 0;15 }
auto grzebiel 21.11.2017 6 / 77
![Page 11: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/11.jpg)
cpp11 standard:Once the type of a declarator-id has been determinedaccording to 8.3, the type of the declared variable using thedeclarator-id is determined from the type of itsinitializer using the rules for template argumentdeduction.
auto grzebiel 21.11.2017 7 / 77
![Page 12: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/12.jpg)
cpp11 standard:If template parameter type P is a reference type, the typereferred to by P is used for type deduction.
auto grzebiel 21.11.2017 8 / 77
![Page 13: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/13.jpg)
lets fix code1 #include <cassert>2 int& referenceToInt();34 void modifyFoo()5 {6 auto x = referenceToInt();7 x = 5;8 }9
10 int main()11 {12 modifyFoo();13 assert(referenceToInt() == 5);14 return 0;15 }
auto grzebiel 21.11.2017 9 / 77
![Page 14: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/14.jpg)
lets fix code1 #include <cassert>2 int& referenceToInt();34 void modifyFoo()5 {6 auto x = referenceToInt();7 x = 5;8 }9
10 int main()11 {12 modifyFoo();13 assert(referenceToInt() == 5);14 return 0;15 }
auto grzebiel 21.11.2017 9 / 77
![Page 15: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/15.jpg)
lets fix code1 #include <cassert>2 int& referenceToInt();34 void modifyFoo()5 {6 auto& x = referenceToInt();7 x = 5;8 }9
10 int main()11 {12 modifyFoo();13 assert(referenceToInt() == 5);14 return 0;15 }
auto grzebiel 21.11.2017 9 / 77
![Page 16: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/16.jpg)
what have I learned?
• before the usage, always read at leset 10 setencesabout the future
• auto does not deduce consts, references and volatiles
auto grzebiel 21.11.2017 10 / 77
![Page 17: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/17.jpg)
what have I learned?
• before the usage, always read at leset 10 setencesabout the future
• auto does not deduce consts, references and volatiles
auto grzebiel 21.11.2017 10 / 77
![Page 18: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/18.jpg)
what have I learned?
• before the usage, always read at leset 10 setencesabout the future
• auto does not deduce consts, references and volatiles
auto grzebiel 21.11.2017 10 / 77
![Page 19: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/19.jpg)
it was not only me!
auto grzebiel 21.11.2017 11 / 77
![Page 20: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/20.jpg)
it was not only me!
auto grzebiel 21.11.2017 11 / 77
![Page 21: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/21.jpg)
Lets imagine that we are in alternative universe in which:
1 int& foo();23 auto a = foo();4 // type of a would be int&
auto grzebiel 21.11.2017 12 / 77
![Page 22: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/22.jpg)
a magical place
https://en.wikipedia.org/wiki/File:Bliss.pngauto grzebiel 21.11.2017 13 / 77
![Page 23: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/23.jpg)
now it works1 #include <cassert>2 int& referenceToInt();34 void modifyFoo()5 {6 auto x = referenceToInt();7 x = 5;8 }9
10 int main()11 {12 modifyFoo();13 assert(referenceToInt() == 5);14 return 0;15 }
auto grzebiel 21.11.2017 14 / 77
![Page 24: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/24.jpg)
in this alternative world
1 int a = 5;2 int* b = &a;3 auto c = *b;4 ++c;5 assert(c != a);
auto grzebiel 21.11.2017 15 / 77
![Page 25: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/25.jpg)
in this alternative world
1 int a = 5;2 int* b = &a;3 auto c = *b;4 ++c;5 assert(c != a);
auto grzebiel 21.11.2017 15 / 77
![Page 26: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/26.jpg)
in this alternative world
1 int a = 5;2 int* b = &a;3 auto c = *b;4 ++c;5 assert(c != a);
auto grzebiel 21.11.2017 15 / 77
![Page 27: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/27.jpg)
in this alternative world
1 int a = 5;2 int* b = &a;3 auto c = *b;4 ++c;5 assert(c != a);
auto grzebiel 21.11.2017 15 / 77
![Page 28: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/28.jpg)
in this alternative world
1 int a = 5;2 int* b = &a;3 auto c = *b;4 ++c;5 assert(c != a);
auto grzebiel 21.11.2017 15 / 77
![Page 29: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/29.jpg)
in this alternative world
1 int a = 5;2 int* b = &a;3 auto c = *b;4 ++c;5 assert(c != a);
auto grzebiel 21.11.2017 15 / 77
![Page 30: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/30.jpg)
in this alternative world
1 auto a = 5;2 auto b = a;
type of variable bwould be int &
auto grzebiel 21.11.2017 16 / 77
![Page 31: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/31.jpg)
in this alternative world
1 auto a = 5;2 auto b = a;
type of variable bwould be int &
auto grzebiel 21.11.2017 16 / 77
![Page 32: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/32.jpg)
back to normal world
auto grzebiel 21.11.2017 17 / 77
![Page 33: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/33.jpg)
auto means template type deduction
auto grzebiel 21.11.2017 18 / 77
![Page 34: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/34.jpg)
1 auto foo() -> int;
auto grzebiel 21.11.2017 19 / 77
![Page 35: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/35.jpg)
auto means template type deduction
except when it’s not
auto grzebiel 21.11.2017 20 / 77
![Page 36: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/36.jpg)
auto means template type deductionexcept when it’s not
auto grzebiel 21.11.2017 20 / 77
![Page 37: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/37.jpg)
1 template <typename T, typename U>
2 auto add(T t, U u) -> decltype(t + u);
auto grzebiel 21.11.2017 21 / 77
![Page 38: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/38.jpg)
1 #include <utility>23 template<typename T, typename U>4 decltype(std::declval<T>() + std::declval<U>())5 add(T t, U u);
auto grzebiel 21.11.2017 22 / 77
![Page 39: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/39.jpg)
1 template <typename T, typename U>
2 auto add(T t, U u) -> decltype(t + u);
auto grzebiel 21.11.2017 23 / 77
![Page 40: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/40.jpg)
1 #include <memory>23 template <typename T>4 struct unique_ptr_wrapper5 {6 std::unique_ptr<T> uptr;7 //...8 auto operator*() -> decltype(*uptr)9 {
10 return *uptr;11 }12 //...13 };
auto grzebiel 21.11.2017 24 / 77
![Page 41: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/41.jpg)
1 #include <memory>23 template <typename T>4 struct unique_ptr_wrapper5 {6 std::unique_ptr<T> uptr;7 //...8 auto operator*() -> decltype(*uptr)9 {
10 return *uptr;11 }12 //...13 };
auto grzebiel 21.11.2017 24 / 77
![Page 42: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/42.jpg)
1 #include <memory>23 template <typename T>4 struct unique_ptr_wrapper5 {6 std::unique_ptr<T> uptr;7 //...8 auto operator*() -> decltype(*uptr)9 {
10 return *uptr;11 }12 //...13 };
auto grzebiel 21.11.2017 24 / 77
![Page 43: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/43.jpg)
1 #include <memory>23 template <typename T>4 struct unique_ptr_wrapper5 {6 std::unique_ptr<T> uptr;7 //...8 auto operator*() -> decltype(*uptr)9 {
10 return *uptr;11 }12 //...13 };
auto grzebiel 21.11.2017 24 / 77
![Page 44: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/44.jpg)
1 #include <memory>23 template <typename T>4 struct unique_ptr_wrapper5 {6 std::unique_ptr<T> uptr;7 //...8 auto operator*()9 {
10 return *uptr;11 }12 //...13 };
auto grzebiel 21.11.2017 25 / 77
![Page 45: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/45.jpg)
1 #include <memory>23 template <typename T>4 struct unique_ptr_wrapper5 {6 std::unique_ptr<T> uptr;7 //...8 auto operator*()9 {
10 return *uptr;11 }12 //...13 };
auto grzebiel 21.11.2017 25 / 77
![Page 46: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/46.jpg)
1 #include <memory>23 template <typename T>4 struct unique_ptr_wrapper5 {6 std::unique_ptr<T> uptr;7 //...8 auto& operator*()9 {
10 return *uptr;11 }12 //...13 };
auto grzebiel 21.11.2017 25 / 77
![Page 47: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/47.jpg)
1 #include <memory>23 template <typename T>4 struct unique_ptr_wrapper5 {6 std::unique_ptr<T> uptr;7 //...8 decltype(auto) operator*()9 {
10 return *uptr;11 }12 //...13 };
auto grzebiel 21.11.2017 26 / 77
![Page 48: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/48.jpg)
1 auto
2 decltype
3 default args
4 rvalue reference
5 syntax
decltype grzebiel 21.11.2017 27 / 77
![Page 49: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/49.jpg)
quiz time!
what is a type of variable y?
decltype grzebiel 21.11.2017 28 / 77
![Page 50: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/50.jpg)
quiz time!
1 int x;2 decltype(x) y;
int
decltype grzebiel 21.11.2017 29 / 77
![Page 51: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/51.jpg)
quiz time!
1 int x;2 decltype(x) y;
int
decltype grzebiel 21.11.2017 29 / 77
![Page 52: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/52.jpg)
quiz time!
1 int x;2 auto& z = x;3 decltype(z) y;
int &
decltype grzebiel 21.11.2017 30 / 77
![Page 53: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/53.jpg)
quiz time!
1 int x;2 auto& z = x;3 decltype(z) y;
int &
decltype grzebiel 21.11.2017 30 / 77
![Page 54: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/54.jpg)
quiz time!
1 int x;2 decltype(&x) y;
int *
decltype grzebiel 21.11.2017 31 / 77
![Page 55: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/55.jpg)
quiz time!
1 int x;2 decltype(&x) y;
int *
decltype grzebiel 21.11.2017 31 / 77
![Page 56: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/56.jpg)
quiz time!
1 int x;2 decltype(x + 3.2) y;
double
decltype grzebiel 21.11.2017 32 / 77
![Page 57: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/57.jpg)
quiz time!
1 int x;2 decltype(x + 3.2) y;
double
decltype grzebiel 21.11.2017 32 / 77
![Page 58: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/58.jpg)
quiz time!
1 struct S { int m; };23 S s{};4 decltype(s.m) y;
int
decltype grzebiel 21.11.2017 33 / 77
![Page 59: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/59.jpg)
quiz time!
1 struct S { int m; };23 S s{};4 decltype(s.m) y;
int
decltype grzebiel 21.11.2017 33 / 77
![Page 60: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/60.jpg)
quiz time!
1 int* x;2 decltype(*x) y;
int&
decltype grzebiel 21.11.2017 34 / 77
![Page 61: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/61.jpg)
quiz time!
1 int* x;2 decltype(*x) y;
int&
decltype grzebiel 21.11.2017 34 / 77
![Page 62: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/62.jpg)
quiz time!
1 int x;2 decltype((x)) y;
int&
decltype grzebiel 21.11.2017 35 / 77
![Page 63: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/63.jpg)
quiz time!
1 int x;2 decltype((x)) y;
int&
decltype grzebiel 21.11.2017 35 / 77
![Page 64: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/64.jpg)
quiz time!
1 struct S{int m;};23 const S* sptr;4 decltype((sptr->m)) y;
const int&
decltype grzebiel 21.11.2017 36 / 77
![Page 65: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/65.jpg)
quiz time!
1 struct S{int m;};23 const S* sptr;4 decltype((sptr->m)) y;
const int&
decltype grzebiel 21.11.2017 36 / 77
![Page 66: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/66.jpg)
quiz time!
1 auto string = "string literal";2 decltype(string) y;
const char*
decltype grzebiel 21.11.2017 37 / 77
![Page 67: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/67.jpg)
quiz time!
1 auto string = "string literal";2 decltype(string) y;
const char*
decltype grzebiel 21.11.2017 37 / 77
![Page 68: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/68.jpg)
quiz time!
1 decltype("string literal") y;
const char (&)[15]
decltype grzebiel 21.11.2017 38 / 77
![Page 69: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/69.jpg)
quiz time!
1 decltype("string literal") y;
const char (&)[15]
decltype grzebiel 21.11.2017 38 / 77
![Page 70: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/70.jpg)
decltype has two seperate usecases which yield differentresults:
• get type of entity
• get type of expression
decltype grzebiel 21.11.2017 39 / 77
![Page 71: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/71.jpg)
decltype has two seperate usecases which yield differentresults:
• get type of entity
• get type of expression
decltype grzebiel 21.11.2017 39 / 77
![Page 72: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/72.jpg)
decltype has two seperate usecases which yield differentresults:
• get type of entity
• get type of expression
decltype grzebiel 21.11.2017 39 / 77
![Page 73: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/73.jpg)
1 int x;2 decltype(x); // an entity3 decltype(5); // expression4 decltype((x)); // expression
decltype grzebiel 21.11.2017 40 / 77
![Page 74: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/74.jpg)
1 int x;2 decltype(x); // an entity3 decltype(5); // expression4 decltype((x)); // expression
decltype grzebiel 21.11.2017 40 / 77
![Page 75: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/75.jpg)
1 int x;2 decltype(x); // an entity3 decltype(5); // expression4 decltype((x)); // expression
decltype grzebiel 21.11.2017 40 / 77
![Page 76: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/76.jpg)
1 int x;2 decltype(x); // an entity3 decltype(5); // expression4 decltype((x)); // expression
decltype grzebiel 21.11.2017 40 / 77
![Page 77: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/77.jpg)
1 struct S{int m;};23 const S* sptr;4 decltype((sptr->m)) y;
decltype grzebiel 21.11.2017 41 / 77
![Page 78: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/78.jpg)
1 auto string = "string literal";2 decltype(string) y;
decltype grzebiel 21.11.2017 42 / 77
![Page 79: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/79.jpg)
1 decltype("string literal") y;
decltype grzebiel 21.11.2017 43 / 77
![Page 80: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/80.jpg)
1 auto
2 decltype
3 default args
4 rvalue reference
5 syntax
default args grzebiel 21.11.2017 44 / 77
![Page 81: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/81.jpg)
inheritance!
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a = 5)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a = 7) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say();31 }
default args grzebiel 21.11.2017 45 / 77
![Page 82: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/82.jpg)
inheritance!
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a = 5)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a = 7) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say();31 }
default args grzebiel 21.11.2017 45 / 77
![Page 83: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/83.jpg)
inheritance!
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a = 5)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a = 7) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say();31 }
default args grzebiel 21.11.2017 45 / 77
![Page 84: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/84.jpg)
inheritance!
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a = 5)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a = 7) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say();31 }
default args grzebiel 21.11.2017 45 / 77
![Page 85: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/85.jpg)
inheritance!
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a = 5)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a = 7) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say();31 }
default args grzebiel 21.11.2017 45 / 77
![Page 86: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/86.jpg)
inheritance!
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a = 5)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a = 7) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say();31 }
default args grzebiel 21.11.2017 45 / 77
![Page 87: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/87.jpg)
inheritance!
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a = 5)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a = 7) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say();31 }
default args grzebiel 21.11.2017 45 / 77
![Page 88: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/88.jpg)
inheritance!
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a = 5)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a = 7) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say();31 }
default args grzebiel 21.11.2017 45 / 77
![Page 89: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/89.jpg)
inheritance!
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a = 5)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a = 7) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say();31 }
default args grzebiel 21.11.2017 45 / 77
![Page 90: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/90.jpg)
and the output is
Child says: 5
default args grzebiel 21.11.2017 46 / 77
![Page 91: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/91.jpg)
and the output is
Child says:
5
default args grzebiel 21.11.2017 46 / 77
![Page 92: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/92.jpg)
and the output is
Child says: 5
default args grzebiel 21.11.2017 46 / 77
![Page 93: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/93.jpg)
default args grzebiel 21.11.2017 47 / 77
![Page 94: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/94.jpg)
function call phases
•
•
•
•
•
default args grzebiel 21.11.2017 48 / 77
![Page 95: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/95.jpg)
function call phases
• name lookup
•
•
•
•
default args grzebiel 21.11.2017 48 / 77
![Page 96: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/96.jpg)
function call phases
• name lookup
• template type deduction
•
•
•
default args grzebiel 21.11.2017 48 / 77
![Page 97: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/97.jpg)
function call phases
• name lookup
• template type deduction
• overload resolution
•
•
default args grzebiel 21.11.2017 48 / 77
![Page 98: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/98.jpg)
function call phases
• name lookup
• template type deduction
• overload resolution
• access control
•
default args grzebiel 21.11.2017 48 / 77
![Page 99: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/99.jpg)
function call phases
• name lookup
• template type deduction
• overload resolution
• access control
• virtual function call
default args grzebiel 21.11.2017 48 / 77
![Page 100: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/100.jpg)
function call phases
• name lookup
• template type deduction
• overload resolution
• access control
• virtual function call
default args grzebiel 21.11.2017 48 / 77
![Page 101: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/101.jpg)
after finding default argument
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a = 5)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a = 7) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say();31 }
default args grzebiel 21.11.2017 49 / 77
![Page 102: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/102.jpg)
after finding default argument
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say(5);31 }
default args grzebiel 21.11.2017 49 / 77
![Page 103: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/103.jpg)
function call phases
• name lookup
• template type deduction
• overload resolution
• access control
• virtual function call
default args grzebiel 21.11.2017 50 / 77
![Page 104: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/104.jpg)
function call phases
• name lookup
• template type deduction
• overload resolution
• access control
• virtual function call
default args grzebiel 21.11.2017 50 / 77
![Page 105: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/105.jpg)
access control
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say(5);31 }
default args grzebiel 21.11.2017 51 / 77
![Page 106: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/106.jpg)
access control
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say(5);31 }
default args grzebiel 21.11.2017 51 / 77
![Page 107: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/107.jpg)
access control
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say(5);31 }
default args grzebiel 21.11.2017 51 / 77
![Page 108: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/108.jpg)
access control
1 void say(std::string who,2 int what)3 {4 std::cout << who << " says: "5 << what << std::endl;6 }78 struct Parent9 {
10 virtual void say(int a)11 {12 ::say("Parent", a);13 }1415 virtual ~Parent() = default;16 };
1718 class Child : public Parent19 {20 void say(int a) override21 {22 ::say("Child", a);23 }24 };2526 int main() {27 Child c{};28 Parent* p = &c;2930 p->say(5);31 }
default args grzebiel 21.11.2017 51 / 77
![Page 109: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/109.jpg)
argument redeclaration1 int foo(int a, int b = 5);23 int main()4 {5 foo(1); // a = 1, b = 567 int foo(int a, int b = 7);8 foo(2); // a = 2, b = 7;9 {
10 int foo(int a = 3, int b = 12);11 foo(); // a = 3, b = 12;12 // ::foo(); // compilation error13 ::foo(4); // a = 4, b = 5;14 }15 }
default args grzebiel 21.11.2017 52 / 77
![Page 110: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/110.jpg)
argument redeclaration1 int foo(int a, int b = 5);23 int main()4 {5 foo(1); // a = 1, b = 567 int foo(int a, int b = 7);8 foo(2); // a = 2, b = 7;9 {
10 int foo(int a = 3, int b = 12);11 foo(); // a = 3, b = 12;12 // ::foo(); // compilation error13 ::foo(4); // a = 4, b = 5;14 }15 }
default args grzebiel 21.11.2017 52 / 77
![Page 111: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/111.jpg)
argument redeclaration1 int foo(int a, int b = 5);23 int main()4 {5 foo(1); // a = 1, b = 567 int foo(int a, int b = 7);8 foo(2); // a = 2, b = 7;9 {
10 int foo(int a = 3, int b = 12);11 foo(); // a = 3, b = 12;12 // ::foo(); // compilation error13 ::foo(4); // a = 4, b = 5;14 }15 }
default args grzebiel 21.11.2017 52 / 77
![Page 112: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/112.jpg)
argument redeclaration1 int foo(int a, int b = 5);23 int main()4 {5 foo(1); // a = 1, b = 567 int foo(int a, int b = 7);8 foo(2); // a = 2, b = 7;9 {
10 int foo(int a = 3, int b = 12);11 foo(); // a = 3, b = 12;12 // ::foo(); // compilation error13 ::foo(4); // a = 4, b = 5;14 }15 }
default args grzebiel 21.11.2017 52 / 77
![Page 113: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/113.jpg)
argument redeclaration1 int foo(int a, int b = 5);23 int main()4 {5 foo(1); // a = 1, b = 567 int foo(int a, int b = 7);8 foo(2); // a = 2, b = 7;9 {
10 int foo(int a = 3, int b = 12);11 foo(); // a = 3, b = 12;12 // ::foo(); // compilation error13 ::foo(4); // a = 4, b = 5;14 }15 }
default args grzebiel 21.11.2017 52 / 77
![Page 114: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/114.jpg)
argument redeclaration1 int foo(int a, int b = 5);23 int main()4 {5 foo(1); // a = 1, b = 567 int foo(int a, int b = 7);8 foo(2); // a = 2, b = 7;9 {
10 int foo(int a = 3, int b = 12);11 foo(); // a = 3, b = 12;12 // ::foo(); // compilation error13 ::foo(4); // a = 4, b = 5;14 }15 }
default args grzebiel 21.11.2017 52 / 77
![Page 115: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/115.jpg)
argument redeclaration1 int foo(int a, int b = 5);23 int main()4 {5 foo(1); // a = 1, b = 567 int foo(int a, int b = 7);8 foo(2); // a = 2, b = 7;9 {
10 int foo(int a = 3, int b = 12);11 foo(); // a = 3, b = 12;12 // ::foo(); // compilation error13 ::foo(4); // a = 4, b = 5;14 }15 }
default args grzebiel 21.11.2017 52 / 77
![Page 116: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/116.jpg)
argument redeclaration1 int foo(int a, int b = 5);23 int main()4 {5 foo(1); // a = 1, b = 567 int foo(int a, int b = 7);8 foo(2); // a = 2, b = 7;9 {
10 int foo(int a = 3, int b = 12);11 foo(); // a = 3, b = 12;12 // ::foo(); // compilation error13 ::foo(4); // a = 4, b = 5;14 }15 }
default args grzebiel 21.11.2017 52 / 77
![Page 117: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/117.jpg)
argument redeclaration1 int foo(int a, int b = 5);23 int main()4 {5 foo(1); // a = 1, b = 567 int foo(int a, int b = 7);8 foo(2); // a = 2, b = 7;9 {
10 int foo(int a = 3, int b = 12);11 foo(); // a = 3, b = 12;12 // ::foo(); // compilation error13 ::foo(4); // a = 4, b = 5;14 }15 }
default args grzebiel 21.11.2017 52 / 77
![Page 118: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/118.jpg)
multiple declarations
1 #include <iostream>23 void foo(int d, float u = 3.14);4 void foo(int p = 5, float a);56 int main()7 {8 foo();9
10 return 0;11 }
default args grzebiel 21.11.2017 53 / 77
![Page 119: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/119.jpg)
multiple declarations
1 #include <iostream>23 void foo(int d, float u = 3.14);4 void foo(int p = 5, float a);56 int main()7 {8 foo();9
10 return 0;11 }
default args grzebiel 21.11.2017 53 / 77
![Page 120: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/120.jpg)
multiple declarations
1 #include <iostream>23 void foo(int d, float u = 3.14);4 void foo(int p = 5, float a);56 int main()7 {8 foo();9
10 return 0;11 }
default args grzebiel 21.11.2017 53 / 77
![Page 121: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/121.jpg)
CppCon 2017: Michael Price “Function default arguments:Slingshot or Shotgun?”
default args grzebiel 21.11.2017 54 / 77
![Page 122: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/122.jpg)
1 auto
2 decltype
3 default args
4 rvalue reference
5 syntax
rvalue reference grzebiel 21.11.2017 55 / 77
![Page 123: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/123.jpg)
1 #include <iostream>2 #include <string>34 void foo(std::string&) {5 std::cout << "got lvalue "6 << std::endl;7 }89 void foo(std::string&&) {
10 std::cout << "got rvalue "11 << std::endl;12 }1314 int main() {15 std::string&& a{"this it the string"};16 foo(a);17 return 0;18 }
rvalue reference grzebiel 21.11.2017 56 / 77
![Page 124: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/124.jpg)
1 #include <iostream>2 #include <string>34 void foo(std::string&) {5 std::cout << "got lvalue "6 << std::endl;7 }89 void foo(std::string&&) {
10 std::cout << "got rvalue "11 << std::endl;12 }1314 int main() {15 std::string&& a{"this it the string"};16 foo(a);17 return 0;18 }
rvalue reference grzebiel 21.11.2017 56 / 77
![Page 125: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/125.jpg)
1 #include <iostream>2 #include <string>34 void foo(std::string&) {5 std::cout << "got lvalue "6 << std::endl;7 }89 void foo(std::string&&) {
10 std::cout << "got rvalue "11 << std::endl;12 }1314 int main() {15 std::string&& a{"this it the string"};16 foo(a);17 return 0;18 }
rvalue reference grzebiel 21.11.2017 56 / 77
![Page 126: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/126.jpg)
1 #include <iostream>2 #include <string>34 void foo(std::string&) {5 std::cout << "got lvalue "6 << std::endl;7 }89 void foo(std::string&&) {
10 std::cout << "got rvalue "11 << std::endl;12 }1314 int main() {15 std::string&& a{"this it the string"};16 foo(a);17 return 0;18 }
rvalue reference grzebiel 21.11.2017 56 / 77
![Page 127: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/127.jpg)
1 #include <iostream>2 #include <string>34 void foo(std::string&) {5 std::cout << "got lvalue "6 << std::endl;7 }89 void foo(std::string&&) {
10 std::cout << "got rvalue "11 << std::endl;12 }1314 int main() {15 std::string&& a{"this it the string"};16 foo(a);17 return 0;18 }
rvalue reference grzebiel 21.11.2017 56 / 77
![Page 128: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/128.jpg)
1 #include <iostream>2 #include <string>34 void foo(std::string&) {5 std::cout << "got lvalue "6 << std::endl;7 }89 void foo(std::string&&) {
10 std::cout << "got rvalue "11 << std::endl;12 }1314 int main() {15 std::string&& a{"this it the string"};16 foo(a);17 return 0;18 }
rvalue reference grzebiel 21.11.2017 56 / 77
![Page 129: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/129.jpg)
and we got
lvalue
rvalue reference grzebiel 21.11.2017 57 / 77
![Page 130: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/130.jpg)
and we got lvalue
rvalue reference grzebiel 21.11.2017 57 / 77
![Page 131: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/131.jpg)
rvalue reference grzebiel 21.11.2017 58 / 77
![Page 132: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/132.jpg)
The variable of type rvalue reference to type T is
an lvalue itself.
rvalue reference grzebiel 21.11.2017 59 / 77
![Page 133: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/133.jpg)
The variable of type rvalue reference to type T is
an lvalue itself.
rvalue reference grzebiel 21.11.2017 59 / 77
![Page 134: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/134.jpg)
rvalue reference grzebiel 21.11.2017 60 / 77
![Page 135: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/135.jpg)
Lets imagine that we are in alternative universe in whichvariable of type rvalue reference is always an rvalue
rvalue reference grzebiel 21.11.2017 61 / 77
![Page 136: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/136.jpg)
rvalue reference grzebiel 21.11.2017 62 / 77
![Page 137: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/137.jpg)
1 #include <iostream>2 #include <string>34 void foo(std::string&) {5 std::cout << "got lvalue "6 << std::endl;7 }89 void foo(std::string&&) {
10 std::cout << "got rvalue "11 << std::endl;12 }1314 int main() {15 std::string&& a{"this it the string"};16 foo(a);17 return 0;18 }
rvalue reference grzebiel 21.11.2017 63 / 77
![Page 138: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/138.jpg)
1 #include <iostream>2 #include <string>34 void foo(std::string&) {5 std::cout << "got lvalue "6 << std::endl;7 }89 void foo(std::string&&) {
10 std::cout << "got rvalue "11 << std::endl;12 }1314 int main() {15 std::string&& a{"this it the string"};16 foo(a);17 return 0;18 }
rvalue reference grzebiel 21.11.2017 63 / 77
![Page 139: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/139.jpg)
1 #include <iostream>2 #include <string>34 void foo(std::string&) {5 std::cout << "got lvalue "6 << std::endl;7 }89 void foo(std::string&&) {
10 std::cout << "got rvalue "11 << std::endl;12 }1314 int main() {15 std::string&& a{"this it the string"};16 foo(a);17 return 0;18 }
rvalue reference grzebiel 21.11.2017 63 / 77
![Page 140: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/140.jpg)
in this magical place
1 void foo(std::string s);23 void bar(std::string&& s)4 {5 foo(s);6 std::cout << s7 << std::endl;8 };
rvalue reference grzebiel 21.11.2017 64 / 77
![Page 141: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/141.jpg)
in this magical place
1 void foo(std::string s);23 void bar(std::string&& s)4 {5 foo(s);6 std::cout << s7 << std::endl;8 };
rvalue reference grzebiel 21.11.2017 64 / 77
![Page 142: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/142.jpg)
in this magical place
1 void foo(std::string s);23 void bar(std::string&& s)4 {5 foo(s);6 std::cout << s7 << std::endl;8 };
rvalue reference grzebiel 21.11.2017 64 / 77
![Page 143: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/143.jpg)
in this magical place
1 void foo(std::string s);23 void bar(std::string&& s)4 {5 foo(s);6 std::cout << s7 << std::endl;8 };
rvalue reference grzebiel 21.11.2017 64 / 77
![Page 144: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/144.jpg)
in this magical place
1 void foo(std::string s);23 void bar(std::string&& s)4 {5 foo(s);6 std::cout << s7 << std::endl;8 };
rvalue reference grzebiel 21.11.2017 64 / 77
![Page 145: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/145.jpg)
in this magical place
1 void foo(std::string s);23 void bar(std::string&& s)4 {5 foo(s);6 std::cout << s7 << std::endl;8 };
rvalue reference grzebiel 21.11.2017 64 / 77
![Page 146: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/146.jpg)
back to normal world
rvalue reference grzebiel 21.11.2017 65 / 77
![Page 147: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/147.jpg)
1 void foo(std::string&);2 void foo(std::string&&);3 //...45 template<typename T>6 void bar(const T& t)7 {8 foo(t);9 }
1011 template<typename T>12 void bar(T&& t)13 {14 foo(std::move(t));15 }
rvalue reference grzebiel 21.11.2017 66 / 77
![Page 148: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/148.jpg)
1 void foo(std::string&);2 void foo(std::string&&);3 //...45 template<typename T>6 void bar(const T& t)7 {8 foo(t);9 }
1011 template<typename T>12 void bar(T&& t)13 {14 foo(std::move(t));15 }
rvalue reference grzebiel 21.11.2017 66 / 77
![Page 149: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/149.jpg)
1 void foo(std::string&);2 void foo(std::string&&);3 //...45 template<typename T>6 void bar(const T& t)7 {8 foo(t);9 }
1011 template<typename T>12 void bar(T&& t)13 {14 foo(std::move(t));15 }
rvalue reference grzebiel 21.11.2017 66 / 77
![Page 150: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/150.jpg)
1 void foo(std::string&);2 void foo(std::string&&);3 //...45 template<typename T>6 void bar(const T& t)7 {8 foo(t);9 }
1011 template<typename T>12 void bar(T&& t)13 {14 foo(std::move(t));15 }
rvalue reference grzebiel 21.11.2017 66 / 77
![Page 151: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/151.jpg)
1 void foo(std::string&);2 void foo(std::string&&);3 //...45 template<typename T>6 void bar(const T& t)7 {8 foo(t);9 }
1011 template<typename T>12 void bar(T&& t)13 {14 foo(std::move(t));15 }
rvalue reference grzebiel 21.11.2017 66 / 77
![Page 152: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/152.jpg)
1 void foo(std::string&);2 void foo(std::string&&);3 //...45 template<typename T>6 void bar(const T& t)7 {8 foo(t);9 }
1011 template<typename T>12 void bar(T&& t)13 {14 foo(std::move(t));15 }
rvalue reference grzebiel 21.11.2017 66 / 77
![Page 153: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/153.jpg)
forwarding reference
1 void foo(std::string&);2 void foo(std::string&&);3 //...45 template<typename T>6 void bar(T&& t)7 {8 foo(std::forward<T>(t));9 }
rvalue reference grzebiel 21.11.2017 67 / 77
![Page 154: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/154.jpg)
forwarding reference
1 void foo(std::string&);2 void foo(std::string&&);3 //...45 template<typename T>6 void bar(T&& t)7 {8 foo(std::forward<T>(t));9 }
rvalue reference grzebiel 21.11.2017 67 / 77
![Page 155: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/155.jpg)
forwarding reference
1 void foo(std::string&);2 void foo(std::string&&);3 //...45 template<typename T>6 void bar(T&& t)7 {8 foo(std::forward<T>(t));9 }
rvalue reference grzebiel 21.11.2017 67 / 77
![Page 156: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/156.jpg)
this is not forwarding1 template<typename T>2 struct Foo3 {4 void bar(T&& t);5 };67 int main()8 {9 std::string s = "I don’t fit small string";
10 Foo<std::string> f;11 //f.bar(s); // compilation error12 f.bar(std::move(s));13 };
rvalue reference grzebiel 21.11.2017 68 / 77
![Page 157: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/157.jpg)
this is not forwarding1 template<typename T>2 struct Foo3 {4 void bar(T&& t);5 };67 int main()8 {9 std::string s = "I don’t fit small string";
10 Foo<std::string> f;11 //f.bar(s); // compilation error12 f.bar(std::move(s));13 };
rvalue reference grzebiel 21.11.2017 68 / 77
![Page 158: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/158.jpg)
this is not forwarding1 template<typename T>2 struct Foo3 {4 void bar(T&& t);5 };67 int main()8 {9 std::string s = "I don’t fit small string";
10 Foo<std::string> f;11 //f.bar(s); // compilation error12 f.bar(std::move(s));13 };
rvalue reference grzebiel 21.11.2017 68 / 77
![Page 159: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/159.jpg)
this is not forwarding1 template<typename T>2 struct Foo3 {4 void bar(T&& t);5 };67 int main()8 {9 std::string s = "I don’t fit small string";
10 Foo<std::string> f;11 //f.bar(s); // compilation error12 f.bar(std::move(s));13 };
rvalue reference grzebiel 21.11.2017 68 / 77
![Page 160: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/160.jpg)
this is not forwarding1 template<typename T>2 struct Foo3 {4 void bar(T&& t);5 };67 int main()8 {9 std::string s = "I don’t fit small string";
10 Foo<std::string> f;11 //f.bar(s); // compilation error12 f.bar(std::move(s));13 };
rvalue reference grzebiel 21.11.2017 68 / 77
![Page 161: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/161.jpg)
this is not forwarding1 template<typename T>2 struct Foo3 {4 void bar(T&& t);5 };67 int main()8 {9 std::string s = "I don’t fit small string";
10 Foo<std::string> f;11 //f.bar(s); // compilation error12 f.bar(std::move(s));13 };
rvalue reference grzebiel 21.11.2017 68 / 77
![Page 162: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/162.jpg)
wait a second
what if all I want is an rvalue referemce?
rvalue reference grzebiel 21.11.2017 69 / 77
![Page 163: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/163.jpg)
1 #include <type_traits>23 template <4 typename T,5 typename = std::enable_if_t<6 std::is_rvalue_reference<T>::value> >7 void bar(T&& t)8 {9 foo(std::move(t));
10 }
rvalue reference grzebiel 21.11.2017 70 / 77
![Page 164: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/164.jpg)
1 #include <type_traits>23 template <4 typename T,5 typename = std::enable_if_t<6 std::is_rvalue_reference<T>::value> >7 void bar(T&& t)8 {9 foo(std::move(t));
10 }
rvalue reference grzebiel 21.11.2017 70 / 77
![Page 165: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/165.jpg)
1 auto
2 decltype
3 default args
4 rvalue reference
5 syntax
syntax grzebiel 21.11.2017 71 / 77
![Page 166: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/166.jpg)
1 struct Foo2 {3 Foo() {4 std::cout << "default\n";5 }67 Foo(int) {8 std::cout << "param\n";9 }
10 };1112 int main()13 {14 int a = 5;15 { Foo(a); }16 return 0;17 }
syntax grzebiel 21.11.2017 72 / 77
![Page 167: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/167.jpg)
1 struct Foo2 {3 Foo() {4 std::cout << "default\n";5 }67 Foo(int) {8 std::cout << "param\n";9 }
10 };1112 int main()13 {14 int a = 5;15 { Foo(a); }16 return 0;17 }
syntax grzebiel 21.11.2017 72 / 77
![Page 168: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/168.jpg)
1 struct Foo2 {3 Foo() {4 std::cout << "default\n";5 }67 Foo(int) {8 std::cout << "param\n";9 }
10 };1112 int main()13 {14 int a = 5;15 { Foo(a); }16 return 0;17 }
syntax grzebiel 21.11.2017 72 / 77
![Page 169: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/169.jpg)
1 struct Foo2 {3 Foo() {4 std::cout << "default\n";5 }67 Foo(int) {8 std::cout << "param\n";9 }
10 };1112 int main()13 {14 int a = 5;15 { Foo(a); }16 return 0;17 }
syntax grzebiel 21.11.2017 72 / 77
![Page 170: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/170.jpg)
1 struct Foo2 {3 Foo() {4 std::cout << "default\n";5 }67 Foo(int) {8 std::cout << "param\n";9 }
10 };1112 int main()13 {14 int a = 5;15 { Foo(a); }16 return 0;17 }
syntax grzebiel 21.11.2017 72 / 77
![Page 171: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/171.jpg)
1 #include <stdio.h>2 int main()3 {4 int(x) = 38;5 x += 4;6 printf("%d", x);78 return 0;9 }
syntax grzebiel 21.11.2017 73 / 77
![Page 172: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/172.jpg)
syntax grzebiel 21.11.2017 74 / 77
![Page 173: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/173.jpg)
1 int foo(int);23 int main()4 {5 int (*x)(int) = foo;6 return 0;7 }
syntax grzebiel 21.11.2017 75 / 77
![Page 174: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/174.jpg)
1 int foo(int);23 int main()4 {5 int (*x)(int) = foo;6 return 0;7 }
syntax grzebiel 21.11.2017 75 / 77
![Page 175: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/175.jpg)
1 int foo(int);23 int main()4 {5 int (*x)(int) = foo;6 return 0;7 }
syntax grzebiel 21.11.2017 75 / 77
![Page 176: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/176.jpg)
1 struct Foo2 {3 Foo() {4 std::cout << "default\n";5 }67 Foo(int) {8 std::cout << "param\n";9 }
10 };1112 int main()13 {14 int a = 5;15 { Foo(a); }16 return 0;17 }
syntax grzebiel 21.11.2017 76 / 77
![Page 177: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/177.jpg)
1 struct Foo2 {3 Foo() {4 std::cout << "default\n";5 }67 Foo(int) {8 std::cout << "param\n";9 }
10 };1112 int main()13 {14 int a = 5;15 { Foo(a); }16 return 0;17 }
syntax grzebiel 21.11.2017 76 / 77
![Page 178: - The worst feature of modern C++: default behavior di… · The worst feature of modern C++: default behavior Marcin Grzebieluch grzebieluch@me.com 21.11.2017 grzebiel 21.11.2017](https://reader035.vdocuments.site/reader035/viewer/2022081617/6020b71901603554fd093d91/html5/thumbnails/178.jpg)
?syntax grzebiel 21.11.2017 77 / 77