SlideShare a Scribd company logo
1 of 2
Reasons to start using C++11
If our code is working fine and performing well, everyone will be wondering why
you should jump on the C++11? Sure, it feels nice to be using the latest
technology, but is it actually worthwhile? In my opinion, the answer is a
definite yes. I will add some reasons to get into C++11 below. Reasons will be
aligned comparing performance benefits and developer productivity.
Get performance benefits
1. Move Semantics. To explain the concept very briefly, it s a way to
optimize copying. Sometimes copying is obviously wasteful. If you re copying
from a temporary string object, simply copying the pointer to the character
buffer would be much more efficient than creating a new buffer and copying the
character. It would work because the source object is about to go out of scope.
However, previously there was no mechanism in C++ to figure out whether the
source object is a temporary or not. Move semantics provide this mechanism by
allowing you to have a move constructor and a move assignment operator in
addition to the copy operations. Move semantics helps prevent unnecessary
copying and therefore improve performance.By implementing move semantics in your
own classes you can get additional performance improvements, for example when
you store them in STL containers. Also, keep in mind that move semantics can be
applied not only to constructors, but also to methods (such as
vector spush_back).
2. type traits (e.g. is_floating_point) and template metaprogramming (e.g.
the enable_if template), you can specialize your templates for types with
particular characteristics and thus implement optimizations.
3. The hash tables which have now become standard provide faster insertion,
deletion and lookup than their ordered counterparts, which can be very useful
when handling large amounts of data. You now have unordered_map,
unordered_multimap, unordered_set andunordered_multiset at your disposal.
Improve your productivity
It s not all about the performance of your code though. time is valuable too,
and C++11 can make you more productive by making your code shorter, clearer and
easier to read.
4. The auto keyword provides type inference, so instead of
vector<vector<MyType>>::const_iterator it = v.begin()
you can now simply write
auto it = v.cbegin()
Although some people complain that it obscures type information, in my opinion
the benefits are more important, as it reduces visual clutter and reveals the
behavior that the code expresses. And there s a lot less typing!
5. Lambda expressions provide a way to define anonymous function objects
(which are actually closures) right where they are used, thus making the code
more linear and easier to follow. This is very convenient in combination with
STL algorithms:
bool is_fuel_level_safe()
{
return all_of(_tanks.begin(), _tanks.end(),
[this](Tank& t) { return t.fuel_level() > _min_fuel_level; });
}
6. The new smart pointers which have replaced the problematic auto_ptr allow
you to stop worrying about memory cleanup, and to remove the cleanup code.
It s good for clarity, and for avoiding memory leaks and the associated time
spent to hunt them down.
7. Having functions as first class objects is a very powerful feature that
allows your code to be flexible and generic. C++11 makes a step in this
direction with std::function. Function provides a way to wrap and pass around
anything callable   function pointers, functors, lambdas and more.
8. There are many other smaller features such as the override and final (or
the non-standard sealed in Visual Studio) keywords and nullptr allow you to to
be clearer the intent of your code.For me, less visual clutter and being able to
express my intentions in code more clearly means I m happier and more
productive.
9. Error detection. If your errors happen at runtime, it means that at the
very least you need to run the software, and probably perform a series of steps
to reproduce the error. This takes time.C++11 provides a way to check
preconditions and catch errors at the earliest possible opportunity   during
compilation, before you even run the code, which is this is achieved by using
static_assert and the type traits templates. Another advantage of this approach
is that such checks don t incur any runtime overhead   one more point for
performance!
10. Strongly-typed enums "Traditional" enums in C++ have some drawbacks: they
export their enumerators in the surrounding scope (which can lead to name
collisions, if two different enums in the same have scope define enumerators
with the same name), they are implicitly converted to integral types and cannot
have a user-specified underlying type. These issues have been fixed in C++ 11
with the introduction of a new category of enums, called strongly-typed enums.
They are specified with the enum class keywords. They no longer export their
enumerators in the surrounding scope, are no longer implicitly converted to
integral types and can have a user-specified underlying type (a feature also
added for traditional enums).
enum class Options {None, One, All};
Options o = Options::All;

More Related Content

What's hot

Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.
gerrell
 
Asp.net MVC - Course 2
Asp.net MVC - Course 2Asp.net MVC - Course 2
Asp.net MVC - Course 2
erdemergin
 

