SlideShare a Scribd company logo
New in C++11 
Trần Duy Quang – May 2014
Agenda 
1. Automatic variables 
2. Decltype 
3. Rvalue reference 
4. Lambda function 
5. Variadic template 
6. Concurrency library 
2
Compiler support 
3 
VS 2010 
Automatic 
variables 
Decltype 
Rvalue 
reference 
Lambda 
function 
VS 2012 
Concurrency 
library 
Memory 
model 
VS 2013 
Variadic 
template 
Custom 
literal 
Delegating 
constructor 
VS 13: Some C++14 features!
auto Variables 
 Implicit variable declaration 
 Keyword: auto 
Note: cbegin to iterate constant, no change in content 4
Careful: auto default 
 By-value for references 
 Use auto& or decltype for desired result! 
5 
int f, not int& f!
More mindblow 
 int&: auto is int (only, no &) 
 But int*: auto is int* ! 
6
std::bind 
 Placeholder objects _1, _2, .., _N 
 C# alike 
7 
1. May cause runtime error, but when? 
2. What about _10 rather than _2?
Range-based for loop 
8 
Better? auto&!
decltype 
 Query the type of an expression 
 Primary use in generic programming1 
Why do we have to use auto & decltype here? 
1Algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters 9
auto without decltype 
 Compile error 
10
Why auto & decltype? 
11
Parenthesized variable 
 Always a reference! 
12
decltype vs auto 
 decltype of a variable 
 returns the type of that variable, including top-level 
const and references 
 decltype depends on its form of variable 
 Parenthesis always yield a reference 
13 
C++ Primer 2014:
What do we have? 
14 
Type of x 
Type of y 
Why? 
decltype(x) y auto y = x 
const int const int int Strips top-level cv-qualifiers 
int[100] int[100] int* Performs array to pointer conversion 
int f (int) int f (int) int (*) (int) Performs function to function pointer 
conversion 
int& int& int Auto remove references 
int&& int&& int 
Don’t forget the reference with parenthesis from decltype! decltype( (x) )
auto vs decltype conclustion 
 auto 
 Everyday use 
 Assign the value of some expression to a new variable 
 decltype 
 Template & generic programming (library code) 
 a new variable with precisely the same type 
15
More mindblow (again) 
 decltype(auto) f = expression; // C++14 
 C++17 will go further? No ideas! 
16
Lambda function 
17
Lambda function 
 []: capture list 
 [] () -> return type 
18
Lambda capture 
 Capture by value 
 42 
 Capture by reference 
 43 
 43 
 (Can be modify 
inside, but not affect 
outside) 
19
Types of capture 
 [=]: automatic capture all by value 
 [&]: automatic capture all by reference 
 [this]: capture this pointer by value 
 [a, &b]: capture a by value and b by reference 
20
Recursive lambda 
21
Stateless lambda 
 Convertible to function pointer! 
 Used with C-style API (e.g. Win32) 
22
High-order function 
 Takes one or more functions as an input 
 Outputs a function 
23 
Sắp xếp tăng dần
Generic lambda 
 Take a deep breath! (C++14 only) 
 We can write 
 auto auto (auto auto) { auto; }; 
 Compiler infers the rest from the context 
 Actually, this is NOT a type deduction 
 This is a template! 
24
Let’s see one generic lambda 
25 Did I tell you about functor?
Lambda physiology 
 For each lambda compiler generate a class 
 Specifying lambda instantiate an object 
 Invoking lambda call the object’s operator() 
26
Rvalue reference 
27
Rvalue definition 
 lvalue: can appear on the left and right 
 rvalue: can only appear on the right 
28
Move semantics 
 What do we need from the last line? 
 Destruct the resource held by hello first 
 Clone resource from temp returned 
 Destruct temp & release its resources 
29 
 More efficient? 
 Swap resources pointers 
 Let temp destructor destruct hello’s original resources
