SlideShare uma empresa Scribd logo
1 de 30
Baixar para ler offline
Modern C++ 
(less == more) || (more == more) 
! 
mailto:michael@meta.sg
History 
1958!!ALGOL!58!!(Bauer,(Backus(et(al) 
1957!!FORTRAN!!(John(Backus) 
1969!!C!!(Dennis(Ritchie) 
1968!!ALGOL!68 
1966!!FORTRAN!66 
1983!!AT&T!C++!/!Cfront!!(Bjarne(Stroustrup) 
1981!!Objec:ve<C!!(Brad(Cox(and(Tom(Love) 
1979!!C!with!Classes!!(Bjarne(Stroustrup) 
1978!!K&R!C!!(Brian(Kernighan(and(Dennis(Ritchie) 
1977!!FORTRAN!77 
1989!!ANSI/ISO!C89 
1987!!GNU!C!Released 
2003!!ISO!C++03 
1999!ISO!C99 
1998!!ISO!C++98 
2017!!ISO!C++17 
2014!!ISO!C++14 
2011!!ISO!C++11 
2008!!Clang!Released 
2008!!ISO!C++!TR1 
1950 1960 1970 1980 1990 2000 2010 2020
What is C++? 
• A general purpose programming language 
• Has a strong bias towards systems programming 
• One layer above assembly language 
int do_rdrand() 
{ 
• Multi-paradigm language 
int r; 
asm("retry: rdrand eaxn” 
" jnc retry;n" 
: "=a" (r)); 
return r; 
• Imperative (C99 superset) 
} 
• Object-oriented (polymorphism, inheritance) 
• Functional (immutability, lambdas, currying) 
• Meta-programming (templates, algorithms)
Why C++ 
• ISO/IEC 14882:2011 
• International standards organisation represented 
by national bodies from 164 member countries 
• Not open to manipulation by individuals or 
corporations for proprietary control 
• COBOL, Fortran, Ada, Prolog, C, C++, Forth, 
ECMAscript 
• C++ is a software engineering language that 
enables the production of high performance 
type-safe, statically verifiable native software.
Why C++ 
• C++ is popular 
Source: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
C++ projects 
• GNU Compiler Collection, LLVM, Clang 
• Java Virtual Machine, Dart, V8, Facebook HHVM 
• Webkit, Chrome, Safari, Firefox, Internet Explorer 
• MySQL, LevelDB, MongoDB, SAP DB 
• Adobe, Autodesk, Apple, Microsoft, … 
• Scientific computing, Computer Aided Engineering, 
Operations Research, Telecommunications, … 
• Bitcoin ☺
What is Modern C++? 
• Modern C++! 
• feels like “a new language” (Bjarne Stroustrup) 
• C++11 refines the C++ language in a backwards 
compatible way to support existing C++ code while 
enabling simpler and more modern idioms 
• Pass-by-value everywhere 
• STL containers got smarter with r-value references 
• Lambdas, initializer lists, variadic templates, etc 
• Improved memory management 
• Improved standard library
Less is exponentially more 
“I was asked a few weeks ago, "What was the biggest surprise 
you encountered rolling out Go?" I knew the answer instantly: 
Although we expected C++ programmers to see Go as an 
alternative, instead most Go programmers come from languages 
like Python and Ruby. Very few come from C++. 
We—Ken, Robert and myself—were C++ programmers when we 
designed a new language to solve the problems that we thought 
needed to be solved for the kind of software we wrote. It seems 
almost paradoxical that other C++ programmers don't seem to 
care.” –Rob Pike 
http://commandcenter.blogspot.com/2012/06/less-is-exponentially-more.html
C++11 has got more 
std::future 
auto lambda 
<functional> 
std::shared_ptr <thread> 
std::async 
<random> 
<type_traits> 
<memory> 
constexpr 
decltype 
<regex> <mutex> 
std::tuple 
std::unordered_map 
std::unordered_set 
nullptr 
<atomic> static_assert 
std::unique_ptr 
<chrono>
C++11 has got less 
C++98 C++11 
#include <iostream> 
#include <vector> 
! 
using namespace std; 
! 
int main() 
{ 
vector<int> v; 
v.push_back(2); 
v.push_back(3); 
v.push_back(5); 
v.push_back(7); 
vector<int>::iterator i; 
for (i = v.begin(); i != v.end(); i++) { 
cout << *i << endl; 
} 
} 
#include <iostream> 
#include <vector> 
! 
using namespace std; 
! 
int main() 
{ 
vector<int> v = {2,3,5,7}; 
for (auto a : v) { 
cout << a << endl; 
} 
} 
or even less 
int main() 
{ 
for (auto a : {2,3,5,7}) 
cout << a << endl; 
}
Template Metaprogramming 
• The C++ template system is turing complete at compile time 
#include <iostream> 
// http://stackoverflow.com/questions/3082113/calculating-factorial-using-template-meta-programming 
! 
using namespace std; 
! 
template <int N> 
struct Factorial 
{ 
enum { value = N * Factorial<N - 1>::value }; 
}; 
! 
template <> 
struct Factorial<0> 
{ 
enum { value = 1 }; 
}; 
! 
int main() 
{ 
cout << Factorial<4>::value << endl; 
cout << Factorial<0>::value << endl; 
}
Zero-copy layout 
OO Language C++11 
class Price 
{ 
int timestamp; 
int volume; 
double price; 
Price(int timestamp, int volume, double price) 
{ 
this.timestamp = timestamp; 
this.volume = volume; 
this.price = price; 
} 
static void main(String args[]) 
{ 
ArrayList<Price> prices; 
prices.ensureCapacity(4); 
prices.add(new Price(1307725482, 5, 26.05)); 
prices.add(new Price(1307725483, 40, 26.15)); 
prices.add(new Price(1307725493, 100, 26.1499)); 
prices.add(new Price(1307725493, 112, 26.15)); 
} 
} 
struct Price 
{ 
int timestamp; 
int volume; 
double price; 
Price(int timestamp, int volume, double price) 
: timestamp(timestamp), volume(volume), price(price) {} 
}; ! 
int main() 
{ 
vector<Price> prices; 
prices.reserve(4); 
prices.emplace_back(1307725482, 5, 26.05); 
prices.emplace_back(1307725483, 40, 26.15); 
prices.emplace_back(1307725493, 100, 26.1499); 
prices.emplace_back(1307725493, 112, 26.15); 
} 
• Containers use polymorphism and type erase 
• Need to devolve to structure of primitive arrays 
to get reasonable performance, but SoA has 
bad cache behaviour 
• Looks are deceiving 
• Templates instantiate optimized code for the type 
• Superset - allows implementation of polymorphic 
containers i.e. vector<object>
Zero-copy layout 
OO Language - 176 bytes, 5 allocations 
Opaque Object Header (16-bytes) array object reference 
size 
length 
Opaque Object Header (16-bytes) 
Opaque Object Header (16-bytes) 
64-bit Object Reference (8-bytes) 64-bit Object Reference (8-bytes) 64-bit Object Reference (8-bytes) 
Opaque Object Header (16-bytes) 
Opaque Object Header (16-bytes) 
1307725482 5 26.05 
1307725483 40 26.15 
1307725493 100 26.1499 
C++11 - 72 bytes, 2 allocations 
array ptr size capacity 
1307725482 5 26.05 1307725483 40 26.15 1307725493 100 26.1499
No more leaks 
• std::unique_ptr 
• Singleton pointer wrapper 
• Ensures a single copy of an object 
• No performance overhead 
• Automatic release (no more delete) 
• std::shared_ptr 
• Reference counting pointer wrapper 
• Thread-safe reference counter 
• Acts like a normal pointer but has overhead 
• Use when correctness is more important than performance 
• Automatic release (no more delete)
R-value references 
• template<typename T> void foo(T&&) 
• New signature to detect r-values (temporaries) 
• In a nut shell enables compile time detection of 
r-value temporaries (versus l-values) to implement efficient 
zero-copy move semantics and perfect forwarding 
• What is an r-value? 
vector<Price> raise(vector<Price> prices) { /* does something */ } 
raise({Price(1307725482, 5, 26.05), Price(1307725483, 40, 26.15)}); 
• Adds complexity to hide complexity 
• Feature designed for STL and library writers 
• std::forward, std::move 
• Efficient pass by value and return by value for containers 
• Simplifies idiom of user code
Initializer lists 
• Array initialization 
was a C++98 bugbear 
• Adds new initializer syntax 
foo{1,2,3,4} 
• Can be used in constructor 
member initialization 
• New header 
<initializer_list> 
• New template 
initializer_list<T> 
struct myclass { 
myclass (int,int); 
myclass (initializer_list<int>); 
/* definitions ... */ 
}; ! 
myclass foo {10,20}; // calls initializer_list ctor 
myclass bar (10,20); // calls first constructor 
template <typename T> 
struct vec 
{ 
vec(T x) : m{x, 0, 0, 1} {} 
vec(T x, T y) : m{x, y, 0, 1} {} 
vec(T x, T y, T z) : m{x, y, z, 1} {} 
vec(T x, T y, T z, T w) : m{x, y, z, w} {} 
T m[4]; 
}; 
! 
vec<float> a(1, 2, 3);
Delegating constructors 
• Really. C++98 didn’t have them 
template <typename T> 
struct vec 
{ 
vec(T x) : vec(x, 0, 0, 1) {} 
vec(T x, T y) : vec(x, y, 0, 1) {} 
vec(T x, T y, T z) : vec(x, y, z, 1) {} 
vec(T x, T y, T z, T w) : m{x, y, z, w} {} 
T m[4]; 
};
Threads and Futures 
• std::thread 
• std::async 
• std::future 
• C++ is in now line 
with other modern 
languages thread 
capabilities 
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <numeric> 
#include <future> ! 
// source http://en.cppreference.com/w/cpp/thread/async ! 
template <typename I> 
int parallel_sum(I beg, I end) 
{ 
typename I::difference_type len = end - beg; 
if (len < 1000) { 
return std::accumulate(beg, end, 0); 
} 
I mid = beg + len/2; 
auto handle = std::async(std::launch::async, 
parallel_sum<I>, mid, end); 
int sum = parallel_sum(beg, mid); 
return sum + handle.get(); 
} ! 
int main() 
{ 
std::vector<int> v(10000, 1); 
std::cout << "The sum is " << parallel_sum(v.begin(), v.end()) << ‘n'; 
}
Compile-time type identification 
• New header <type_traits> 
• std::is_void<T> 
• std::is_integral<T> 
• std::is_array<T> 
• std::is_class<T> 
• std::is_pointer<T> 
• std::is_volatile<T> 
• std::rank<T>, std::extent<T,N> 
• …. many many more …. 
template <typename R> static const EGType& typeOf() 
{ 
typedef typename std::remove_extent<R>::type A; 
typedef typename std::remove_pointer<R>::type P; 
if (std::is_array<R>::value) { 
typedef typename std::remove_const<A>::type V; 
return arrayType<V>(); 
} else if (std::is_pointer<R>::value) { 
typedef typename std::remove_const<P>::type V; 
return pointerType<V>(); 
} else { 
typedef typename std::remove_const<R>::type V; 
return integralType<V>(); 
} 
}
Variadic templates 
• Variadic templates allow 
implementation of a compile 
time type safe printf(…) 
• Variadic templates combined 
with compile time type 
identification gives super 
powers to C++ 
• Can collect type information 
at compile time and use at 
runtime 
• Allows creation of an 
Objective-C style messaging 
system with late-binding 
#include <type_traits> 
#include <functional> 
#include <string> 
#include <iostream> 
#include <iomanip> ! 
using namespace std; 
using namespace std::placeholders; ! 
template<typename T> 
void reflect_compiler_reflect(T value) 
{ 
cout << setw(70) << typeid(T).name() 
<< " is_pointer=" << is_pointer<T>::value 
<< " is_integral=" << is_integral<T>::value 
<< " is_floating_point=" << is_floating_point<T>::value 
<< " is_class=" << is_class<T>::value 
<< " is_empty=" << is_empty<T>::value 
<< endl; 
} ! 
template<typename T, typename... Args> 
void reflect_compiler_reflect(T value, Args... args) 
{ 
reflect_compiler_reflect(value); 
reflect_compiler_reflect(args...); 
} ! 
int main() 
{ 
int a = 1; 
float b = 4.5f; 
double c[71]; 
string d; 
auto e = [] (int a) {}; 
auto f = std::bind(e, 99, _1); 
struct {} g; 
reflect_compiler_reflect(a, b, c, d, e, f, g); 
}
User-defined literals 
• Allow definition of type 
safe SI units and other 
creative uses 
• Solve Mars Climate 
Orbiter type problems 
class Symbol 
{ 
public: 
string name; 
Symbol(const char *name) : name(name) {} 
}; ! 
Symbol operator "" _symbol(const char* name, size_t) { 
return Symbol(name); 
} ! 
int main() 
{ 
Symbol Foo = "Foo"_symbol; 
}
More functional 
• lambdas 
• [], [=], [&] 
• use in place of old-style function objects 
• combine with existing STL generic algorithms 
e.g. std::partition 
• currying 
• std::function 
• std::bind 
• std::placeholders::_1
Lots more STL 
• Compile time reflection 
• <type_traits> 
• Containers 
• <array>, <unordered_set>, <unordered_map>, <forward_list> 
• Multi-threading 
• <atomic>, <thread>, <mutex>, <future>, <condition_variable> 
• More utility 
• <tuple>, <regex>, <chrono>, <codecvt> 
• Numerics 
• <random>, <ratio>, <cfenv>
C++14 
auto lambda = [](auto x, auto y) {return x + y;}; 
• Generic lambdas 
• lambda initializers 
• Variable templates 
• make_unique 
• Runtime sized arrays 
• Filesystem (Boost::filesystem) 
• Networking 
auto lambda = [value = 1] {return value;}; 
template<typename T> 
constexpr T pi = T(3.1415926535897932385); 
auto u = make_unique<some_type>(ctor, params); 
void foo(size_t n) { int a[n]; }
LLVM / Clang 
• Modular compiler toolchain 
• 2012 ACM Software System Award 
• Clang memory sanitizer 
• Clang address sanitizer 
• Clang thread sanitizer 
• Clang modernize 
• Firefox - emscripten C++ to asm.js 
• Chrome - PNaCl C++ LLVM bitcode 
• Foundation of many OpenCL implementations
C++ - pros 
• Maturity and Performance 
• 30 years of evolution and production use in large scale systems 
• ~ 2x - 3x faster than Java 
• ~ 10x - 100x faster than Ruby and Python 
• Compiler and architecture choices 
• GCC 4.9, Clang 3.4, Intel C++ 14, Visual C++ 2013, etc 
• Easy access to processor features 
• SSE4 Streaming Extensions, AVX-512 SIMD Vector Extensions 
• Compile time static checking and type safety 
• Static analysis tools, valgrind, clang memory sanitizer,… 
• Multi-paradigm 
• Offers a choice of programming styles
C++ - cons 
• Big language, big learning curve 
• Define an idiom with C++: google c++ style 
• Long compile times 
• Idea is to spend time now to save it in the future 
• Missing standard libraries 
• networking, database, graphics, sound, xml and json 
serialization, etc 
• The cost of runtime performance 
• Buffer overflows,Illegal memory accesses 
• Requires static analysis 
• Potential solution: Intel MPX (Memory Protection Extensions)
Conclusion 
• Pick the right language for the job 
• C++ is suitable for infrastructure code where 
performance and type safety are important 
• C++ requires care with memory management 
(leaks, buffer offer-flows, off-by-one errors) 
• Give C++ a go!
Comments / Questions

Mais conteúdo relacionado

Mais procurados

Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Geeks Anonymes
 
C++11 concurrency
C++11 concurrencyC++11 concurrency
C++11 concurrencyxu liwei
 
C++11: Rvalue References, Move Semantics, Perfect Forwarding
C++11: Rvalue References, Move Semantics, Perfect ForwardingC++11: Rvalue References, Move Semantics, Perfect Forwarding
C++11: Rvalue References, Move Semantics, Perfect ForwardingFrancesco Casalegno
 
C++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabsC++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabsStephane Gleizes
 
Regular types in C++
Regular types in C++Regular types in C++
Regular types in C++Ilio Catallo
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Sumant Tambe
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMSfawzmasood
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Sumant Tambe
 
Modern C++ Explained: Move Semantics (Feb 2018)
Modern C++ Explained: Move Semantics (Feb 2018)Modern C++ Explained: Move Semantics (Feb 2018)
Modern C++ Explained: Move Semantics (Feb 2018)Olve Maudal
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Chris Adamson
 

Mais procurados (20)

What's New in C++ 11?
What's New in C++ 11?What's New in C++ 11?
What's New in C++ 11?
 
C++11
C++11C++11
C++11
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
 
C++11 concurrency
C++11 concurrencyC++11 concurrency
C++11 concurrency
 
C++11: Rvalue References, Move Semantics, Perfect Forwarding
C++11: Rvalue References, Move Semantics, Perfect ForwardingC++11: Rvalue References, Move Semantics, Perfect Forwarding
C++11: Rvalue References, Move Semantics, Perfect Forwarding
 
C++ 11
C++ 11C++ 11
C++ 11
 
C++ Presentation
C++ PresentationC++ Presentation
C++ Presentation
 
The Style of C++ 11
The Style of C++ 11The Style of C++ 11
The Style of C++ 11
 
Smart Pointers in C++
Smart Pointers in C++Smart Pointers in C++
Smart Pointers in C++
 
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
 
C++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabsC++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabs
 
Le langage rust
Le langage rustLe langage rust
Le langage rust
 
Regular types in C++
Regular types in C++Regular types in C++
Regular types in C++
 
Smart pointers
Smart pointersSmart pointers
Smart pointers
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)
 
Modern C++ Explained: Move Semantics (Feb 2018)
Modern C++ Explained: Move Semantics (Feb 2018)Modern C++ Explained: Move Semantics (Feb 2018)
Modern C++ Explained: Move Semantics (Feb 2018)
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
C++ references
C++ referencesC++ references
C++ references
 

Semelhante a Modern C++

Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overviewTAlha MAlik
 
Cs1123 11 pointers
Cs1123 11 pointersCs1123 11 pointers
Cs1123 11 pointersTAlha MAlik
 
Abhishek lingineni
Abhishek lingineniAbhishek lingineni
Abhishek lingineniabhishekl404
 
CPlusPus
CPlusPusCPlusPus
CPlusPusrasen58
 
C++ process new
C++ process newC++ process new
C++ process new敬倫 林
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.pptInfotech27
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.pptTeacherOnat
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.pptJayarAlejo
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.pptJayarAlejo
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.pptEPORI
 
C++ programming: Basic introduction to C++.ppt
C++ programming: Basic introduction to C++.pptC++ programming: Basic introduction to C++.ppt
C++ programming: Basic introduction to C++.pptyp02
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossumoscon2007
 
0100_Embeded_C_CompilationProcess.pdf
0100_Embeded_C_CompilationProcess.pdf0100_Embeded_C_CompilationProcess.pdf
0100_Embeded_C_CompilationProcess.pdfKhaledIbrahim10923
 
2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++kinan keshkeh
 
C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)Christian Nagel
 

Semelhante a Modern C++ (20)

Return of c++
Return of c++Return of c++
Return of c++
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
Cs1123 11 pointers
Cs1123 11 pointersCs1123 11 pointers
Cs1123 11 pointers
 
Abhishek lingineni
Abhishek lingineniAbhishek lingineni
Abhishek lingineni
 
CPlusPus
CPlusPusCPlusPus
CPlusPus
 
C++ process new
C++ process newC++ process new
C++ process new
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++ programming: Basic introduction to C++.ppt
C++ programming: Basic introduction to C++.pptC++ programming: Basic introduction to C++.ppt
C++ programming: Basic introduction to C++.ppt
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossum
 
2CPP15 - Templates
2CPP15 - Templates2CPP15 - Templates
2CPP15 - Templates
 
0100_Embeded_C_CompilationProcess.pdf
0100_Embeded_C_CompilationProcess.pdf0100_Embeded_C_CompilationProcess.pdf
0100_Embeded_C_CompilationProcess.pdf
 
2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++
 
C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)
 

Último

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...masabamasaba
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 

Último (20)

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 

Modern C++

  • 1.
  • 2. Modern C++ (less == more) || (more == more) ! mailto:michael@meta.sg
  • 3. History 1958!!ALGOL!58!!(Bauer,(Backus(et(al) 1957!!FORTRAN!!(John(Backus) 1969!!C!!(Dennis(Ritchie) 1968!!ALGOL!68 1966!!FORTRAN!66 1983!!AT&T!C++!/!Cfront!!(Bjarne(Stroustrup) 1981!!Objec:ve<C!!(Brad(Cox(and(Tom(Love) 1979!!C!with!Classes!!(Bjarne(Stroustrup) 1978!!K&R!C!!(Brian(Kernighan(and(Dennis(Ritchie) 1977!!FORTRAN!77 1989!!ANSI/ISO!C89 1987!!GNU!C!Released 2003!!ISO!C++03 1999!ISO!C99 1998!!ISO!C++98 2017!!ISO!C++17 2014!!ISO!C++14 2011!!ISO!C++11 2008!!Clang!Released 2008!!ISO!C++!TR1 1950 1960 1970 1980 1990 2000 2010 2020
  • 4. What is C++? • A general purpose programming language • Has a strong bias towards systems programming • One layer above assembly language int do_rdrand() { • Multi-paradigm language int r; asm("retry: rdrand eaxn” " jnc retry;n" : "=a" (r)); return r; • Imperative (C99 superset) } • Object-oriented (polymorphism, inheritance) • Functional (immutability, lambdas, currying) • Meta-programming (templates, algorithms)
  • 5. Why C++ • ISO/IEC 14882:2011 • International standards organisation represented by national bodies from 164 member countries • Not open to manipulation by individuals or corporations for proprietary control • COBOL, Fortran, Ada, Prolog, C, C++, Forth, ECMAscript • C++ is a software engineering language that enables the production of high performance type-safe, statically verifiable native software.
  • 6. Why C++ • C++ is popular Source: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
  • 7. C++ projects • GNU Compiler Collection, LLVM, Clang • Java Virtual Machine, Dart, V8, Facebook HHVM • Webkit, Chrome, Safari, Firefox, Internet Explorer • MySQL, LevelDB, MongoDB, SAP DB • Adobe, Autodesk, Apple, Microsoft, … • Scientific computing, Computer Aided Engineering, Operations Research, Telecommunications, … • Bitcoin ☺
  • 8. What is Modern C++? • Modern C++! • feels like “a new language” (Bjarne Stroustrup) • C++11 refines the C++ language in a backwards compatible way to support existing C++ code while enabling simpler and more modern idioms • Pass-by-value everywhere • STL containers got smarter with r-value references • Lambdas, initializer lists, variadic templates, etc • Improved memory management • Improved standard library
  • 9. Less is exponentially more “I was asked a few weeks ago, "What was the biggest surprise you encountered rolling out Go?" I knew the answer instantly: Although we expected C++ programmers to see Go as an alternative, instead most Go programmers come from languages like Python and Ruby. Very few come from C++. We—Ken, Robert and myself—were C++ programmers when we designed a new language to solve the problems that we thought needed to be solved for the kind of software we wrote. It seems almost paradoxical that other C++ programmers don't seem to care.” –Rob Pike http://commandcenter.blogspot.com/2012/06/less-is-exponentially-more.html
  • 10. C++11 has got more std::future auto lambda <functional> std::shared_ptr <thread> std::async <random> <type_traits> <memory> constexpr decltype <regex> <mutex> std::tuple std::unordered_map std::unordered_set nullptr <atomic> static_assert std::unique_ptr <chrono>
  • 11. C++11 has got less C++98 C++11 #include <iostream> #include <vector> ! using namespace std; ! int main() { vector<int> v; v.push_back(2); v.push_back(3); v.push_back(5); v.push_back(7); vector<int>::iterator i; for (i = v.begin(); i != v.end(); i++) { cout << *i << endl; } } #include <iostream> #include <vector> ! using namespace std; ! int main() { vector<int> v = {2,3,5,7}; for (auto a : v) { cout << a << endl; } } or even less int main() { for (auto a : {2,3,5,7}) cout << a << endl; }
  • 12. Template Metaprogramming • The C++ template system is turing complete at compile time #include <iostream> // http://stackoverflow.com/questions/3082113/calculating-factorial-using-template-meta-programming ! using namespace std; ! template <int N> struct Factorial { enum { value = N * Factorial<N - 1>::value }; }; ! template <> struct Factorial<0> { enum { value = 1 }; }; ! int main() { cout << Factorial<4>::value << endl; cout << Factorial<0>::value << endl; }
  • 13. Zero-copy layout OO Language C++11 class Price { int timestamp; int volume; double price; Price(int timestamp, int volume, double price) { this.timestamp = timestamp; this.volume = volume; this.price = price; } static void main(String args[]) { ArrayList<Price> prices; prices.ensureCapacity(4); prices.add(new Price(1307725482, 5, 26.05)); prices.add(new Price(1307725483, 40, 26.15)); prices.add(new Price(1307725493, 100, 26.1499)); prices.add(new Price(1307725493, 112, 26.15)); } } struct Price { int timestamp; int volume; double price; Price(int timestamp, int volume, double price) : timestamp(timestamp), volume(volume), price(price) {} }; ! int main() { vector<Price> prices; prices.reserve(4); prices.emplace_back(1307725482, 5, 26.05); prices.emplace_back(1307725483, 40, 26.15); prices.emplace_back(1307725493, 100, 26.1499); prices.emplace_back(1307725493, 112, 26.15); } • Containers use polymorphism and type erase • Need to devolve to structure of primitive arrays to get reasonable performance, but SoA has bad cache behaviour • Looks are deceiving • Templates instantiate optimized code for the type • Superset - allows implementation of polymorphic containers i.e. vector<object>
  • 14. Zero-copy layout OO Language - 176 bytes, 5 allocations Opaque Object Header (16-bytes) array object reference size length Opaque Object Header (16-bytes) Opaque Object Header (16-bytes) 64-bit Object Reference (8-bytes) 64-bit Object Reference (8-bytes) 64-bit Object Reference (8-bytes) Opaque Object Header (16-bytes) Opaque Object Header (16-bytes) 1307725482 5 26.05 1307725483 40 26.15 1307725493 100 26.1499 C++11 - 72 bytes, 2 allocations array ptr size capacity 1307725482 5 26.05 1307725483 40 26.15 1307725493 100 26.1499
  • 15. No more leaks • std::unique_ptr • Singleton pointer wrapper • Ensures a single copy of an object • No performance overhead • Automatic release (no more delete) • std::shared_ptr • Reference counting pointer wrapper • Thread-safe reference counter • Acts like a normal pointer but has overhead • Use when correctness is more important than performance • Automatic release (no more delete)
  • 16. R-value references • template<typename T> void foo(T&&) • New signature to detect r-values (temporaries) • In a nut shell enables compile time detection of r-value temporaries (versus l-values) to implement efficient zero-copy move semantics and perfect forwarding • What is an r-value? vector<Price> raise(vector<Price> prices) { /* does something */ } raise({Price(1307725482, 5, 26.05), Price(1307725483, 40, 26.15)}); • Adds complexity to hide complexity • Feature designed for STL and library writers • std::forward, std::move • Efficient pass by value and return by value for containers • Simplifies idiom of user code
  • 17. Initializer lists • Array initialization was a C++98 bugbear • Adds new initializer syntax foo{1,2,3,4} • Can be used in constructor member initialization • New header <initializer_list> • New template initializer_list<T> struct myclass { myclass (int,int); myclass (initializer_list<int>); /* definitions ... */ }; ! myclass foo {10,20}; // calls initializer_list ctor myclass bar (10,20); // calls first constructor template <typename T> struct vec { vec(T x) : m{x, 0, 0, 1} {} vec(T x, T y) : m{x, y, 0, 1} {} vec(T x, T y, T z) : m{x, y, z, 1} {} vec(T x, T y, T z, T w) : m{x, y, z, w} {} T m[4]; }; ! vec<float> a(1, 2, 3);
  • 18. Delegating constructors • Really. C++98 didn’t have them template <typename T> struct vec { vec(T x) : vec(x, 0, 0, 1) {} vec(T x, T y) : vec(x, y, 0, 1) {} vec(T x, T y, T z) : vec(x, y, z, 1) {} vec(T x, T y, T z, T w) : m{x, y, z, w} {} T m[4]; };
  • 19. Threads and Futures • std::thread • std::async • std::future • C++ is in now line with other modern languages thread capabilities #include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <future> ! // source http://en.cppreference.com/w/cpp/thread/async ! template <typename I> int parallel_sum(I beg, I end) { typename I::difference_type len = end - beg; if (len < 1000) { return std::accumulate(beg, end, 0); } I mid = beg + len/2; auto handle = std::async(std::launch::async, parallel_sum<I>, mid, end); int sum = parallel_sum(beg, mid); return sum + handle.get(); } ! int main() { std::vector<int> v(10000, 1); std::cout << "The sum is " << parallel_sum(v.begin(), v.end()) << ‘n'; }
  • 20. Compile-time type identification • New header <type_traits> • std::is_void<T> • std::is_integral<T> • std::is_array<T> • std::is_class<T> • std::is_pointer<T> • std::is_volatile<T> • std::rank<T>, std::extent<T,N> • …. many many more …. template <typename R> static const EGType& typeOf() { typedef typename std::remove_extent<R>::type A; typedef typename std::remove_pointer<R>::type P; if (std::is_array<R>::value) { typedef typename std::remove_const<A>::type V; return arrayType<V>(); } else if (std::is_pointer<R>::value) { typedef typename std::remove_const<P>::type V; return pointerType<V>(); } else { typedef typename std::remove_const<R>::type V; return integralType<V>(); } }
  • 21. Variadic templates • Variadic templates allow implementation of a compile time type safe printf(…) • Variadic templates combined with compile time type identification gives super powers to C++ • Can collect type information at compile time and use at runtime • Allows creation of an Objective-C style messaging system with late-binding #include <type_traits> #include <functional> #include <string> #include <iostream> #include <iomanip> ! using namespace std; using namespace std::placeholders; ! template<typename T> void reflect_compiler_reflect(T value) { cout << setw(70) << typeid(T).name() << " is_pointer=" << is_pointer<T>::value << " is_integral=" << is_integral<T>::value << " is_floating_point=" << is_floating_point<T>::value << " is_class=" << is_class<T>::value << " is_empty=" << is_empty<T>::value << endl; } ! template<typename T, typename... Args> void reflect_compiler_reflect(T value, Args... args) { reflect_compiler_reflect(value); reflect_compiler_reflect(args...); } ! int main() { int a = 1; float b = 4.5f; double c[71]; string d; auto e = [] (int a) {}; auto f = std::bind(e, 99, _1); struct {} g; reflect_compiler_reflect(a, b, c, d, e, f, g); }
  • 22. User-defined literals • Allow definition of type safe SI units and other creative uses • Solve Mars Climate Orbiter type problems class Symbol { public: string name; Symbol(const char *name) : name(name) {} }; ! Symbol operator "" _symbol(const char* name, size_t) { return Symbol(name); } ! int main() { Symbol Foo = "Foo"_symbol; }
  • 23. More functional • lambdas • [], [=], [&] • use in place of old-style function objects • combine with existing STL generic algorithms e.g. std::partition • currying • std::function • std::bind • std::placeholders::_1
  • 24. Lots more STL • Compile time reflection • <type_traits> • Containers • <array>, <unordered_set>, <unordered_map>, <forward_list> • Multi-threading • <atomic>, <thread>, <mutex>, <future>, <condition_variable> • More utility • <tuple>, <regex>, <chrono>, <codecvt> • Numerics • <random>, <ratio>, <cfenv>
  • 25. C++14 auto lambda = [](auto x, auto y) {return x + y;}; • Generic lambdas • lambda initializers • Variable templates • make_unique • Runtime sized arrays • Filesystem (Boost::filesystem) • Networking auto lambda = [value = 1] {return value;}; template<typename T> constexpr T pi = T(3.1415926535897932385); auto u = make_unique<some_type>(ctor, params); void foo(size_t n) { int a[n]; }
  • 26. LLVM / Clang • Modular compiler toolchain • 2012 ACM Software System Award • Clang memory sanitizer • Clang address sanitizer • Clang thread sanitizer • Clang modernize • Firefox - emscripten C++ to asm.js • Chrome - PNaCl C++ LLVM bitcode • Foundation of many OpenCL implementations
  • 27. C++ - pros • Maturity and Performance • 30 years of evolution and production use in large scale systems • ~ 2x - 3x faster than Java • ~ 10x - 100x faster than Ruby and Python • Compiler and architecture choices • GCC 4.9, Clang 3.4, Intel C++ 14, Visual C++ 2013, etc • Easy access to processor features • SSE4 Streaming Extensions, AVX-512 SIMD Vector Extensions • Compile time static checking and type safety • Static analysis tools, valgrind, clang memory sanitizer,… • Multi-paradigm • Offers a choice of programming styles
  • 28. C++ - cons • Big language, big learning curve • Define an idiom with C++: google c++ style • Long compile times • Idea is to spend time now to save it in the future • Missing standard libraries • networking, database, graphics, sound, xml and json serialization, etc • The cost of runtime performance • Buffer overflows,Illegal memory accesses • Requires static analysis • Potential solution: Intel MPX (Memory Protection Extensions)
  • 29. Conclusion • Pick the right language for the job • C++ is suitable for infrastructure code where performance and type safety are important • C++ requires care with memory management (leaks, buffer offer-flows, off-by-one errors) • Give C++ a go!