SlideShare uma empresa Scribd logo
1 de 25
Richard Thomson
Principal Architect for Modeling, Daz 3D
legalize@xmission.com
@LegalizeAdulthd
LegalizeAdulthood.wordpress.com
Thanks to our Sponsors!
Community Sponsor
Yearly Sponsor
Marquee Sponsor
About Me...
 Meetup organizer:
 Utah C++ Programmers (2nd Wednesday)
 Salt Lake City Software Craftsmanship (1st Thursday)
 3D Modelers (3rd Tuesday)
 C++ language track on exercism.io
 Polyglot developer
 Currently: C++, JavaScript/NodeJS
 Previously: C#, JavaScript/NodeJS, Python, Java
 Distantly: C, Perl, FORTRAN, LISP, FORTH, Assembly, TECO
 Different languages have their strengths
 Leverage strengths where appropriate
Why Use C++?
 Type safety
 Encapsulate necessary unsafe operations
 Resource safety
 Not all resource management is managing memory
 Performance
 For some parts of almost all systems, it's important
 Predictability
 For hard or soft real-time systems
Why Use C++?
 Teachability
 Complexity of code should be proportional to
complexity of the task
 Readability
 For people and machines ("analyzability")
 Direct map to hardware
 For instructions and fundamental data types
 Zero-overhead abstraction
 Classes with constructors and destructors, inheritance,
generic programming, functional programming
techniques
ISO Standard for C++
 C++98 1998: First ISO standard
 C++03 2003: "Bug fix" to C++98 standard
 C++11 2011: Major enhancement to language and
library
 C++14 2014: Bug fixes and improvements to C++11
 C++17 2017? Library additions and bug fixes
What is "Modern" C++?
 Embrace the improvements brought by C++11/14
 Eschew old coding practices based on earlier standards
 Avoid like the plague C-style coding practices!
Print Sorted Words from Input
#include <algorithm> // sort
#include <iostream> // cin, cout
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> words;
string input;
while (cin >> input) {
words.push_back(input);
}
sort(begin(words), end(words));
for (auto w : words) {
cout << w << 'n';
}
return 0;
}
one
barney
zoo
betty
fred
alpha
^Z
alpha
barney
betty
fred
one
zoo
Some Observations
 This code accepts input words bounded only by
available memory.
 string is a general-purpose dynamically sized string
class provided by the standard library.
 vector is a standard container for any copyable type,
in this case string.
 sort is a standard library algorithm that operates
polymorphically on sequences of values, in this case
strings.
 begin and end are standard library functions for
iterating over containers, including "raw" arrays.
Print Words Custom Sorted
#include <algorithm> // sort
#include <iostream> // cin, cout
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> words;
string input;
while (cin >> input) {
words.push_back(input);
}
sort(begin(words), end(words),
[](auto lhs, auto rhs) {
return lhs[1] < rhs[1];
});
for (auto w : words) {
cout << w << 'n';
}
return 0;
}
zar
betty
one
alpha
^Z
zar
betty
alpha
one
More Observations
 Standard library algorithms are extensible through
functors (instances of function class objects).
 Lambda functions provide succinct syntax for writing
such functors.
 Range-based for loop allows for easy enumeration of
all values in a collection.
 auto allows us to let the compiler figure out the types.
 C++ standard library algorithms are often more
efficient than their C library counterparts, particularly
when customized with application functors.
Beyond the Language:
IDEs and Tools
 IDEs and tools have also advanced.
 Static analysis tools:
 Finds common problems in C++ code bases.
 Some tools suggest automated fixes for problems.
 Refactoring tools:
 Visual Studio 2015
 Clion
 ReSharper for C++
 clang-tidy
Goals of C++11/14
 Maintain stability and compatibility with prior versions.
 Prefer introducing new features via the standard library instead
of the core language.
 Prefer changes that can evolve programming technique.
 Improve C++ to facilitate systems and library design.
 Improve type safety by providing safer alternatives to earlier