Obvious solution 
 Overload operator= ! (Copy assignment) 
 Right hand side should be passed by reference 
 rvalue references! 
 MyString&&: rvalue reference to MyString& 
30
Function overload resolution 
 “Am I being called on an lvalue or rvalue?” 
31
Achieving move semantics 
 Should occur only for copy constructor and 
assignment operator! 
32
Forcing move semantics 
 std::move help 
 Type with no move semantics implementation? 
 Swap like old times! 
33
Funny jokes 
34
Smart pointers 
35
Three types of smart pointer 
 unique_ptr<T> - Single ownership 
 Deleted when pointer dies 
 shared_ptr<T> - Shared ownership 
 Reference pointer counting 
 weak_ptr<T> - Cycle breaking 
 auto_ptr deprecated! 
36
Before we go on 
 Resource Acquisition Is Initialization (RAII) 
37
 RAII in C++ has been around for over a decade 
 C++11 encourages its use as default 
 Smart pointers help building RAII around legacy 
interfaces 
 Move semantics makes passing resources around 
cheap 
38
unique_ptr 
39
shared_ptr 
 Last pointer dies, object is deleted 
40
weak_ptr 
 Does not affect reference count 
 Break cycles between shared_ptrs 
41
Some other things 
42
Threads & Async 
43
Variadic template 
44
Rules of expansion 
45
Initializer list 
46
using 
47
Raw string literals 
48
Other examples of raw string literals 
49
Tuple 
50
Default & delete 
51
The last coffee drop 
52
C++ Accelerated Massive 
Parallelism 
53
Simple example 
54 
Normal version AMP version
Basic elements of AMP 
55 
Code run on 
each thread 
Thread id 
running the 
lambda 
Check if code can run 
with AMP / Direct3D
Reference 1 
 Slide C++11 
 Slide What’s new in C++11 
 Slide The future of C++ 
 Slide The style of C++11 
 Slide C++11 
 Slide C++11 idioms 
 Slide What’s new in Visual C++11 
 Slide C++11 – Feel the new language 
 Slide C++11 Talk 
56
Reference 2 
 Slide C++11 – A change in style 
 Slide New C++ Standard – C++11 
 Slide Advanced C++ runtime improvement 
techniques 
 Slide Hot C+11 Rvalue references and Move 
semantics 
 Slide C++ usage experience 
57
Reference 3 
 Ebook C++11 for programmers 2014 
 Ebook C++ Primer 5th Edition 2013 
 Ebook C Primer Plus 2014 
 Ebook Effective C++ 3rd Ed 55 Specific Ways to 
Improve Your Programs and Designs 2005 
 Ebook Effective C++ & More effective C++ 
58

More Related Content

What's hot

Modern C++
Modern C++Modern C++
Modern C++
Michael Clark
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
mspline
 
Le langage rust
Le langage rustLe langage rust
Le langage rust
Geeks Anonymes
 
C++11
C++11C++11
What's New in C++ 11?
What's New in C++ 11?What's New in C++ 11?
What's New in C++ 11?
Sasha Goldshtein
 
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
 
C++ 11
C++ 11C++ 11
Gentle introduction to modern C++
Gentle introduction to modern C++Gentle introduction to modern C++
Gentle introduction to modern C++
Mihai Todor
 
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
Francesco Casalegno
 
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
Francesco Casalegno
 
C++ Presentation
C++ PresentationC++ Presentation
C++ Presentation
Carson Wilber
 
The Style of C++ 11
The Style of C++ 11The Style of C++ 11
The Style of C++ 11
Sasha Goldshtein
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
harman kaur
 
C++ theory
C++ theoryC++ theory
C++ theory
Shyam Khant
 
C++ Training
C++ TrainingC++ Training
C++ Training
SubhendraBasu5
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
fawzmasood
 
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
 
Smart Pointers in C++
Smart Pointers in C++Smart Pointers in C++
Smart Pointers in C++
Francesco Casalegno
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
corehard_by
 
Regular types in C++
Regular types in C++Regular types in C++
Regular types in C++
Ilio Catallo
 

