SlideShare a Scribd company logo
1 of 28
Download to read offline
A brief overview of C++17
Daniel Eriksson
Table of contents
● The standardization process, the committee
● C++ Standards
● The current status of the standardization process
● New language features
● New features in the standard libraries
● References
The standardization process
● A Commitee under ISO/IEC so multiple companies can co-operate and define
the language
● Work Group 21 (Google for wg21)
● Info on isocpp.org
○ Community site for publicizing for publicizing activity
● Work with Technical Specifications, TS:s
C++ Standards
● 1998
● 2003 TC1
● 2011
● 2014
● 2017
The Current Status
● Builds on C++14
● Significant library update
○ The additions and changes to the libraries are the biggest part of the new standard.
● Modest language update
● The standard has been agreed upon
● Will now be reviewed by ISO
● Expected release by the end of 2017
New language features
Attributes
● [[fallthrough]] a case without breaking
● [[nodiscard]] warns on ignored function results
● [[maybe_unused]]
● Grammar supports attributes on namespaces
○ namespace std::relops [[deprecated]] { …. }
● Grammars supports attributes on enumeratiors
○ enum MyEnum {old_name [[deprecated]], new_name ]
New Language Features
Examples
● [[maybe_unsued]] int f() {} // Won’t issue warning if return value is not
catched.
● [[nodiscard]] int f() {} // Will issue warning if return value is not catched.
● Alos deducted from type:
○ struct [[nodiscard]] MyStruct {};
○ MyStruct f() {}; // Will give compiler warning if return value is not handled.
New Language Features
Lamda Expressions
● constexpr lamda expressions
● It is now possible to caputre a copy of this, e.g *this
New Language Features
Structured Bindings
● Declare multiple variables, bound by function result
○ auto [x, y] = *map.find(key) // Returns a pair
● Functions can return
○ An aggregate
○ an arry-by-reference
○ something that supports the tuple protocol: array, pair or tuple
● Works anywhere an initialization may be performed
for (auto& [first, second] : myMap) {
// use firts and secon
}
New Features In The Standard Libraries
● Multicore support and Parallelism 1
● Math functions
● Extended vocabulary
● Text Handling
● Filesystem
● Smart Pointers
Parallelism
Distinction between parallelism and concurrency
● Parallelism
○ Simultaneously executing many copies of the same task to speed a single computation
● Concurrency
○ Performing multiple actions at the same time, often to improve latency
Parallelism
● Added execution_policy overload to most functions in the <algorithm> and <numeric>
headers
● Almost all of the algorithms in the standard library now how a “paralliezed” version
● Excpet
○ Random nubers
○ Heap opertaions (other than is_hep and is_heap_until)
○ permutations operations
○ copy_backwards, move_backward, lowe_bound, upper_bound, equal_range,
binary_search, accumulate, partial_sum, iota
● Added some new
○ exclusive_scan
○ inclusive_scan
○ transform_reduce
○ redue
Parallellism
Execution policies
● std::execution::seq
● std::execution::par
● std::execution::par_unseq
Math functions
● Adopted all of ISO 29124 (extensions to C++)
○ > 20 mathematical special functions
○ Bessel functions, beta function, riemann zeta etc
● hypot(x, y, z)
● gcd(a, b)
● lcm(a, b)
● A sampling function
○ sample(begin, end, out_iter, nSamples, rgb)
pair and tuple
● Unpack tuple arguments into a function call
○ apply(func, tuple{1, “two”, 3.14});
● Construct and object by unpacking a tuple
○ auto x = tuple{1, “two”, 3.14}
○ auto y = make_from_tuple<MyTYpe>(x);
Extended vocabulary
● Vocabulary types are the kind of types you would like to use in your interfaces
● Good with standardized vocabulary between libraries (for example)
● Already present
○ pair, tuple, array already in
● New ones
○ optinal<T>
○ any
○ variant<Types…>
○ string_view
optional<T>
#include <variant>
#include <string>
#include <string>
#include <iostream>
#include <optional>
// optional can be used as the return type of a factory that may fail
std::optional<std::string> create(bool b) {
if(b)
return "Godzilla";
else
return {};
}
int main()
{
std::cout << "create(false) returned "
<< create(false).value_or("empty") << 'n';
// optional-returning factory functions are usable as conditions of while and if
if(auto str = create(true)) {
std::cout << "create(true) returned " << *str << 'n';
}
}
variant<TYPES…>
#include <variant>
#include <string>
int main()
{
std::variant<int, float> v, w;
v = 12; // v contains int
int i = std::get<int>(v);
w = std::get<int>(v);
w = std::get<0>(v); // same effect as the previous line
w = v; // same effect as the previous line
// std::get<double>(v); // error: no double in [int, float]
// std::get<3>(v); // error: valid index values are 0 and 1
try {
std::get<float>(w); // w contains int, not float: will throw
}
catch (std::bad_variant_access&) {}
std::variant<std::string> v("abc"); // converting constructors work when unambiguous
v = "def"; // converting assignment also works when unambiguous
}
any
● Can hold any value as long as it is copy constructible
● Like varian except that it does not know what type it holds
● Will have to use any_cast to retrieve the value
any
int main()
{
boost::any a = 1;
std::cout << std::any_cast<int>(a) << 'n';
a = 3.14;
std::cout << std::any_cast<double>(a) << 'n';
a = true;
std::cout << std::boolalpha << std::any_cast<bool>(a) << 'n';
}
string_view
● string_view gives the ability to refer to an existing string in a non-owning way.
bool compare(const std::string& s1, const std::string& s2)
{
// do some comparisons between s1 and s2
}
int main()
{
std::string str = "this is my input string";
bool r1 = compare(str, "this is the first test string");
bool r2 = compare(str, "this is the second test string");
bool r3 = compare(str, "this is the third test string");
}
string_view
bool compare(std::string_view s1, std::string_view s2)
{
if (s1 == s2)
return true;
std::cout << '"' << s1 << "" does not match "" << s2 << ""n";
return false;
}
int main()
{
std::string str = "this is my input string";
compare(str, "this is the first test string");
compare(str, "this is the second test string");
compare(str, "this is the third test string");
return 0;
}
string_view
● In the last example only str is allocated.
● It is also possible to create string_view from a substring of a string.
○ The string_view points into the original string rather than to allocate a new string
○ string_view holds a pointer to a string and a size
Filesystem
● std::filesystem
● Specification based on POSIX standard semantics
○ NO protection against file system data races
● Uses system_error reporting introduced in C++11
● Functions and iterators to navigate a filesystem
● Functions to create, manipulate and query files (including directories and
symlinks)
Further Changes And Additions
● Smart pointers
● Allocators
● Memory Resources
Library Features Removed
● auto_ptr => Use unique_ptr
● bind1st, bind2nd, men_fun, men_fun_ref, ptr_fun, unary_function,
binary_funciton
● random_shuffle
References
● Alisdair Meredith
○ C++17 in Breadth Part 1
○ C++17 in Breadth Part 2
● isocpp.org
● cppreference.com