What's hot (19)

Greg Demo Slides
Greg Demo SlidesGreg Demo Slides
Greg Demo Slides
 
My final requirement
My final requirementMy final requirement
My final requirement
 
Tutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng verTutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng ver
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.
 
Coding Best Practices
Coding Best PracticesCoding Best Practices
Coding Best Practices
 
Asp.net MVC - Course 2
Asp.net MVC - Course 2Asp.net MVC - Course 2
Asp.net MVC - Course 2
 
Educating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz TamirEducating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz Tamir
 
Can't Dance The Lambda
Can't Dance The LambdaCan't Dance The Lambda
Can't Dance The Lambda
 
Class7
Class7Class7
Class7
 
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
Comparing the general static analysis in Visual Studio 2010 and PVS-Studio by...
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
 
Combating software entropy 2-roc1-
Combating software entropy 2-roc1-Combating software entropy 2-roc1-
Combating software entropy 2-roc1-
 
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...
 
Ruby Blocks
Ruby BlocksRuby Blocks
Ruby Blocks
 
C#/.NET Little Wonders
C#/.NET Little WondersC#/.NET Little Wonders
C#/.NET Little Wonders
 
Code Contracts API In .Net
Code Contracts API In .NetCode Contracts API In .Net
Code Contracts API In .Net
 
Constraint-ly motion - making your app dance - John Hoford, Google
Constraint-ly motion - making your app dance - John Hoford, GoogleConstraint-ly motion - making your app dance - John Hoford, Google
Constraint-ly motion - making your app dance - John Hoford, Google
 
Cordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to JavascriptCordova training : Day 3 - Introduction to Javascript
Cordova training : Day 3 - Introduction to Javascript
 
C++basics
C++basicsC++basics
C++basics
 

Similar to why c++11?

Migrating From Cpp To C Sharp
Migrating From Cpp To C SharpMigrating From Cpp To C Sharp
Migrating From Cpp To C Sharp
Ganesh Samarthyam
 
Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net Fundamentals
LiquidHub
 
Perl web programming
Perl web programmingPerl web programming
Perl web programming
Johnny Pork
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
WE-IT TUTORIALS
 
Maintainable Javascript carsonified
Maintainable Javascript carsonifiedMaintainable Javascript carsonified
Maintainable Javascript carsonified
Christian Heilmann
 
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdf
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdfNode.js and the MEAN Stack Building Full-Stack Web Applications.pdf
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdf
lubnayasminsebl
 

Similar to why c++11? (20)

Migrating From Cpp To C Sharp
Migrating From Cpp To C SharpMigrating From Cpp To C Sharp
Migrating From Cpp To C Sharp
 
T2
T2T2
T2
 
We continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShellWe continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShell
 
Node.JS error handling best practices
Node.JS error handling best practicesNode.JS error handling best practices
Node.JS error handling best practices
 
Workshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfWorkshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdf
 
ewili13_submission_14
ewili13_submission_14ewili13_submission_14
ewili13_submission_14
 
Ad505 dev blast
Ad505 dev blastAd505 dev blast
Ad505 dev blast
 
Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net Fundamentals
 
Oops index
Oops indexOops index
Oops index
 
c-for-c-programmers.pdf
c-for-c-programmers.pdfc-for-c-programmers.pdf
c-for-c-programmers.pdf
 
Put to the Test
Put to the TestPut to the Test
Put to the Test
 
Perl web programming
Perl web programmingPerl web programming
Perl web programming
 
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
 