unsafe techniques.
 Increase performance and the ability to work directly with the
hardware.
 Provide proper solutions to real-world problems.
 Implement the zero-overhead principle, aka "don't pay for what
you don't use".
 Make C++ easier to teach and learn.
Performance Additions
 "Move semantics" improve performance of transfer of
ownership of data.
 constexpr generalized constant expressions.
Usability Enhancements
 Uniform initializer syntax.
 Type inference (auto).
 Range-based for loop.
 Lambda functions and
expressions.
 Alternate function syntax
(trailing return type).
 Constructor delegation.
 Field initializers.
 Explicit override and
final.
 Null pointer constant
(nullptr, nullptr_t).
 Strongly-typed
enumerations.
 Right angle bracket.
 Template aliases.
 Unrestricted unions.
Functionality Enhancements
 Variadic templates
 Variadic macros
 New string literals for
Unicode
 User-defined literals
 Multithreading memory
model
 Thread-local storage
 Explicitly defaulting or
deleting special member
functions
 Type long long int
 Static assertions
 Generalized sizeof
 Control of object alignment
 Allow garbage collected
implementations
 Attributes
Standard Library Enhancements
 Upgrades to standard
library components.
 Threading facilities.
 Tuples.
 Hash tables.
 Regular expressions.
 General-purpose smart
pointers.
 Extensible random
number facility.
 Reference wrapper.
 Polymorphic wrappers for
function objects.
 Type traits for
metaprogramming.
 Uniform method for
computing the return
type of function objects.
Modern C++ Idioms
 "Almost always auto"
 "No naked new/delete"
 "No raw loops"
 "No raw owning pointers"
 "Uniform initialization"
 Embrace Zero-overhead Abstraction
Uniform Initialization
 Motivation:
 Simplify initialization by using a uniform syntax for
initializing values of all types.
 int f{3};
 string s{"hello, world!"};
 Foo g{"constructor", "arguments"};
 vector<string> words{"hi", "there"};
Almost Always Auto
 Motivation:
 Let the compiler figure out types as much as is feasible.
 auto x = 42;
 auto x{42};
 Subjective. Some people prefer it; removes the clutter
of types from the code. Others feel that it can obscure
the actual types being used. No supermajority
consensus yet on this idiom.
No Naked new/delete
 Motivation:
 New and delete are low-level heap operations
corresponding to resource allocation. Their low-level
nature can be a source of errors. Therefore, use an
encapsulating class that implements the desired
ownership policy.
 unique_ptr<Foo> f{make_unique<Foo>(x, y)};
 shared_ptr<Foo> g{make_shared<Foo>(x, y)};
 weak_ptr<Foo> h{g};
No Raw Owning Pointers
 Motivation:
 Use a smart pointer class to enforce ownership policies.
Raw pointers and references are still useful for efficiency,
but they no longer represent ownership.
 auto pw = make_shared<widget>();
No Raw Loops
 Motivation:
 The standard library algorithms cover most of what you
need to do. With lambdas for customization, using
them is easy. Write your own algorithms in the style of
the standard library when necessary.
 Sean Parent, "C++ Seasoning" Going Native 2013
 https://channel9.msdn.com/Events/GoingNative/2013
/Cpp-Seasoning
Embrace Zero-Overhead
Abstraction
 Motivation:
 There is no runtime penalty for abstraction, so embrace
it fully.
 Create small, focused types to express specific
semantics on top of general types.
 Examples: Points, (geometric) Vectors, Matrices for 3D
graphics. Small concrete value types can be as efficient
as inline computation.
Practice Modern C++
 http://ideone.com
 Web-based modern C++ development environment
 Quick to experiment, no install, save work for later.
 Visual Studio 2015 Community Edition
 Full-featured IDE with refactoring support.
 Good for full sized projects.
 http://exercism.io
 Practice modern C++ on a variety of problems and get peer