What's hot (20)

Modern C++
Modern C++Modern C++
Modern C++
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
 
Le langage rust
Le langage rustLe langage rust
Le langage rust
 
C++11
C++11C++11
C++11
 
What's New in C++ 11?
What's New in C++ 11?What's New in C++ 11?
What's New in C++ 11?
 
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)
 
C++ 11
C++ 11C++ 11
C++ 11
 
Gentle introduction to modern C++
Gentle introduction to modern C++Gentle introduction to modern C++
Gentle introduction to modern C++
 
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++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
 
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
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
 
C++ theory
C++ theoryC++ theory
C++ theory
 
C++ Training
C++ TrainingC++ Training
C++ Training
 
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)
 
Smart Pointers in C++
Smart Pointers in C++Smart Pointers in C++
Smart Pointers in C++
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
Regular types in C++
Regular types in C++Regular types in C++
Regular types in C++
 

Viewers also liked

Changes in c++0x
Changes in c++0xChanges in c++0x
Changes in c++0x
4002 JOF
 
[OLD VERSION, SEE DESCRIPTION FOR NEWER VERSION LINK] Hot C++: Rvalue Referen...
[OLD VERSION, SEE DESCRIPTION FOR NEWER VERSION LINK] Hot C++: Rvalue Referen...[OLD VERSION, SEE DESCRIPTION FOR NEWER VERSION LINK] Hot C++: Rvalue Referen...
[OLD VERSION, SEE DESCRIPTION FOR NEWER VERSION LINK] Hot C++: Rvalue Referen...
Andrey Upadyshev
 
C++ Builder 程式撰寫基礎 / C++ Builder Basic
C++ Builder 程式撰寫基礎 / C++ Builder Basic C++ Builder 程式撰寫基礎 / C++ Builder Basic
C++ Builder 程式撰寫基礎 / C++ Builder Basic
YKLee3434
 
TCP/IP
TCP/IPTCP/IP
Web I - 05 - HTTP Protocol
Web I - 05 - HTTP ProtocolWeb I - 05 - HTTP Protocol
Web I - 05 - HTTP Protocol
Randy Connolly
 
Bjarne essencegn13
Bjarne essencegn13Bjarne essencegn13
Bjarne essencegn13
Hunde Gurmessa
 
"Http protocol and other stuff" by Bipin Upadhyay
"Http protocol and other stuff" by Bipin Upadhyay"Http protocol and other stuff" by Bipin Upadhyay
"Http protocol and other stuff" by Bipin Upadhyay
Bipin Upadhyay
 
HTTP Protocol Basic
HTTP Protocol BasicHTTP Protocol Basic
HTTP Protocol Basic
Chuong Mai
 
C++17 - the upcoming revolution (Code::Dive 2015)/
C++17 - the upcoming revolution (Code::Dive 2015)/C++17 - the upcoming revolution (Code::Dive 2015)/
C++17 - the upcoming revolution (Code::Dive 2015)/
Sławomir Zborowski
 
Elements of C++11
Elements of C++11Elements of C++11
Elements of C++11
Uilian Ries
 
Networking - TCP/IP stack introduction and IPv6
Networking - TCP/IP stack introduction and IPv6Networking - TCP/IP stack introduction and IPv6
Networking - TCP/IP stack introduction and IPv6
Rodolfo Kohn
 
Database connectivity to sql server asp.net
Database connectivity to sql server asp.netDatabase connectivity to sql server asp.net
Database connectivity to sql server asp.net
Hemant Sankhla
 
C++11 Idioms @ Silicon Valley Code Camp 2012
C++11 Idioms @ Silicon Valley Code Camp 2012 C++11 Idioms @ Silicon Valley Code Camp 2012
C++11 Idioms @ Silicon Valley Code Camp 2012
Sumant Tambe
 
C++ 11 Style : A Touch of Class
C++ 11 Style : A Touch of ClassC++ 11 Style : A Touch of Class
C++ 11 Style : A Touch of Class
Yogendra Rampuria
 
C# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slidesC# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slides
Sami Mut
 
C++11 smart pointers
C++11 smart pointersC++11 smart pointers
C++11 smart pointers
chchwy Chang
 
Data structures / C++ Program examples
Data structures / C++ Program examplesData structures / C++ Program examples
Data structures / C++ Program examples
Kevin III
 
Cpp17 and Beyond
Cpp17 and BeyondCpp17 and Beyond
Cpp17 and Beyond
ComicSansMS
 
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)
Guy Podjarny
 

Viewers also liked (20)

Changes in c++0x
Changes in c++0xChanges in c++0x
Changes in c++0x
 
[OLD VERSION, SEE DESCRIPTION FOR NEWER VERSION LINK] Hot C++: Rvalue Referen...
[OLD VERSION, SEE DESCRIPTION FOR NEWER VERSION LINK] Hot C++: Rvalue Referen...[OLD VERSION, SEE DESCRIPTION FOR NEWER VERSION LINK] Hot C++: Rvalue Referen...
[OLD VERSION, SEE DESCRIPTION FOR NEWER VERSION LINK] Hot C++: Rvalue Referen...
 
C++ Builder 程式撰寫基礎 / C++ Builder Basic
C++ Builder 程式撰寫基礎 / C++ Builder Basic C++ Builder 程式撰寫基礎 / C++ Builder Basic
C++ Builder 程式撰寫基礎 / C++ Builder Basic
 
TCP/IP
TCP/IPTCP/IP
TCP/IP
 
Web I - 05 - HTTP Protocol
Web I - 05 - HTTP ProtocolWeb I - 05 - HTTP Protocol
Web I - 05 - HTTP Protocol
 
Bjarne essencegn13
Bjarne essencegn13Bjarne essencegn13
Bjarne essencegn13
 
"Http protocol and other stuff" by Bipin Upadhyay
"Http protocol and other stuff" by Bipin Upadhyay"Http protocol and other stuff" by Bipin Upadhyay
"Http protocol and other stuff" by Bipin Upadhyay
 
HTTP Protocol Basic
HTTP Protocol BasicHTTP Protocol Basic
HTTP Protocol Basic
 
C++17 - the upcoming revolution (Code::Dive 2015)/
C++17 - the upcoming revolution (Code::Dive 2015)/C++17 - the upcoming revolution (Code::Dive 2015)/
C++17 - the upcoming revolution (Code::Dive 2015)/
 
Elements of C++11
Elements of C++11Elements of C++11
Elements of C++11
 
Networking - TCP/IP stack introduction and IPv6
Networking - TCP/IP stack introduction and IPv6Networking - TCP/IP stack introduction and IPv6
Networking - TCP/IP stack introduction and IPv6
 
Database connectivity to sql server asp.net
Database connectivity to sql server asp.netDatabase connectivity to sql server asp.net
Database connectivity to sql server asp.net
 
C++11 Idioms @ Silicon Valley Code Camp 2012
C++11 Idioms @ Silicon Valley Code Camp 2012 C++11 Idioms @ Silicon Valley Code Camp 2012
C++11 Idioms @ Silicon Valley Code Camp 2012
 
C++14 Overview
C++14 OverviewC++14 Overview
C++14 Overview
 
C++ 11 Style : A Touch of Class
C++ 11 Style : A Touch of ClassC++ 11 Style : A Touch of Class
C++ 11 Style : A Touch of Class
 
C# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slidesC# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slides
 
C++11 smart pointers
C++11 smart pointersC++11 smart pointers
C++11 smart pointers
 
Data structures / C++ Program examples
Data structures / C++ Program examplesData structures / C++ Program examples
Data structures / C++ Program examples
 
Cpp17 and Beyond
Cpp17 and BeyondCpp17 and Beyond
Cpp17 and Beyond
 
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)
 

Similar to C++11

Intro to c++
Intro to c++Intro to c++
Intro to c++
temkin abdlkader
 