What every C++ programmer should know about modern compilers (w/ comments, AC...
What every C++ programmer should know about modern compilers (w/ comments, AC...What every C++ programmer should know about modern compilers (w/ comments, AC...
What every C++ programmer should know about modern compilers (w/ comments, AC...
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 
Five Common Angular Mistakes
Five Common Angular MistakesFive Common Angular Mistakes
Five Common Angular Mistakes
 
Top 10 Tips for Developing Android Apps Using Kotlin
Top 10 Tips for Developing Android Apps Using KotlinTop 10 Tips for Developing Android Apps Using Kotlin
Top 10 Tips for Developing Android Apps Using Kotlin
 
Maintainable Javascript carsonified
Maintainable Javascript carsonifiedMaintainable Javascript carsonified
Maintainable Javascript carsonified
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdf
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdfNode.js and the MEAN Stack Building Full-Stack Web Applications.pdf
Node.js and the MEAN Stack Building Full-Stack Web Applications.pdf
 

Recently uploaded

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
+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
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 

Recently uploaded (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
+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...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
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-...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
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
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
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 🔝✔️✔️
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 

why c++11?

  • 1. Reasons to start using C++11 If our code is working fine and performing well, everyone will be wondering why you should jump on the C++11? Sure, it feels nice to be using the latest technology, but is it actually worthwhile? In my opinion, the answer is a definite yes. I will add some reasons to get into C++11 below. Reasons will be aligned comparing performance benefits and developer productivity. Get performance benefits 1. Move Semantics. To explain the concept very briefly, it s a way to optimize copying. Sometimes copying is obviously wasteful. If you re copying from a temporary string object, simply copying the pointer to the character buffer would be much more efficient than creating a new buffer and copying the character. It would work because the source object is about to go out of scope. However, previously there was no mechanism in C++ to figure out whether the source object is a temporary or not. Move semantics provide this mechanism by allowing you to have a move constructor and a move assignment operator in addition to the copy operations. Move semantics helps prevent unnecessary copying and therefore improve performance.By implementing move semantics in your own classes you can get additional performance improvements, for example when you store them in STL containers. Also, keep in mind that move semantics can be applied not only to constructors, but also to methods (such as vector spush_back). 2. type traits (e.g. is_floating_point) and template metaprogramming (e.g. the enable_if template), you can specialize your templates for types with particular characteristics and thus implement optimizations. 3. The hash tables which have now become standard provide faster insertion, deletion and lookup than their ordered counterparts, which can be very useful when handling large amounts of data. You now have unordered_map, unordered_multimap, unordered_set andunordered_multiset at your disposal. Improve your productivity It s not all about the performance of your code though. time is valuable too, and C++11 can make you more productive by making your code shorter, clearer and easier to read. 4. The auto keyword provides type inference, so instead of vector<vector<MyType>>::const_iterator it = v.begin() you can now simply write auto it = v.cbegin() Although some people complain that it obscures type information, in my opinion the benefits are more important, as it reduces visual clutter and reveals the behavior that the code expresses. And there s a lot less typing! 5. Lambda expressions provide a way to define anonymous function objects (which are actually closures) right where they are used, thus making the code more linear and easier to follow. This is very convenient in combination with STL algorithms: bool is_fuel_level_safe() { return all_of(_tanks.begin(), _tanks.end(), [this](Tank& t) { return t.fuel_level() > _min_fuel_level; }); } 6. The new smart pointers which have replaced the problematic auto_ptr allow you to stop worrying about memory cleanup, and to remove the cleanup code. It s good for clarity, and for avoiding memory leaks and the associated time spent to hunt them down. 7. Having functions as first class objects is a very powerful feature that allows your code to be flexible and generic. C++11 makes a step in this direction with std::function. Function provides a way to wrap and pass around anything callable   function pointers, functors, lambdas and more. 8. There are many other smaller features such as the override and final (or the non-standard sealed in Visual Studio) keywords and nullptr allow you to to be clearer the intent of your code.For me, less visual clutter and being able to express my intentions in code more clearly means I m happier and more productive. 9. Error detection. If your errors happen at runtime, it means that at the very least you need to run the software, and probably perform a series of steps to reproduce the error. This takes time.C++11 provides a way to check
  • 2. preconditions and catch errors at the earliest possible opportunity   during compilation, before you even run the code, which is this is achieved by using static_assert and the type traits templates. Another advantage of this approach is that such checks don t incur any runtime overhead   one more point for performance! 10. Strongly-typed enums "Traditional" enums in C++ have some drawbacks: they export their enumerators in the surrounding scope (which can lead to name collisions, if two different enums in the same have scope define enumerators with the same name), they are implicitly converted to integral types and cannot have a user-specified underlying type. These issues have been fixed in C++ 11 with the introduction of a new category of enums, called strongly-typed enums. They are specified with the enum class keywords. They no longer export their enumerators in the surrounding scope, are no longer implicitly converted to integral types and can have a user-specified underlying type (a feature also added for traditional enums). enum class Options {None, One, All}; Options o = Options::All;