From talk given by Yehezkel Bernat of Intel @Hometalk offices on 23/8/2016
For the Meetup Group JLMcTech - http://www.meetup.com/JLMcTech/
Code examples for the slides: https://github.com/YehezkelShB/presentation-modern-cpp-jlm-meetup
1. Modern C++ - Why and What
JLM Charedi Tech Meetup
Yehezkel Bernat - YehezkelShB@gmail.com
Thunderbolt
TM SW team, Intel
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
2. Agenda
Modern C++ - Meaning
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
3. Agenda
Modern C++ - Meaning
To make sure we use the same terminology
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
4. Agenda
Modern C++ - Meaning
To make sure we use the same terminology
Modern C++ - Why?
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
5. Agenda
Modern C++ - Meaning
To make sure we use the same terminology
Modern C++ - Why?
To make you interested in C++
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
6. Agenda
Modern C++ - Meaning
To make sure we use the same terminology
Modern C++ - Why?
To make you interested in C++
Modern C++ - What?
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
7. Agenda
Modern C++ - Meaning
To make sure we use the same terminology
Modern C++ - Why?
To make you interested in C++
Modern C++ - What?
To give you a taste of what is possible
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
8. Agenda
Modern C++ - Meaning
To make sure we use the same terminology
Modern C++ - Why?
To make you interested in C++
Modern C++ - What?
To give you a taste of what is possible
Not your father's C++
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
9. Agenda
Modern C++ - Meaning
To make sure we use the same terminology
Modern C++ - Why?
To make you interested in C++
Modern C++ - What?
To give you a taste of what is possible
Not your father's C++
(Herb Sutter's title for a presentation in Lang.NEXT 2012)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
10. What it means Modern C++?
Outline
Part I
Modern C++ - Meaning
1 What it means Modern C++?
New standards
Not just the standards
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
11. What it means Modern C++?
New standards
Not just the standards
Outline
1 What it means Modern C++?
New standards
Not just the standards
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
12. What it means Modern C++?
New standards
Not just the standards
Slow start. . .
The language started in '79
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
13. What it means Modern C++?
New standards
Not just the standards
Slow start. . .
The language started in '79
Other impotant points in the language history:
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
14. What it means Modern C++?
New standards
Not just the standards
Slow start. . .
The language started in '79
Other impotant points in the language history:
'85 - 1
st edition of TCPL
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
15. What it means Modern C++?
New standards
Not just the standards
Slow start. . .
The language started in '79
Other impotant points in the language history:
'85 - 1
st edition of TCPL
'87 - Support in GCC
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
16. What it means Modern C++?
New standards
Not just the standards
Slow start. . .
The language started in '79
Other impotant points in the language history:
'85 - 1
st edition of TCPL
'87 - Support in GCC
'90 - ARM - The Annotated C++ Reference Manual (de-facto
standard)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
17. What it means Modern C++?
New standards
Not just the standards
Slow start. . .
The language started in '79
Other impotant points in the language history:
'85 - 1
st edition of TCPL
'87 - Support in GCC
'90 - ARM - The Annotated C++ Reference Manual (de-facto
standard)
'91 - ISO C++ Commitee founded
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
18. What it means Modern C++?
New standards
Not just the standards
Slow start. . .
The language started in '79
Other impotant points in the language history:
'85 - 1
st edition of TCPL
'87 - Support in GCC
'90 - ARM - The Annotated C++ Reference Manual (de-facto
standard)
'91 - ISO C++ Commitee founded
'92 - STL implemented
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
19. What it means Modern C++?
New standards
Not just the standards
Slow start. . .
The language started in '79
Other impotant points in the language history:
'85 - 1
st edition of TCPL
'87 - Support in GCC
'90 - ARM - The Annotated C++ Reference Manual (de-facto
standard)
'91 - ISO C++ Commitee founded
'92 - STL implemented
'98 - C++98
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
20. What it means Modern C++?
New standards
Not just the standards
Slow start. . .
The language started in '79
Other impotant points in the language history:
'85 - 1
st edition of TCPL
'87 - Support in GCC
'90 - ARM - The Annotated C++ Reference Manual (de-facto
standard)
'91 - ISO C++ Commitee founded
'92 - STL implemented
'98 - C++98
'98 - 3
rd edition of TCPL
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
21. What it means Modern C++?
New standards
Not just the standards
Slow start. . .
The language started in '79
Other impotant points in the language history:
'85 - 1
st edition of TCPL
'87 - Support in GCC
'90 - ARM - The Annotated C++ Reference Manual (de-facto
standard)
'91 - ISO C++ Commitee founded
'92 - STL implemented
'98 - C++98
'98 - 3
rd edition of TCPL
'99 - Boost started
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
22. What it means Modern C++?
New standards
Not just the standards
Slow start. . .
The language started in '79
Other impotant points in the language history:
'85 - 1
st edition of TCPL
'87 - Support in GCC
'90 - ARM - The Annotated C++ Reference Manual (de-facto
standard)
'91 - ISO C++ Commitee founded
'92 - STL implemented
'98 - C++98
'98 - 3
rd edition of TCPL
'99 - Boost started
'03 - C++03
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
23. What it means Modern C++?
New standards
Not just the standards
Slow start. . .
The language started in '79
Other impotant points in the language history:
'85 - 1
st edition of TCPL
'87 - Support in GCC
'90 - ARM - The Annotated C++ Reference Manual (de-facto
standard)
'91 - ISO C++ Commitee founded
'92 - STL implemented
'98 - C++98
'98 - 3
rd edition of TCPL
'99 - Boost started
'03 - C++03
http://en.cppreference.com/w/cpp/language/history
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
24. What it means Modern C++?
New standards
Not just the standards
. . . and then (almost full) stop
Compiler support wasn't great
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
25. What it means Modern C++?
New standards
Not just the standards
. . . and then (almost full) stop
Compiler support wasn't great
nor full
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
26. What it means Modern C++?
New standards
Not just the standards
. . . and then (almost full) stop
Compiler support wasn't great
nor full
Other languages gained momentum (Java - started '95, C# -
started '02)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
27. What it means Modern C++?
New standards
Not just the standards
. . . and then (almost full) stop
Compiler support wasn't great
nor full
Other languages gained momentum (Java - started '95, C# -
started '02)
Vague promises for having C++0x
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
28. What it means Modern C++?
New standards
Not just the standards
. . . and then (almost full) stop
Compiler support wasn't great
nor full
Other languages gained momentum (Java - started '95, C# -
started '02)
Vague promises for having C++0x
Nothing much meanwhile
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
29. What it means Modern C++?
New standards
Not just the standards
. . . and then (almost full) stop
Compiler support wasn't great
nor full
Other languages gained momentum (Java - started '95, C# -
started '02)
Vague promises for having C++0x
Nothing much meanwhile
(TR1?)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
30. What it means Modern C++?
New standards
Not just the standards
But then it started again!
Standard
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
31. What it means Modern C++?
New standards
Not just the standards
But then it started again!
Standard
C++11
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
32. What it means Modern C++?
New standards
Not just the standards
But then it started again!
Standard
C++11
(C++0b?)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
33. What it means Modern C++?
New standards
Not just the standards
But then it started again!
Standard
C++11
(C++0b?)
C++14
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
34. What it means Modern C++?
New standards
Not just the standards
But then it started again!
Standard
C++11
(C++0b?)
C++14
C++17
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
35. What it means Modern C++?
New standards
Not just the standards
But then it started again!
Standard
C++11
(C++0b?)
C++14
C++17
Many TSes
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
36. What it means Modern C++?
New standards
Not just the standards
But then it started again!
Standard
C++11
(C++0b?)
C++14
C++17
Many TSes
Compiler support
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
37. What it means Modern C++?
New standards
Not just the standards
But then it started again!
Standard
C++11
(C++0b?)
C++14
C++17
Many TSes
Compiler support
Even a completly new and shiny compiler, Clang (LLVM based)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
38. What it means Modern C++?
New standards
Not just the standards
But then it started again!
Standard
C++11
(C++0b?)
C++14
C++17
Many TSes
Compiler support
Even a completly new and shiny compiler, Clang (LLVM based)
Tool support
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
39. What it means Modern C++?
New standards
Not just the standards
But then it started again!
Standard
C++11
(C++0b?)
C++14
C++17
Many TSes
Compiler support
Even a completly new and shiny compiler, Clang (LLVM based)
Tool support
IDEs, static and dynamic analyzers, etc.
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
41. What it means Modern C++?
New standards
Not just the standards
Outline
1 What it means Modern C++?
New standards
Not just the standards
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
42. What it means Modern C++?
New standards
Not just the standards
Not only 'what', it's also about the 'how'
C++ Core Guidelines
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
43. What it means Modern C++?
New standards
Not just the standards
Not only 'what', it's also about the 'how'
C++ Core Guidelines
http://isocpp.github.io/CppCoreGuidelines/
CppCoreGuidelines
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
44. What it means Modern C++?
New standards
Not just the standards
Not only 'what', it's also about the 'how'
C++ Core Guidelines
http://isocpp.github.io/CppCoreGuidelines/
CppCoreGuidelines
Scott Meyers' Eective C++ series
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
45. What it means Modern C++?
New standards
Not just the standards
Not only 'what', it's also about the 'how'
C++ Core Guidelines
http://isocpp.github.io/CppCoreGuidelines/
CppCoreGuidelines
Scott Meyers' Eective C++ series
Eective C++ (3
rd ed.), More Eective C++, Eective STL,
Eective Modern C++
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
46. What it means Modern C++?
New standards
Not just the standards
Not only 'what', it's also about the 'how'
C++ Core Guidelines
http://isocpp.github.io/CppCoreGuidelines/
CppCoreGuidelines
Scott Meyers' Eective C++ series
Eective C++ (3
rd ed.), More Eective C++, Eective STL,
Eective Modern C++
More. . .
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
47. What it means Modern C++?
New standards
Not just the standards
Not only 'what', it's also about the 'how'
C++ Core Guidelines
http://isocpp.github.io/CppCoreGuidelines/
CppCoreGuidelines
Scott Meyers' Eective C++ series
Eective C++ (3
rd ed.), More Eective C++, Eective STL,
Eective Modern C++
More. . .
Generally: the common wisdom the C++ developer
community collected over the years
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
48. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
Outline
Part II
Modern C++ - Why?
2 Wasn't C++ dead years ago?
3 Aren't managed languages all what we need?
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
49. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
Outline
2 Wasn't C++ dead years ago?
3 Aren't managed languages all what we need?
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
50. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
The Free Lunch Is Over
In '05, Herb Sutter wrote an article titled The Free Lunch Is
Over: A Fundamental Turn Toward Concurrency in Software
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
51. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
The Free Lunch Is Over
In '05, Herb Sutter wrote an article titled The Free Lunch Is
Over: A Fundamental Turn Toward Concurrency in Software
http:
//www.gotw.ca/publications/concurrency-ddj.htm
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
52. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
The Free Lunch Is Over
In '05, Herb Sutter wrote an article titled The Free Lunch Is
Over: A Fundamental Turn Toward Concurrency in Software
http:
//www.gotw.ca/publications/concurrency-ddj.htm
Key observation was simply looking at the following graph:
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
54. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
Why C++
No free lunch
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
55. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
Why C++
No free lunch
One conclusion is that concurrency and parallelism became
very important to utilize the CPU advancement
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
56. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
Why C++
No free lunch
One conclusion is that concurrency and parallelism became
very important to utilize the CPU advancement
Another conclusion, as Sutter explained in C++ and Beyond
2011, is that we care again about performance
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
57. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
Why C++
No free lunch
One conclusion is that concurrency and parallelism became
very important to utilize the CPU advancement
Another conclusion, as Sutter explained in C++ and Beyond
2011, is that we care again about performance
Performance per Watt
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
58. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
Why C++
No free lunch
One conclusion is that concurrency and parallelism became
very important to utilize the CPU advancement
Another conclusion, as Sutter explained in C++ and Beyond
2011, is that we care again about performance
Performance per Watt
Both mobile and datacenters
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
59. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
Why C++
No free lunch
One conclusion is that concurrency and parallelism became
very important to utilize the CPU advancement
Another conclusion, as Sutter explained in C++ and Beyond
2011, is that we care again about performance
Performance per Watt
Both mobile and datacenters
Performance per Size
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
60. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
Why C++
No free lunch
One conclusion is that concurrency and parallelism became
very important to utilize the CPU advancement
Another conclusion, as Sutter explained in C++ and Beyond
2011, is that we care again about performance
Performance per Watt
Both mobile and datacenters
Performance per Size
Performace per Cycle
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
61. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
Why C++
No free lunch
One conclusion is that concurrency and parallelism became
very important to utilize the CPU advancement
Another conclusion, as Sutter explained in C++ and Beyond
2011, is that we care again about performance
Performance per Watt
Both mobile and datacenters
Performance per Size
Performace per Cycle
Do more with the same for better experience
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
62. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
Outline
2 Wasn't C++ dead years ago?
3 Aren't managed languages all what we need?
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
63. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
Aren't managed languages all what we need?
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
64. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
Aren't managed languages all what we need?
Nope
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
65. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
More seriously
Depends on what we are optimizing for
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
66. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
More seriously
Depends on what we are optimizing for
The usual trade-o (no, not space/time trade-o)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
67. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
More seriously
Depends on what we are optimizing for
The usual trade-o (no, not space/time trade-o)
Developer/development time - Managed
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
68. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
More seriously
Depends on what we are optimizing for
The usual trade-o (no, not space/time trade-o)
Developer/development time - Managed
Performance - Unmanaged
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
69. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
More seriously
Depends on what we are optimizing for
The usual trade-o (no, not space/time trade-o)
Developer/development time - Managed
Performance - Unmanaged
(Compatibility is also a big win for C++, but that isn't new)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
70. Wasn't C++ dead years ago?
Aren't managed languages all what we need?
More seriously
Depends on what we are optimizing for
The usual trade-o (no, not space/time trade-o)
Developer/development time - Managed
Performance - Unmanaged
(Compatibility is also a big win for C++, but that isn't new)
What it means Managed / Unmanaged?
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
71. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Outline
Part III
Modern C++ - What?
4 But C++ is not the right choice anyway
5 Isn't C++ very hard to use?
6 Isn't C++ very unsafe to use?
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
72. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Outline
4 But C++ is not the right choice anyway
5 Isn't C++ very hard to use?
6 Isn't C++ very unsafe to use?
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
73. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
74. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
75. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
76. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
const std::setstd::mapstd::string, std::pair
int, std::vectordouble::iterator::const_iterator
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
77. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
const std::setstd::mapstd::string, std::pair
int, std::vectordouble::iterator::const_iterator
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
78. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
const std::setstd::mapstd::string, std::pair
int, std::vectordouble::iterator::const_iterator
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
79. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
const std::setstd::mapstd::string, std::pair
int, std::vectordouble::iterator::const_iterator
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
80. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
const std::setstd::mapstd::string, std::pair
int, std::vectordouble::iterator::const_iterator
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
81. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
const std::setstd::mapstd::string, std::pair
int, std::vectordouble::iterator::const_iterator
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
82. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
Writing explicit loops
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
83. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
Writing explicit loops
Example: 01-ExplicitLoops.cpp
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
84. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
Writing explicit loops
Example: 01-ExplicitLoops.cpp
Inconsistency (e.g. initializing struct vs. class vs. array vs.
container)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
85. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
Writing explicit loops
Example: 01-ExplicitLoops.cpp
Inconsistency (e.g. initializing struct vs. class vs. array vs.
container)
Example: 02-InitDierences.cpp (rst part)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
86. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
Writing explicit loops
Example: 01-ExplicitLoops.cpp
Inconsistency (e.g. initializing struct vs. class vs. array vs.
container)
Example: 02-InitDierences.cpp (rst part)
Safety issues:
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
87. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
Writing explicit loops
Example: 01-ExplicitLoops.cpp
Inconsistency (e.g. initializing struct vs. class vs. array vs.
container)
Example: 02-InitDierences.cpp (rst part)
Safety issues:
Pointers are dangerous
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
88. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
Writing explicit loops
Example: 01-ExplicitLoops.cpp
Inconsistency (e.g. initializing struct vs. class vs. array vs.
container)
Example: 02-InitDierences.cpp (rst part)
Safety issues:
Pointers are dangerous
Explicit memory handling (no garbage collector)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
89. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
What are the main pain points you have about C++?
Here are (some of) mine:
Usability issues:
Hard-to-spell long template instantiation types
Writing explicit loops
Example: 01-ExplicitLoops.cpp
Inconsistency (e.g. initializing struct vs. class vs. array vs.
container)
Example: 02-InitDierences.cpp (rst part)
Safety issues:
Pointers are dangerous
Explicit memory handling (no garbage collector)
Implicit conversions
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
90. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Outline
4 But C++ is not the right choice anyway
5 Isn't C++ very hard to use?
6 Isn't C++ very unsafe to use?
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
91. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Easier-to-use added features
We'll present here a few features of modern C++
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
92. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Easier-to-use added features
We'll present here a few features of modern C++
Most of them made the language easier to use
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
93. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Easier-to-use added features
We'll present here a few features of modern C++
Most of them made the language easier to use
Usually they improve safety too
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
94. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Easier-to-use added features
We'll present here a few features of modern C++
Most of them made the language easier to use
Usually they improve safety too
Sometimes they also improve performance (but in no case hurt
performance)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
95. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
auto
auto
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
96. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
auto
auto
AAA - Almost Always Auto
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
97. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
auto
auto
AAA - Almost Always Auto
(Improved in C++17 with copy elision guarantee and not
deducing initializer-list)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
98. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
auto
auto
AAA - Almost Always Auto
(Improved in C++17 with copy elision guarantee and not
deducing initializer-list)
It's also about performance
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
99. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
auto
auto
AAA - Almost Always Auto
(Improved in C++17 with copy elision guarantee and not
deducing initializer-list)
It's also about performance
Prevents hidden implicit copy (Eective Modern C++, Scott
Meyers)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
100. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
auto
auto
AAA - Almost Always Auto
(Improved in C++17 with copy elision guarantee and not
deducing initializer-list)
It's also about performance
Prevents hidden implicit copy (Eective Modern C++, Scott
Meyers)
std::mapstd::string, int m;
// Fill with data ...
for (auto i = m.begin(); i != m.end(); ++i)
{
const std::pairstd::string, int entry = *i;
// Work with entry
}
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
101. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
auto
auto
AAA - Almost Always Auto
(Improved in C++17 with copy elision guarantee and not
deducing initializer-list)
It's also about performance
Prevents hidden implicit copy (Eective Modern C++, Scott
Meyers)
It's actually also about safety
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
102. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
auto
auto
AAA - Almost Always Auto
(Improved in C++17 with copy elision guarantee and not
deducing initializer-list)
It's also about performance
Prevents hidden implicit copy (Eective Modern C++, Scott
Meyers)
It's actually also about safety
Better maintainability, esp. with refactoring; better generic
code
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
103. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
auto
auto
AAA - Almost Always Auto
(Improved in C++17 with copy elision guarantee and not
deducing initializer-list)
It's also about performance
Prevents hidden implicit copy (Eective Modern C++, Scott
Meyers)
It's actually also about safety
Better maintainability, esp. with refactoring; better generic
code
(We'll see it in use in the following code examples)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
104. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Better loops
Range-based for loops
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
105. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Better loops
Range-based for loops
Example: 01-ExplicitLoops-RangeBased.cpp
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
106. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Better loops
Range-based for loops
Example: 01-ExplicitLoops-RangeBased.cpp
Algorithms are better (loops with name and explicit intention)
- but harder to use!
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
107. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Better loops
Range-based for loops
Example: 01-ExplicitLoops-RangeBased.cpp
Algorithms are better (loops with name and explicit intention)
- but harder to use!
Example: 01-ExplicitLoops-Algorithms.cpp
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
108. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Better loops
Range-based for loops
Example: 01-ExplicitLoops-RangeBased.cpp
Algorithms are better (loops with name and explicit intention)
- but harder to use!
Example: 01-ExplicitLoops-Algorithms.cpp
Lambda functions - make algorithms usable
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
109. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Better loops
Range-based for loops
Example: 01-ExplicitLoops-RangeBased.cpp
Algorithms are better (loops with name and explicit intention)
- but harder to use!
Example: 01-ExplicitLoops-Algorithms.cpp
Lambda functions - make algorithms usable
Example: 01-ExplicitLoops-Lambdas.cpp
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
110. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Better initialization
Brace initializers (e.g. no discrimination against init of
member structs and arrays; init of containers)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
111. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Better initialization
Brace initializers (e.g. no discrimination against init of
member structs and arrays; init of containers)
In-class initializers
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
112. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Better initialization
Brace initializers (e.g. no discrimination against init of
member structs and arrays; init of containers)
In-class initializers
Example: 02-InitDierences.cpp (second part)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
113. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Better information passing
std::tuple
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
114. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Better information passing
std::tuple
(C# is catching up with C#7)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
115. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Better information passing
std::tuple
(C# is catching up with C#7)
Further expanded by structured binding in C++17
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
116. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Outline
4 But C++ is not the right choice anyway
5 Isn't C++ very hard to use?
6 Isn't C++ very unsafe to use?
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
117. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
One safety mechanism to rule them all
RAII
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
118. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
One safety mechanism to rule them all
RAII
Solves both resource safety issues and exception safety issues
(e.g. auto reset a ag)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
119. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
One safety mechanism to rule them all
RAII
Solves both resource safety issues and exception safety issues
(e.g. auto reset a ag)
Smart pointers
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
120. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
One safety mechanism to rule them all
RAII
Solves both resource safety issues and exception safety issues
(e.g. auto reset a ag)
Smart pointers
Example: SmartPointers.sln
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
121. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
One safety mechanism to rule them all
RAII
Solves both resource safety issues and exception safety issues
(e.g. auto reset a ag)
Smart pointers
Example: SmartPointers.sln
Example: RAII
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
122. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
One safety mechanism to rule them all
RAII
Solves both resource safety issues and exception safety issues
(e.g. auto reset a ag)
Smart pointers
Example: SmartPointers.sln
Example: RAII
More RAII tools (STL, fstream, lock_guard)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
123. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
One safety mechanism to rule them all
RAII
Solves both resource safety issues and exception safety issues
(e.g. auto reset a ag)
Smart pointers
Example: SmartPointers.sln
Example: RAII
More RAII tools (STL, fstream, lock_guard)
Scope guard
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
124. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
One safety mechanism to rule them all
RAII
Solves both resource safety issues and exception safety issues
(e.g. auto reset a ag)
Smart pointers
Example: SmartPointers.sln
Example: RAII
More RAII tools (STL, fstream, lock_guard)
Scope guard
Example: ScopeGuard
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
125. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Another interesting safety mechanism
Mars land vehicle story
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
126. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Another interesting safety mechanism
Mars land vehicle story
https://en.wikipedia.org/wiki/Mars_Climate_Orbiter
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
127. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Another interesting safety mechanism
Mars land vehicle story
https://en.wikipedia.org/wiki/Mars_Climate_Orbiter
UDLs
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
128. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Another interesting safety mechanism
Mars land vehicle story
https://en.wikipedia.org/wiki/Mars_Climate_Orbiter
UDLs
Bjarne Stroustrup's talk, slides 18-23
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
129. But C++ is not the right choice anyway
Isn't C++ very hard to use?
Isn't C++ very unsafe to use?
Another interesting safety mechanism
Mars land vehicle story
https://en.wikipedia.org/wiki/Mars_Climate_Orbiter
UDLs
Bjarne Stroustrup's talk, slides 18-23
Example: UDLs
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
135. References
C++ Today: The Beast Is Back; Ga²per Aºman, Jon Kalb;
http:
//www.oreilly.com/programming/free/c++-today.csp
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
136. References
C++ Today: The Beast Is Back; Ga²per Aºman, Jon Kalb;
http:
//www.oreilly.com/programming/free/c++-today.csp
Elements of Modern C++ Style; Herb Sutter;
https://herbsutter.com/elements-of-modern-c-style/
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
137. References
C++ Today: The Beast Is Back; Ga²per Aºman, Jon Kalb;
http:
//www.oreilly.com/programming/free/c++-today.csp
Elements of Modern C++ Style; Herb Sutter;
https://herbsutter.com/elements-of-modern-c-style/
C++ Super-FAQ; https://isocpp.org/faq
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
138. References
C++ Today: The Beast Is Back; Ga²per Aºman, Jon Kalb;
http:
//www.oreilly.com/programming/free/c++-today.csp
Elements of Modern C++ Style; Herb Sutter;
https://herbsutter.com/elements-of-modern-c-style/
C++ Super-FAQ; https://isocpp.org/faq
C++ reference; http://cppreference.com
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
139. References
C++ Today: The Beast Is Back; Ga²per Aºman, Jon Kalb;
http:
//www.oreilly.com/programming/free/c++-today.csp
Elements of Modern C++ Style; Herb Sutter;
https://herbsutter.com/elements-of-modern-c-style/
C++ Super-FAQ; https://isocpp.org/faq
C++ reference; http://cppreference.com
C++ Core Guidelines; http://isocpp.github.io/
CppCoreGuidelines/CppCoreGuidelines
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
140. References
C++ Today: The Beast Is Back; Ga²per Aºman, Jon Kalb;
http:
//www.oreilly.com/programming/free/c++-today.csp
Elements of Modern C++ Style; Herb Sutter;
https://herbsutter.com/elements-of-modern-c-style/
C++ Super-FAQ; https://isocpp.org/faq
C++ reference; http://cppreference.com
C++ Core Guidelines; http://isocpp.github.io/
CppCoreGuidelines/CppCoreGuidelines
Ask me for more references, articles, books and videos
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What
141. References
C++ Today: The Beast Is Back; Ga²per Aºman, Jon Kalb;
http:
//www.oreilly.com/programming/free/c++-today.csp
Elements of Modern C++ Style; Herb Sutter;
https://herbsutter.com/elements-of-modern-c-style/
C++ Super-FAQ; https://isocpp.org/faq
C++ reference; http://cppreference.com
C++ Core Guidelines; http://isocpp.github.io/
CppCoreGuidelines/CppCoreGuidelines
Ask me for more references, articles, books and videos
(or just google it)
Yehezkel Bernat - YehezkelShB@gmail.com Modern C++ - Why and What