review and discussion of your solution.

Mais conteúdo relacionado

Mais procurados

Generic Programming seminar
Generic Programming seminarGeneric Programming seminar
Generic Programming seminarGautam Roy
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Languagemspline
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 FeaturesJan Rüegg
 
What's New in C++ 11/14?
What's New in C++ 11/14?What's New in C++ 11/14?
What's New in C++ 11/14?Dina Goldshtein
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++Tech_MX
 
Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++Anton Kolotaev
 
Templates presentation
Templates presentationTemplates presentation
Templates presentationmalaybpramanik
 
Oop2011 actor presentation_stal
Oop2011 actor presentation_stalOop2011 actor presentation_stal
Oop2011 actor presentation_stalMichael Stal
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaMichael Stal
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Sayed Ahmed
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handlingsanya6900
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpprajshreemuthiah
 
Web application architecture
Web application architectureWeb application architecture
Web application architectureIlio Catallo
 
Memory management in C++
Memory management in C++Memory management in C++
Memory management in C++Ilio Catallo
 

Mais procurados (20)

Smart Pointers in C++
Smart Pointers in C++Smart Pointers in C++
Smart Pointers in C++
 
Generic Programming seminar
Generic Programming seminarGeneric Programming seminar
Generic Programming seminar
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
What's New in C++ 11/14?
What's New in C++ 11/14?What's New in C++ 11/14?
What's New in C++ 11/14?
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
 
Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++
 
Smart pointers
Smart pointersSmart pointers
Smart pointers
 
Memory Management In C++
Memory Management In C++Memory Management In C++
Memory Management In C++
 
Templates presentation
Templates presentationTemplates presentation
Templates presentation
 
Oop2011 actor presentation_stal
Oop2011 actor presentation_stalOop2011 actor presentation_stal
Oop2011 actor presentation_stal
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handling
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
 
Memory management in C++
Memory management in C++Memory management in C++
Memory management in C++
 
C++11
C++11C++11
C++11
 
Data types in c++
Data types in c++ Data types in c++
Data types in c++
 

Destaque

Effective stl notes
Effective stl notesEffective stl notes
Effective stl notesUttam Gandhi
 
Effective c++notes
Effective c++notesEffective c++notes
Effective c++notesUttam Gandhi
 
Gérer son environnement de développement avec Docker
Gérer son environnement de développement avec DockerGérer son environnement de développement avec Docker
Gérer son environnement de développement avec DockerJulien Dubois
 
Статический и динамический полиморфизм в C++, Дмитрий Леванов
Статический и динамический полиморфизм в C++, Дмитрий ЛевановСтатический и динамический полиморфизм в C++, Дмитрий Леванов
Статический и динамический полиморфизм в C++, Дмитрий ЛевановYandex
 
High Order Function Computations in c++14 (C++ Dev Meetup Iasi)
High Order Function Computations in c++14 (C++ Dev Meetup Iasi)High Order Function Computations in c++14 (C++ Dev Meetup Iasi)
High Order Function Computations in c++14 (C++ Dev Meetup Iasi)Ovidiu Farauanu
 
Dependency Injection in C++ (Community Days 2015)
Dependency Injection in C++ (Community Days 2015)Dependency Injection in C++ (Community Days 2015)
Dependency Injection in C++ (Community Days 2015)Daniele Pallastrelli
 
С++ without new and delete
С++ without new and deleteС++ without new and delete
С++ without new and deletePlatonov Sergey
 
Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Sameer Rathoud
 
Михаил Матросов, “С++ без new и delete”
Михаил Матросов, “С++ без new и delete”Михаил Матросов, “С++ без new и delete”
Михаил Матросов, “С++ без new и delete”Platonov Sergey
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingDustin Chase
 