The Goal and The Journey - Turning back on one year of C++14 Migration
The Goal and The Journey - Turning back on one year of C++14 MigrationThe Goal and The Journey - Turning back on one year of C++14 Migration
The Goal and The Journey - Turning back on one year of C++14 Migration
Joel Falcou
 
Whats New in Visual Studio 2012 for C++ Developers
Whats New in Visual Studio 2012 for C++ DevelopersWhats New in Visual Studio 2012 for C++ Developers
Whats New in Visual Studio 2012 for C++ Developers
Rainer Stropek
 
Can't Dance The Lambda
Can't Dance The LambdaCan't Dance The Lambda
Can't Dance The Lambda
Togakangaroo
 
Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic Server
Apache Traffic Server
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
Ralph Weber
 
Cling the llvm based interpreter
Cling the llvm based interpreterCling the llvm based interpreter
Cling the llvm based interpreter
Roberto Nogueira
 
C++ question and answers
C++ question and answersC++ question and answers
C++ question and answers
AdenKheire
 
What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
Mohsen Zainalpour
 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)
Shoaib Ghachi
 
Rcpp
RcppRcpp
Rcpp
Ajay Ohri
 
Technical trainning.pptx
Technical trainning.pptxTechnical trainning.pptx
Technical trainning.pptx
SanuSan3
 
C material
C materialC material
C material
tarique472
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
SRamadossbiher
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
SRamadossbiher
 
Combating software entropy 2-roc1-
Combating software entropy 2-roc1-Combating software entropy 2-roc1-
Combating software entropy 2-roc1-
Hammad Rajjoub
 
LLVM
LLVMLLVM
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
Abishek Purushothaman
 
C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New FeaturesC#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Features
techfreak
 
C programming
C programmingC programming

Similar to C++11 (20)

Intro to c++
Intro to c++Intro to c++
Intro to c++
 
The Goal and The Journey - Turning back on one year of C++14 Migration
The Goal and The Journey - Turning back on one year of C++14 MigrationThe Goal and The Journey - Turning back on one year of C++14 Migration
The Goal and The Journey - Turning back on one year of C++14 Migration
 
Whats New in Visual Studio 2012 for C++ Developers
Whats New in Visual Studio 2012 for C++ DevelopersWhats New in Visual Studio 2012 for C++ Developers
Whats New in Visual Studio 2012 for C++ Developers
 
Can't Dance The Lambda
Can't Dance The LambdaCan't Dance The Lambda
Can't Dance The Lambda
 
Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic Server
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 
Cling the llvm based interpreter
Cling the llvm based interpreterCling the llvm based interpreter
Cling the llvm based interpreter
 
C++ question and answers
C++ question and answersC++ question and answers
C++ question and answers
 
What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)
 
Rcpp
RcppRcpp
Rcpp
 
Technical trainning.pptx
Technical trainning.pptxTechnical trainning.pptx
Technical trainning.pptx
 
C material
C materialC material
C material
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
 
Combating software entropy 2-roc1-
Combating software entropy 2-roc1-Combating software entropy 2-roc1-
Combating software entropy 2-roc1-
 
LLVM
LLVMLLVM
LLVM
 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
 
C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New FeaturesC#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Features
 
C programming
C programmingC programming
C programming
 

Recently uploaded

AI-Based Home Security System : Home security
AI-Based Home Security System : Home securityAI-Based Home Security System : Home security
AI-Based Home Security System : Home security
AIRCC Publishing Corporation
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
Kamal Acharya
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
PreethaV16
 
5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf
AlvianRamadhani5
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
Kamal Acharya
 
Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...
cannyengineerings
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
b0754201
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
ijseajournal
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
aryanpankaj78
 
P5 Working Drawings.pdf floor plan, civil
P5 Working Drawings.pdf floor plan, civilP5 Working Drawings.pdf floor plan, civil
P5 Working Drawings.pdf floor plan, civil
AnasAhmadNoor
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
nedcocy
 
TIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptxTIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptx
CVCSOfficial
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
Paris Salesforce Developer Group
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
PreethaV16
 
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Transcat
 
SCALING OF MOS CIRCUITS m .pptx
SCALING OF MOS CIRCUITS m                 .pptxSCALING OF MOS CIRCUITS m                 .pptx
SCALING OF MOS CIRCUITS m .pptx
harshapolam10
 

Recently uploaded (20)

AI-Based Home Security System : Home security
AI-Based Home Security System : Home securityAI-Based Home Security System : Home security
AI-Based Home Security System : Home security
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
 
5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
 
Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
 
P5 Working Drawings.pdf floor plan, civil
P5 Working Drawings.pdf floor plan, civilP5 Working Drawings.pdf floor plan, civil
P5 Working Drawings.pdf floor plan, civil
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
 
TIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptxTIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptx
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
 
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
 
SCALING OF MOS CIRCUITS m .pptx
SCALING OF MOS CIRCUITS m                 .pptxSCALING OF MOS CIRCUITS m                 .pptx
SCALING OF MOS CIRCUITS m .pptx
 

C++11

  • 1. New in C++11 Trần Duy Quang – May 2014
  • 2. Agenda 1. Automatic variables 2. Decltype 3. Rvalue reference 4. Lambda function 5. Variadic template 6. Concurrency library 2
  • 3. Compiler support 3 VS 2010 Automatic variables Decltype Rvalue reference Lambda function VS 2012 Concurrency library Memory model VS 2013 Variadic template Custom literal Delegating constructor VS 13: Some C++14 features!
  • 4. auto Variables  Implicit variable declaration  Keyword: auto Note: cbegin to iterate constant, no change in content 4
  • 5. Careful: auto default  By-value for references  Use auto& or decltype for desired result! 5 int f, not int& f!
  • 6. More mindblow  int&: auto is int (only, no &)  But int*: auto is int* ! 6
  • 7. std::bind  Placeholder objects _1, _2, .., _N  C# alike 7 1. May cause runtime error, but when? 2. What about _10 rather than _2?
  • 8. Range-based for loop 8 Better? auto&!
  • 9. decltype  Query the type of an expression  Primary use in generic programming1 Why do we have to use auto & decltype here? 1Algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters 9
  • 10. auto without decltype  Compile error 10
  • 11. Why auto & decltype? 11
  • 12. Parenthesized variable  Always a reference! 12
  • 13. decltype vs auto  decltype of a variable  returns the type of that variable, including top-level const and references  decltype depends on its form of variable  Parenthesis always yield a reference 13 C++ Primer 2014:
  • 14. What do we have? 14 Type of x Type of y Why? decltype(x) y auto y = x const int const int int Strips top-level cv-qualifiers int[100] int[100] int* Performs array to pointer conversion int f (int) int f (int) int (*) (int) Performs function to function pointer conversion int& int& int Auto remove references int&& int&& int Don’t forget the reference with parenthesis from decltype! decltype( (x) )
  • 15. auto vs decltype conclustion  auto  Everyday use  Assign the value of some expression to a new variable  decltype  Template & generic programming (library code)  a new variable with precisely the same type 15
  • 16. More mindblow (again)  decltype(auto) f = expression; // C++14  C++17 will go further? No ideas! 16
  • 18. Lambda function  []: capture list  [] () -> return type 18
  • 19. Lambda capture  Capture by value  42  Capture by reference  43  43  (Can be modify inside, but not affect outside) 19
  • 20. Types of capture  [=]: automatic capture all by value  [&]: automatic capture all by reference  [this]: capture this pointer by value  [a, &b]: capture a by value and b by reference 20
  • 22. Stateless lambda  Convertible to function pointer!  Used with C-style API (e.g. Win32) 22
  • 23. High-order function  Takes one or more functions as an input  Outputs a function 23 Sắp xếp tăng dần
  • 24. Generic lambda  Take a deep breath! (C++14 only)  We can write  auto auto (auto auto) { auto; };  Compiler infers the rest from the context  Actually, this is NOT a type deduction  This is a template! 24
  • 25. Let’s see one generic lambda 25 Did I tell you about functor?
  • 26. Lambda physiology  For each lambda compiler generate a class  Specifying lambda instantiate an object  Invoking lambda call the object’s operator() 26
  • 28. Rvalue definition  lvalue: can appear on the left and right  rvalue: can only appear on the right 28
  • 29. Move semantics  What do we need from the last line?  Destruct the resource held by hello first  Clone resource from temp returned  Destruct temp & release its resources 29  More efficient?  Swap resources pointers  Let temp destructor destruct hello’s original resources
  • 30. Obvious solution  Overload operator= ! (Copy assignment)  Right hand side should be passed by reference  rvalue references!  MyString&&: rvalue reference to MyString& 30
  • 31. Function overload resolution  “Am I being called on an lvalue or rvalue?” 31
  • 32. Achieving move semantics  Should occur only for copy constructor and assignment operator! 32
  • 33. Forcing move semantics  std::move help  Type with no move semantics implementation?  Swap like old times! 33
  • 36. Three types of smart pointer  unique_ptr<T> - Single ownership  Deleted when pointer dies  shared_ptr<T> - Shared ownership  Reference pointer counting  weak_ptr<T> - Cycle breaking  auto_ptr deprecated! 36
  • 37. Before we go on  Resource Acquisition Is Initialization (RAII) 37
  • 38.  RAII in C++ has been around for over a decade  C++11 encourages its use as default  Smart pointers help building RAII around legacy interfaces  Move semantics makes passing resources around cheap 38
  • 40. shared_ptr  Last pointer dies, object is deleted 40
  • 41. weak_ptr  Does not affect reference count  Break cycles between shared_ptrs 41
  • 49. Other examples of raw string literals 49
  • 52. The last coffee drop 52
  • 53. C++ Accelerated Massive Parallelism 53
  • 54. Simple example 54 Normal version AMP version
  • 55. Basic elements of AMP 55 Code run on each thread Thread id running the lambda Check if code can run with AMP / Direct3D
  • 56. Reference 1  Slide C++11  Slide What’s new in C++11  Slide The future of C++  Slide The style of C++11  Slide C++11  Slide C++11 idioms  Slide What’s new in Visual C++11  Slide C++11 – Feel the new language  Slide C++11 Talk 56
  • 57. Reference 2  Slide C++11 – A change in style  Slide New C++ Standard – C++11  Slide Advanced C++ runtime improvement techniques  Slide Hot C+11 Rvalue references and Move semantics  Slide C++ usage experience 57
  • 58. Reference 3  Ebook C++11 for programmers 2014  Ebook C++ Primer 5th Edition 2013  Ebook C Primer Plus 2014  Ebook Effective C++ 3rd Ed 55 Specific Ways to Improve Your Programs and Designs 2005  Ebook Effective C++ & More effective C++ 58

Editor's Notes

  1. Chú ý: cbegin là duyệt container hằng số (constant begin), duyệt không cho phép thay đổi cấu trúc / dữ liệu
  2. Inside the for, you need to specify the alias auto& in order to avoid to create a copy of the elements inside the vector within the thread variable. In this way every operations done on the thread var is done on the element inside the threads vector. Moreover, in a range-based for, you always want to use a reference & for performance reasons.
  3. In the C++ programming language, decltype is a keyword used to query the type of an expression. It was introduced in the current version of the C++ standard, C++11. Its primary intended use is in generic programming, where it is often difficult, or even impossible, to express types that depend on template parameters. Algorithms are written in terms of to-be-specified-later types that are then instantiated when needed for specific types provided as parameters. This approach, pioneered by ML in 1973,[citation needed] permits writing common functions or types that differ only in the set of types on which they operate when used, thus reducing duplication
  4. Có thể tự viết các string literal của riêng mình