More Related Content

What's hot

An Overview Of Standard C++Tr1
An Overview Of Standard C++Tr1An Overview Of Standard C++Tr1
An Overview Of Standard C++Tr1
Ganesh Samarthyam
 

What's hot (20)

DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()
 
Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminary
 
Java 7
Java 7Java 7
Java 7
 
Basic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersBasic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmers
 
C++11 Idioms @ Silicon Valley Code Camp 2012
C++11 Idioms @ Silicon Valley Code Camp 2012 C++11 Idioms @ Silicon Valley Code Camp 2012
C++11 Idioms @ Silicon Valley Code Camp 2012
 
Introduction to JQ
Introduction to JQIntroduction to JQ
Introduction to JQ
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)
 
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury SechetDConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
 
Алексей Кутумов, Вектор с нуля
Алексей Кутумов, Вектор с нуляАлексей Кутумов, Вектор с нуля
Алексей Кутумов, Вектор с нуля
 
Parsers Combinators in Scala, Ilya @lambdamix Kliuchnikov
Parsers Combinators in Scala, Ilya @lambdamix KliuchnikovParsers Combinators in Scala, Ilya @lambdamix Kliuchnikov
Parsers Combinators in Scala, Ilya @lambdamix Kliuchnikov
 
C++17 std::filesystem - Overview
C++17 std::filesystem - OverviewC++17 std::filesystem - Overview
C++17 std::filesystem - Overview
 
Towards hasktorch 1.0
Towards hasktorch 1.0Towards hasktorch 1.0
Towards hasktorch 1.0
 
Vocabulary Types in C++17
Vocabulary Types in C++17Vocabulary Types in C++17
Vocabulary Types in C++17
 
jq: JSON - Like a Boss
jq: JSON - Like a Bossjq: JSON - Like a Boss
jq: JSON - Like a Boss
 
An Overview Of Standard C++Tr1
An Overview Of Standard C++Tr1An Overview Of Standard C++Tr1
An Overview Of Standard C++Tr1
 
Systematic Generation Data and Types in C++
Systematic Generation Data and Types in C++Systematic Generation Data and Types in C++
Systematic Generation Data and Types in C++
 
Let's talks about string operations in C++17
Let's talks about string operations in C++17Let's talks about string operations in C++17
Let's talks about string operations in C++17
 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)
 

Similar to Meetup C++ A brief overview of c++17