C++ Dependency Management 2.0
C++ Dependency Management 2.0C++ Dependency Management 2.0
C++ Dependency Management 2.0Patrick Charrier
 
Multithreading 101
Multithreading 101Multithreading 101
Multithreading 101Tim Penhey
 
C++11 smart pointers
C++11 smart pointersC++11 smart pointers
C++11 smart pointerschchwy Chang
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingKamal Acharya
 
Introduction to Bitcoin and ECDSA
Introduction to Bitcoin and ECDSAIntroduction to Bitcoin and ECDSA
Introduction to Bitcoin and ECDSANikesh Mistry
 
Multithreading done right
Multithreading done rightMultithreading done right
Multithreading done rightPlatonov Sergey
 

Destaque (20)

Effective stl notes
Effective stl notesEffective stl notes
Effective stl notes
 
Effective c++notes
Effective c++notesEffective c++notes
Effective c++notes
 
Gérer son environnement de développement avec Docker
Gérer son environnement de développement avec DockerGérer son environnement de développement avec Docker
Gérer son environnement de développement avec Docker
 
Smart Pointers
Smart PointersSmart Pointers
Smart Pointers
 
Статический и динамический полиморфизм в C++, Дмитрий Леванов
Статический и динамический полиморфизм в C++, Дмитрий ЛевановСтатический и динамический полиморфизм в C++, Дмитрий Леванов
Статический и динамический полиморфизм в C++, Дмитрий Леванов
 
High Order Function Computations in c++14 (C++ Dev Meetup Iasi)
High Order Function Computations in c++14 (C++ Dev Meetup Iasi)High Order Function Computations in c++14 (C++ Dev Meetup Iasi)
High Order Function Computations in c++14 (C++ Dev Meetup Iasi)
 
Dependency Injection in C++ (Community Days 2015)
Dependency Injection in C++ (Community Days 2015)Dependency Injection in C++ (Community Days 2015)
Dependency Injection in C++ (Community Days 2015)
 
С++ without new and delete
С++ without new and deleteС++ without new and delete
С++ without new and delete
 
Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())
 
Михаил Матросов, “С++ без new и delete”
Михаил Матросов, “С++ без new и delete”Михаил Матросов, “С++ без new и delete”
Михаил Матросов, “С++ без new и delete”
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
STL Algorithms In Action
STL Algorithms In ActionSTL Algorithms In Action
STL Algorithms In Action
 
C++ Dependency Management 2.0
C++ Dependency Management 2.0C++ Dependency Management 2.0
C++ Dependency Management 2.0
 
Multithreading 101
Multithreading 101Multithreading 101
Multithreading 101
 
File Pointers
File PointersFile Pointers
File Pointers
 
C++11 smart pointers
C++11 smart pointersC++11 smart pointers
C++11 smart pointers
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Introduction to Bitcoin and ECDSA
Introduction to Bitcoin and ECDSAIntroduction to Bitcoin and ECDSA
Introduction to Bitcoin and ECDSA
 
Multithreading done right
Multithreading done rightMultithreading done right
Multithreading done right
 
C++11
C++11C++11
C++11
 

Semelhante a Modern C++

Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)Ravi Okade
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Pythondn
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonRalf Gommers
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinaloscon2007
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinaloscon2007
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency ConstructsTed Leung
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptxVijalJain3
 
Introduction to c_plus_plus
Introduction to c_plus_plusIntroduction to c_plus_plus
Introduction to c_plus_plusSayed Ahmed
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011YoungSu Son
 
Beyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureBeyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureJayaram Sankaranarayanan
 
NOSQL and Cassandra
NOSQL and CassandraNOSQL and Cassandra
NOSQL and Cassandrarantav
 
DotNet Introduction
DotNet IntroductionDotNet Introduction
DotNet IntroductionWei Sun
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming LanguageYLTO
 
the productive programer: mechanics
the productive programer: mechanicsthe productive programer: mechanics
the productive programer: mechanicselliando dias
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Ovidiu Farauanu
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overviewstasimus
 

