SlideShare une entreprise Scribd logo
1  sur  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.

Contenu connexe

Tendances (20)

OOP in C++
OOP in C++OOP in C++
OOP in C++
 
Effective modern c++ 5
Effective modern c++ 5Effective modern c++ 5
Effective modern c++ 5
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
 
C++
C++C++
C++
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
C++ programming
C++ programmingC++ programming
C++ programming
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Operator overloading C++
Operator overloading C++Operator overloading C++
Operator overloading C++
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by Example
 
Friend function
Friend functionFriend function
Friend function
 
pre processor directives in C
pre processor directives in Cpre processor directives in C
pre processor directives in C
 
C basics
C   basicsC   basics
C basics
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
 
Friend functions
Friend functions Friend functions
Friend functions
 
C# in depth
C# in depthC# in depth
C# in depth
 

En vedette

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
 
Михаил Матросов, “С++ без 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
 

En vedette (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
 
Михаил Матросов, “С++ без 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
 
Memory Management In C++
Memory Management In C++Memory Management In C++
Memory Management In C++
 
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
 

Similaire à 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
 
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
 
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
 

Similaire à 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
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)
 
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)
 

Plus 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
 
Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++Richard Thomson
 

Plus de Richard Thomson (9)

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++
 
Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++
 
Web mashups with NodeJS
Web mashups with NodeJSWeb mashups with NodeJS
Web mashups with NodeJS
 

Dernier

Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 

Dernier (20)

Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
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-...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

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.