JavaScript: Patterns, Part 2
JavaScript: Patterns, Part  2JavaScript: Patterns, Part  2
JavaScript: Patterns, Part 2
Chris Farrell
 
李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义
yiditushe
 
Internal Anatomy of an Update
Internal Anatomy of an UpdateInternal Anatomy of an Update
Internal Anatomy of an Update
MongoDB
 
Fantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and JavascriptFantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and Javascript
Kamil Toman
 

Similar to Meetup C++ A brief overview of c++17 (20)

TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVA
 
Dart workshop
Dart workshopDart workshop
Dart workshop
 
Custom Pregel Algorithms in ArangoDB
Custom Pregel Algorithms in ArangoDBCustom Pregel Algorithms in ArangoDB
Custom Pregel Algorithms in ArangoDB
 
JavaScript: Patterns, Part 2
JavaScript: Patterns, Part  2JavaScript: Patterns, Part  2
JavaScript: Patterns, Part 2
 
李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义
 
What's New in C++ 11?
What's New in C++ 11?What's New in C++ 11?
What's New in C++ 11?
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional Programming
 
Java 8
Java 8Java 8
Java 8
 
Golang dot-testing-lite
Golang dot-testing-liteGolang dot-testing-lite
Golang dot-testing-lite
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
Internal Anatomy of an Update
Internal Anatomy of an UpdateInternal Anatomy of an Update
Internal Anatomy of an Update
 
Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++
 
The Ring programming language version 1.7 book - Part 17 of 196
The Ring programming language version 1.7 book - Part 17 of 196The Ring programming language version 1.7 book - Part 17 of 196
The Ring programming language version 1.7 book - Part 17 of 196
 
(3) cpp procedural programming
(3) cpp procedural programming(3) cpp procedural programming
(3) cpp procedural programming
 
Should i Go there
Should i Go thereShould i Go there
Should i Go there
 
Fantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and JavascriptFantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and Javascript
 
C
CC
C
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
 
The Ring programming language version 1.6 book - Part 16 of 189
The Ring programming language version 1.6 book - Part 16 of 189The Ring programming language version 1.6 book - Part 16 of 189
The Ring programming language version 1.6 book - Part 16 of 189
 

Recently uploaded

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+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
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
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 Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
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-...
 
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...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
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 Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%+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...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%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
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 