Semelhante a Modern C++ (20)

Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for Python
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinal
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinal
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
 
Unit 1
Unit  1Unit  1
Unit 1
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
Introduction to c_plus_plus
Introduction to c_plus_plusIntroduction to c_plus_plus
Introduction to c_plus_plus
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
Beyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureBeyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software Architecture
 
NOSQL and Cassandra
NOSQL and CassandraNOSQL and Cassandra
NOSQL and Cassandra
 
DotNet Introduction
DotNet IntroductionDotNet Introduction
DotNet Introduction
 
Rust presentation convergeconf
Rust presentation convergeconfRust presentation convergeconf
Rust presentation convergeconf
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Code Metrics
Code MetricsCode Metrics
Code Metrics
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
 
the productive programer: mechanics
the productive programer: mechanicsthe productive programer: mechanics
the productive programer: mechanics
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overview
 

Mais de Richard Thomson

Vintage Computing Festival Midwest 18 2023-09-09 What's In A Terminal.pdf
Vintage Computing Festival Midwest 18 2023-09-09 What's In A Terminal.pdfVintage Computing Festival Midwest 18 2023-09-09 What's In A Terminal.pdf
Vintage Computing Festival Midwest 18 2023-09-09 What's In A Terminal.pdfRichard Thomson
 
Automated Testing with CMake, CTest and CDash
Automated Testing with CMake, CTest and CDashAutomated Testing with CMake, CTest and CDash
Automated Testing with CMake, CTest and CDashRichard Thomson
 
Feature and platform testing with CMake
Feature and platform testing with CMakeFeature and platform testing with CMake
Feature and platform testing with CMakeRichard Thomson
 
Consuming Libraries with CMake
Consuming Libraries with CMakeConsuming Libraries with CMake
Consuming Libraries with CMakeRichard Thomson
 
SIMD Processing Using Compiler Intrinsics
SIMD Processing Using Compiler IntrinsicsSIMD Processing Using Compiler Intrinsics
SIMD Processing Using Compiler IntrinsicsRichard Thomson
 
Cross Platform Mobile Development with Visual Studio 2015 and C++
Cross Platform Mobile Development with Visual Studio 2015 and C++Cross Platform Mobile Development with Visual Studio 2015 and C++
Cross Platform Mobile Development with Visual Studio 2015 and C++Richard Thomson
 

Mais de Richard Thomson (8)

Vintage Computing Festival Midwest 18 2023-09-09 What's In A Terminal.pdf
Vintage Computing Festival Midwest 18 2023-09-09 What's In A Terminal.pdfVintage Computing Festival Midwest 18 2023-09-09 What's In A Terminal.pdf
Vintage Computing Festival Midwest 18 2023-09-09 What's In A Terminal.pdf
 
Automated Testing with CMake, CTest and CDash
Automated Testing with CMake, CTest and CDashAutomated Testing with CMake, CTest and CDash
Automated Testing with CMake, CTest and CDash
 
Feature and platform testing with CMake
Feature and platform testing with CMakeFeature and platform testing with CMake
Feature and platform testing with CMake
 
Consuming Libraries with CMake
Consuming Libraries with CMakeConsuming Libraries with CMake
Consuming Libraries with CMake
 
BEFLIX
BEFLIXBEFLIX
BEFLIX
 
SIMD Processing Using Compiler Intrinsics
SIMD Processing Using Compiler IntrinsicsSIMD Processing Using Compiler Intrinsics
SIMD Processing Using Compiler Intrinsics
 
Cross Platform Mobile Development with Visual Studio 2015 and C++
Cross Platform Mobile Development with Visual Studio 2015 and C++Cross Platform Mobile Development with Visual Studio 2015 and C++
Cross Platform Mobile Development with Visual Studio 2015 and C++
 
