SlideShare a Scribd company logo
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

PPS
Commenting Best Practices
PPTX
Presentatie .NET 4/VS2010
PPTX
Code Generation using T4
PDF
Of complicacy of programming, or won't C# save us?
PPTX
The Little Wonders of C# 6
PPTX
New features in C# 6
PPTX
C++ vs C#
PDF
Hexagonal architecture
Commenting Best Practices
Presentatie .NET 4/VS2010
Code Generation using T4
Of complicacy of programming, or won't C# save us?
The Little Wonders of C# 6
New features in C# 6
C++ vs C#
Hexagonal architecture

What's hot (19)

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

Similar to why c++11? (20)

PPTX
Modern C++
PPTX
Return of c++
PDF
C++11
PDF
Modern C++
PPTX
Useful C++ Features You Should be Using
PPTX
Whats New in Visual Studio 2012 for C++ Developers
PDF
C++11 Was Only the Beginning
PDF
C++: a fast tour of a fast language
PPTX
C++ 11 Features
PPTX
Summary of C++17 features
PPT
Gentle introduction to modern C++
PPTX
PDF
How to make a large C++-code base manageable
PPTX
Modern C++ Lunch and Learn
PDF
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
PPTX
C++ Langauage Training in Ambala ! BATRA COMPUTER CENTRE
PDF
C++ Training
PDF
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
Modern C++
Return of c++
C++11
Modern C++
Useful C++ Features You Should be Using
Whats New in Visual Studio 2012 for C++ Developers
C++11 Was Only the Beginning
C++: a fast tour of a fast language
C++ 11 Features
Summary of C++17 features
Gentle introduction to modern C++
How to make a large C++-code base manageable
Modern C++ Lunch and Learn
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
C++ Langauage Training in Ambala ! BATRA COMPUTER CENTRE
C++ Training
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
lecture02-cpp.ppt
lecture02-cpp.ppt
Ad

Recently uploaded (20)

PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
medical staffing services at VALiNTRY
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
System and Network Administraation Chapter 3
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
System and Network Administration Chapter 2
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
top salesforce developer skills in 2025.pdf
How Creative Agencies Leverage Project Management Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
medical staffing services at VALiNTRY
Wondershare Filmora 15 Crack With Activation Key [2025
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PTS Company Brochure 2025 (1).pdf.......
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
System and Network Administraation Chapter 3
Odoo Companies in India – Driving Business Transformation.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
System and Network Administration Chapter 2
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Understanding Forklifts - TECH EHS Solution
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
2025 Textile ERP Trends: SAP, Odoo & Oracle
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 41
ManageIQ - Sprint 268 Review - Slide Deck
top salesforce developer skills in 2025.pdf

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;