Meetup C++ A brief overview of c++17

  • 1. A brief overview of C++17 Daniel Eriksson
  • 2. Table of contents ● The standardization process, the committee ● C++ Standards ● The current status of the standardization process ● New language features ● New features in the standard libraries ● References
  • 3. The standardization process ● A Commitee under ISO/IEC so multiple companies can co-operate and define the language ● Work Group 21 (Google for wg21) ● Info on isocpp.org ○ Community site for publicizing for publicizing activity ● Work with Technical Specifications, TS:s
  • 4. C++ Standards ● 1998 ● 2003 TC1 ● 2011 ● 2014 ● 2017
  • 5. The Current Status ● Builds on C++14 ● Significant library update ○ The additions and changes to the libraries are the biggest part of the new standard. ● Modest language update ● The standard has been agreed upon ● Will now be reviewed by ISO ● Expected release by the end of 2017
  • 6.
  • 7. New language features Attributes ● [[fallthrough]] a case without breaking ● [[nodiscard]] warns on ignored function results ● [[maybe_unused]] ● Grammar supports attributes on namespaces ○ namespace std::relops [[deprecated]] { …. } ● Grammars supports attributes on enumeratiors ○ enum MyEnum {old_name [[deprecated]], new_name ]
  • 8. New Language Features Examples ● [[maybe_unsued]] int f() {} // Won’t issue warning if return value is not catched. ● [[nodiscard]] int f() {} // Will issue warning if return value is not catched. ● Alos deducted from type: ○ struct [[nodiscard]] MyStruct {}; ○ MyStruct f() {}; // Will give compiler warning if return value is not handled.
  • 9. New Language Features Lamda Expressions ● constexpr lamda expressions ● It is now possible to caputre a copy of this, e.g *this
  • 10. New Language Features Structured Bindings ● Declare multiple variables, bound by function result ○ auto [x, y] = *map.find(key) // Returns a pair ● Functions can return ○ An aggregate ○ an arry-by-reference ○ something that supports the tuple protocol: array, pair or tuple ● Works anywhere an initialization may be performed for (auto& [first, second] : myMap) { // use firts and secon }
  • 11. New Features In The Standard Libraries ● Multicore support and Parallelism 1 ● Math functions ● Extended vocabulary ● Text Handling ● Filesystem ● Smart Pointers
  • 12. Parallelism Distinction between parallelism and concurrency ● Parallelism ○ Simultaneously executing many copies of the same task to speed a single computation ● Concurrency ○ Performing multiple actions at the same time, often to improve latency
  • 13. Parallelism ● Added execution_policy overload to most functions in the <algorithm> and <numeric> headers ● Almost all of the algorithms in the standard library now how a “paralliezed” version ● Excpet ○ Random nubers ○ Heap opertaions (other than is_hep and is_heap_until) ○ permutations operations ○ copy_backwards, move_backward, lowe_bound, upper_bound, equal_range, binary_search, accumulate, partial_sum, iota ● Added some new ○ exclusive_scan ○ inclusive_scan ○ transform_reduce ○ redue
  • 14. Parallellism Execution policies ● std::execution::seq ● std::execution::par ● std::execution::par_unseq
  • 15. Math functions ● Adopted all of ISO 29124 (extensions to C++) ○ > 20 mathematical special functions ○ Bessel functions, beta function, riemann zeta etc ● hypot(x, y, z) ● gcd(a, b) ● lcm(a, b) ● A sampling function ○ sample(begin, end, out_iter, nSamples, rgb)
  • 16. pair and tuple ● Unpack tuple arguments into a function call ○ apply(func, tuple{1, “two”, 3.14}); ● Construct and object by unpacking a tuple ○ auto x = tuple{1, “two”, 3.14} ○ auto y = make_from_tuple<MyTYpe>(x);
  • 17. Extended vocabulary ● Vocabulary types are the kind of types you would like to use in your interfaces ● Good with standardized vocabulary between libraries (for example) ● Already present ○ pair, tuple, array already in ● New ones ○ optinal<T> ○ any ○ variant<Types…> ○ string_view
  • 18. optional<T> #include <variant> #include <string> #include <string> #include <iostream> #include <optional> // optional can be used as the return type of a factory that may fail std::optional<std::string> create(bool b) { if(b) return "Godzilla"; else return {}; } int main() { std::cout << "create(false) returned " << create(false).value_or("empty") << 'n'; // optional-returning factory functions are usable as conditions of while and if if(auto str = create(true)) { std::cout << "create(true) returned " << *str << 'n'; } }
  • 19. variant<TYPES…> #include <variant> #include <string> int main() { std::variant<int, float> v, w; v = 12; // v contains int int i = std::get<int>(v); w = std::get<int>(v); w = std::get<0>(v); // same effect as the previous line w = v; // same effect as the previous line // std::get<double>(v); // error: no double in [int, float] // std::get<3>(v); // error: valid index values are 0 and 1 try { std::get<float>(w); // w contains int, not float: will throw } catch (std::bad_variant_access&) {} std::variant<std::string> v("abc"); // converting constructors work when unambiguous v = "def"; // converting assignment also works when unambiguous }
  • 20. any ● Can hold any value as long as it is copy constructible ● Like varian except that it does not know what type it holds ● Will have to use any_cast to retrieve the value
  • 21. any int main() { boost::any a = 1; std::cout << std::any_cast<int>(a) << 'n'; a = 3.14; std::cout << std::any_cast<double>(a) << 'n'; a = true; std::cout << std::boolalpha << std::any_cast<bool>(a) << 'n'; }
  • 22. string_view ● string_view gives the ability to refer to an existing string in a non-owning way. bool compare(const std::string& s1, const std::string& s2) { // do some comparisons between s1 and s2 } int main() { std::string str = "this is my input string"; bool r1 = compare(str, "this is the first test string"); bool r2 = compare(str, "this is the second test string"); bool r3 = compare(str, "this is the third test string"); }
  • 23. string_view bool compare(std::string_view s1, std::string_view s2) { if (s1 == s2) return true; std::cout << '"' << s1 << "" does not match "" << s2 << ""n"; return false; } int main() { std::string str = "this is my input string"; compare(str, "this is the first test string"); compare(str, "this is the second test string"); compare(str, "this is the third test string"); return 0; }
  • 24. string_view ● In the last example only str is allocated. ● It is also possible to create string_view from a substring of a string. ○ The string_view points into the original string rather than to allocate a new string ○ string_view holds a pointer to a string and a size
  • 25. Filesystem ● std::filesystem ● Specification based on POSIX standard semantics ○ NO protection against file system data races ● Uses system_error reporting introduced in C++11 ● Functions and iterators to navigate a filesystem ● Functions to create, manipulate and query files (including directories and symlinks)
  • 26. Further Changes And Additions ● Smart pointers ● Allocators ● Memory Resources
  • 27. Library Features Removed ● auto_ptr => Use unique_ptr ● bind1st, bind2nd, men_fun, men_fun_ref, ptr_fun, unary_function, binary_funciton ● random_shuffle
  • 28. References ● Alisdair Meredith ○ C++17 in Breadth Part 1 ○ C++17 in Breadth Part 2 ● isocpp.org ● cppreference.com