Web mashups with NodeJS
Web mashups with NodeJSWeb mashups with NodeJS
Web mashups with NodeJS
 

Último

Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 

Último (20)

Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 

Modern C++

  • 1. Richard Thomson Principal Architect for Modeling, Daz 3D legalize@xmission.com @LegalizeAdulthd LegalizeAdulthood.wordpress.com
  • 2. Thanks to our Sponsors! Community Sponsor Yearly Sponsor Marquee Sponsor
  • 3. About Me...  Meetup organizer:  Utah C++ Programmers (2nd Wednesday)  Salt Lake City Software Craftsmanship (1st Thursday)  3D Modelers (3rd Tuesday)  C++ language track on exercism.io  Polyglot developer  Currently: C++, JavaScript/NodeJS  Previously: C#, JavaScript/NodeJS, Python, Java  Distantly: C, Perl, FORTRAN, LISP, FORTH, Assembly, TECO  Different languages have their strengths  Leverage strengths where appropriate
  • 4. Why Use C++?  Type safety  Encapsulate necessary unsafe operations  Resource safety  Not all resource management is managing memory  Performance  For some parts of almost all systems, it's important  Predictability  For hard or soft real-time systems
  • 5. Why Use C++?  Teachability  Complexity of code should be proportional to complexity of the task  Readability  For people and machines ("analyzability")  Direct map to hardware  For instructions and fundamental data types  Zero-overhead abstraction  Classes with constructors and destructors, inheritance, generic programming, functional programming techniques
  • 6. ISO Standard for C++  C++98 1998: First ISO standard  C++03 2003: "Bug fix" to C++98 standard  C++11 2011: Major enhancement to language and library  C++14 2014: Bug fixes and improvements to C++11  C++17 2017? Library additions and bug fixes
  • 7. What is "Modern" C++?  Embrace the improvements brought by C++11/14  Eschew old coding practices based on earlier standards  Avoid like the plague C-style coding practices!
  • 8. Print Sorted Words from Input #include <algorithm> // sort #include <iostream> // cin, cout #include <string> #include <vector> using namespace std; int main() { vector<string> words; string input; while (cin >> input) { words.push_back(input); } sort(begin(words), end(words)); for (auto w : words) { cout << w << 'n'; } return 0; } one barney zoo betty fred alpha ^Z alpha barney betty fred one zoo
  • 9. Some Observations  This code accepts input words bounded only by available memory.  string is a general-purpose dynamically sized string class provided by the standard library.  vector is a standard container for any copyable type, in this case string.  sort is a standard library algorithm that operates polymorphically on sequences of values, in this case strings.  begin and end are standard library functions for iterating over containers, including "raw" arrays.
  • 10. Print Words Custom Sorted #include <algorithm> // sort #include <iostream> // cin, cout #include <string> #include <vector> using namespace std; int main() { vector<string> words; string input; while (cin >> input) { words.push_back(input); } sort(begin(words), end(words), [](auto lhs, auto rhs) { return lhs[1] < rhs[1]; }); for (auto w : words) { cout << w << 'n'; } return 0; } zar betty one alpha ^Z zar betty alpha one
  • 11. More Observations  Standard library algorithms are extensible through functors (instances of function class objects).  Lambda functions provide succinct syntax for writing such functors.  Range-based for loop allows for easy enumeration of all values in a collection.  auto allows us to let the compiler figure out the types.  C++ standard library algorithms are often more efficient than their C library counterparts, particularly when customized with application functors.
  • 12. Beyond the Language: IDEs and Tools  IDEs and tools have also advanced.  Static analysis tools:  Finds common problems in C++ code bases.  Some tools suggest automated fixes for problems.  Refactoring tools:  Visual Studio 2015  Clion  ReSharper for C++  clang-tidy
  • 13. Goals of C++11/14  Maintain stability and compatibility with prior versions.  Prefer introducing new features via the standard library instead of the core language.  Prefer changes that can evolve programming technique.  Improve C++ to facilitate systems and library design.  Improve type safety by providing safer alternatives to earlier unsafe techniques.  Increase performance and the ability to work directly with the hardware.  Provide proper solutions to real-world problems.  Implement the zero-overhead principle, aka "don't pay for what you don't use".  Make C++ easier to teach and learn.
  • 14. Performance Additions  "Move semantics" improve performance of transfer of ownership of data.  constexpr generalized constant expressions.
  • 15. Usability Enhancements  Uniform initializer syntax.  Type inference (auto).  Range-based for loop.  Lambda functions and expressions.  Alternate function syntax (trailing return type).  Constructor delegation.  Field initializers.  Explicit override and final.  Null pointer constant (nullptr, nullptr_t).  Strongly-typed enumerations.  Right angle bracket.  Template aliases.  Unrestricted unions.
  • 16. Functionality Enhancements  Variadic templates  Variadic macros  New string literals for Unicode  User-defined literals  Multithreading memory model  Thread-local storage  Explicitly defaulting or deleting special member functions  Type long long int  Static assertions  Generalized sizeof  Control of object alignment  Allow garbage collected implementations  Attributes
  • 17. Standard Library Enhancements  Upgrades to standard library components.  Threading facilities.  Tuples.  Hash tables.  Regular expressions.  General-purpose smart pointers.  Extensible random number facility.  Reference wrapper.  Polymorphic wrappers for function objects.  Type traits for metaprogramming.  Uniform method for computing the return type of function objects.
  • 18. Modern C++ Idioms  "Almost always auto"  "No naked new/delete"  "No raw loops"  "No raw owning pointers"  "Uniform initialization"  Embrace Zero-overhead Abstraction
  • 19. Uniform Initialization  Motivation:  Simplify initialization by using a uniform syntax for initializing values of all types.  int f{3};  string s{"hello, world!"};  Foo g{"constructor", "arguments"};  vector<string> words{"hi", "there"};
  • 20. Almost Always Auto  Motivation:  Let the compiler figure out types as much as is feasible.  auto x = 42;  auto x{42};  Subjective. Some people prefer it; removes the clutter of types from the code. Others feel that it can obscure the actual types being used. No supermajority consensus yet on this idiom.
  • 21. No Naked new/delete  Motivation:  New and delete are low-level heap operations corresponding to resource allocation. Their low-level nature can be a source of errors. Therefore, use an encapsulating class that implements the desired ownership policy.  unique_ptr<Foo> f{make_unique<Foo>(x, y)};  shared_ptr<Foo> g{make_shared<Foo>(x, y)};  weak_ptr<Foo> h{g};
  • 22. No Raw Owning Pointers  Motivation:  Use a smart pointer class to enforce ownership policies. Raw pointers and references are still useful for efficiency, but they no longer represent ownership.  auto pw = make_shared<widget>();
  • 23. No Raw Loops  Motivation:  The standard library algorithms cover most of what you need to do. With lambdas for customization, using them is easy. Write your own algorithms in the style of the standard library when necessary.  Sean Parent, "C++ Seasoning" Going Native 2013  https://channel9.msdn.com/Events/GoingNative/2013 /Cpp-Seasoning
  • 24. Embrace Zero-Overhead Abstraction  Motivation:  There is no runtime penalty for abstraction, so embrace it fully.  Create small, focused types to express specific semantics on top of general types.  Examples: Points, (geometric) Vectors, Matrices for 3D graphics. Small concrete value types can be as efficient as inline computation.
  • 25. Practice Modern C++  http://ideone.com  Web-based modern C++ development environment  Quick to experiment, no install, save work for later.  Visual Studio 2015 Community Edition  Full-featured IDE with refactoring support.  Good for full sized projects.  http://exercism.io  Practice modern C++ on a variety of problems and get peer review and discussion of your solution.