SlideShare a Scribd company logo
1 of 33
Summary of C++17
features
Is this release good, great, amazing or meh?
Bartłomiej Filipek
http://www.bfilipek.com/
Blog version, annotated
Last update: 25th Nov 2017
About me
www.bfilipek.com
10y+ experience
Currently @Xara.com
Text related features
Somehow addicted to Cpp :D
The plan
C++17 timeline
What we get
Fixes and deprecation
Language clarification
Templates
Attributes
Simplification
Filesystem
Parallel STL
Utils
Summary
Timeline
The new standard for C++17 was approved at the beginning of September. But what was the journey to that point? How it all
started?
https://isocpp.org/std/status
Here’s the up-to-date version of the timeline for the C++ standard. Around 13 years we need to wait for C++11 (since 98), but then the work
speeded up! It’s clear from that picture how much work is going on. There’s the current trunk, plus several major branches with larger features
(TS). At some point those branches are merged into the trunk. The committee meets several times per year and votes on the proposals.
https://isocpp.org/std/the-committee
Here’s the overview of all the groups that work on new features.
Each larger feature has it’s own group!
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4700.pdf
https://github.com/cplusplus/draft
If you have problem with sleep just download the draft for the
standard (for free) and start reading!
Ship every 3 years
As I see here’s the major changed that happened in the
standardization process: C++11 was so late (we expected it to be
before 2010!), but the committee waited until all the features
were ready. Now we focus on the deadline. If a feature is not
ready, then it’s simply moved to the next standard.
Merged: The Library Fundamentals 1 TS (most parts)
Removal of some deprecated types and functions, including std::auto_ptr, std::random_shuffle, and old function adaptors
Merged: The Parallelism TS, a.k.a. “Parallel STL.”,
Merged: File System TS,
Merged: The Mathematical Special Functions IS,
Improving std::pair and std::tuple
std::shared_mutex (untimed)
Variant, Optional, Any
Splicing Maps and Sets
New auto rules for direct-list-initialization
static_assert with no message
typename in a template template parameter
Removing trigraphs
Nested namespace definition
Attributes for namespaces and enumerators
u8 character literals
Allow constant evaluation for all non-type template arguments
Fold Expressions
Unary fold expressions and empty parameter packs
Remove Deprecated Use of the register Keyword
Remove Deprecated operator++(bool)
Removing Deprecated Exception Specifications from C++17
Make exception specifications part of the type system
Aggregate initialization of classes with base classes
Lambda capture of *this
Using attribute namespaces without repetition
Dynamic memory allocation for over-aligned data
__has_include in preprocessor conditionals
Template argument deduction for class templates
Non-type template parameters with auto type
Guaranteed copy elision
New specification for inheriting constructors (DR1941 et al)
Direct-list-initialization of enumerations
Stricter expression evaluation order
constexpr lambda expressions
Different begin and end types in range-based for
[[fallthrough]] attribute
[[nodiscard]] attribute
[[maybe_unused]] attribute
Ignore unknown attributes
Pack expansions in using-declarations
Structured Binding Declarations
Hexadecimal floating-point literals
init-statements for if and switch
Inline variables
DR: Matching of template template-arguments excludes compatible templates
std::uncaught_exceptions()
constexpr if-statements
1. Fixes and deprecation
2. Language clarification
3. Templates
4. Attributes
5. Simplification
6. Filesystem
7. Parallel STL
8. Utils
Deprecation & Removal
Removing trigraphs
Removing register keyword
Remove Deprecated operator++(bool)
Cannot inherit from std::iterator
auto_ptr is gone!
MSVC 2017 using /std:c++latest:
error C2039: 'auto_ptr': is not a member of 'std'
Removing Deprecated Exception
Specifications from C++17
void fooThrowsInt(int a) throw(int)
{
printf_s("can throw intsn");
if (a == 0)
throw 1;
}
Use “noexcept”
Fixes
static_assert with no message
New auto rules for direct-list-initialization
auto x5{ 3 }; // decltype(x5) is int, not initializer_list
Different begin and end types in range-based for
{
auto && __range = for - range - initializer;
for (auto __begin = begin - expr,
__end = end - expr;
__begin != __end;
++__begin)
{
for_range_declaration = *__begin;
statement
}
}
{
auto && __range = for - range - initializer;
auto __begin = begin - expr;
auto __end = end - expr;
for (; __begin != __end; ++__begin)
{
for_range_declaration = *__begin;
statement
}
}
Language clarifications
Guaranteed copy elision
(only for temporary objects, not for Named RVO)
Exception specifications part of the type system
void foo() noexcept;
void foo();
Dynamic memory allocation for over-aligned data
new is now aware of the alignment of the object.
Stricter expression evaluation order
Why do we need make_unique?
foo(make_unique<T>(), otherFunction()); foo(unique_ptr<T>(new T), otherFunction());
Templates
Template argument deduction for class
templates
std::pair<int, double> p(10, 0.0);
// same as
std::pair p(10, 0.0); // deduced automatically!
std::lock_guard<std::shared_timed_mutex,
std::shared_lock<std::shared_timed_mutex>> lck(mut_, r1);
// Can now become :
std::lock_guard lck(mut_, r1);
custom class template deduction guides
Fold expressions
auto SumCpp11()
{
return 0;
}
template<typename T1, typename... T>
auto SumCpp11(T1 s, T... ts)
{
return s + SumCpp11(ts...);
}
template<typename ...Args> auto sum(Args ...args)
{
return (args + ... + 0);
}
template<typename ...Args>
void FoldPrint(Args&&... args)
{
(cout << ... << forward<Args>(args)) << 'n';
}
// SFINAE
template <typename T, std::enable_if_t < std::is_pointer<T>{} > * = nullptr >
auto get_value(T t)
{
return *t;
}
template <typename T, std::enable_if_t < !std::is_pointer<T>{} > * = nullptr >
auto get_value(T t)
{
return t;
} // Tag dispatching
template <typename T>
auto get_value(T t, std::true_type)
{
return *t;
}
template <typename T>
auto get_value(T t, std::false_type)
{
return t;
}
template <typename T>
auto get_value(T t)
{
return get_value(t, std::is_pointer<T>{});
}https://blog.tartanllama.xyz/if-constexpr/
template <typename T>
auto get_value(T t)
constexpr if
template <typename T>
auto get_value(T t)
{
if constexpr (std::is_pointer_v<T>)
return *t;
else
return t;
}
Attributes
[[fallthrough]]
[[nodiscard]]
[[maybe_unused]]
@cppreference.com
Attributes available in C++17
[[noreturn]]
[[carries_dependency]]
[[deprecated]]
[[deprecated("msg")]]
[[fallthrough]]
[[nodiscard]]
[[maybe_unused]]
enum class[[nodiscard]] ErrorCode{
OK,
Fatal,
System,
FileIssue
};
ErrorCode Compute() { ... }
...
Compute(); // warning!
How will it simplify the code?
Inline variables
Great for header-only libs!
constexpr if
Structured Binding Declarations
// works with arrays:
double myArray[3] = { 1.0, 2.0, 3.0 };
auto[a, b, c] = myArray;
auto[a, b] = myPair; // binds myPair.first/second (must implement get<N>)
// non static, public members
struct S { int x1; double y1; };
S f();
const auto[x, y] = f();
std::map myMap;
for (const auto &[key, val] : myMap)
{
}
Init-statement for if/switch
{
auto val = GetValue();
if (condition(val))
// on success
else
// on false...
}
if (auto val = GetValue(); condition(val))
// on success
else
// on false...
if (const auto it = myString.find("Hello"); it != std::string::npos)
std::cout << it << " Hellon";
if (const auto it = myString.find("World"); it != std::string::npos)
std::cout << it << " Worldn";
Structured bindings & init in if
statements
// better together: structured bindings + if initializer
if (auto[iter, succeeded] = mymap.insert(value); succeeded) {
use(iter); // ok
// ...
} // iter and succeeded are destroyed here
Filesystem
namespace fs = std::experimental::filesystem;
void DisplayDirTree(const fs::path& pathToShow, int level)
{
if (fs::exists(pathToShow) && fs::is_directory(pathToShow))
{
auto lead = std::string(level * 3, ' ');
for (const auto& entry : fs::directory_iterator(pathToShow))
{
auto filename = entry.path().filename();
if (fs::is_directory(entry.status()))
{
cout << lead << "[+] " << filename << "n";
DisplayDirTree(entry, level + 1);
cout << "n";
}
else if (fs::is_regular_file(entry.status()))
DisplayFileInfo(entry, lead, filename);
else
cout << lead << " [?]" << filename << "n";
}
}
}
Parallel STL
std::vector<int> v = genLargeVector();
// standard sequential sort
std::sort(v.begin(), v.end());
// explicitly sequential sort
std::sort(std::seq, v.begin(), v.end());
// permitting parallel execution
std::sort(std::par, v.begin(), v.end());
// permitting vectorization as well
std::sort(std::par_unseq, v.begin(), v.end());
Utils
std::any
std::variant
std::optional
string_view
Searchers
http://www.bfilipek.com/2017/09/cpp17-details-utils.html
auto a = std::any(12);
a = std::string("hello world");
a = 10.0f;
cout << std::any_cast<float>(a);
std::variant<int, float, std::string> abc;
// get<>
// get_if<>
// visit()
std::optional<std::string> ostr = GetUserResponse();
default_searcher
boyer_moore_searcher
boyer_moore_horspool_searcher
Compiler support
GCC 7.0 is feature complete
Clang 5.0
MSVC 2017.4 has most of the features
The separate part is the standard library for each compiler. They might be delayed,
especially regarding parallel versions of the algorithms.
Summary
Is C++17 great? Amazing? Or just meh… ?
I think it’s a very decent version of the standard! Maybe people
would like to see more, but it was not possible due to the
deadline. Without this we would have to wait a year or two to
have all the “desired” features to be accepted.
Bonus – seemyfreePDFwithdescriptionofalloftheC++17 features!
http://www.bfilipek.com/2017/09/c17-in-detail-summary-bonus.html
https://isocpp.org/

More Related Content

What's hot

C#, imparare a programmare e sopravvivere
C#, imparare a programmare e sopravvivereC#, imparare a programmare e sopravvivere
C#, imparare a programmare e sopravvivereMatteo Valoriani
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumlercorehard_by
 
utPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQLutPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQLSteven Feuerstein
 
Introducing new AIOps innovations in Oracle 19c - San Jose AICUG
Introducing new AIOps innovations in Oracle 19c - San Jose AICUGIntroducing new AIOps innovations in Oracle 19c - San Jose AICUG
Introducing new AIOps innovations in Oracle 19c - San Jose AICUGSandesh Rao
 
48742447 11g-sql-fundamentals-ii-additional-practices-and-solutions
48742447 11g-sql-fundamentals-ii-additional-practices-and-solutions48742447 11g-sql-fundamentals-ii-additional-practices-and-solutions
48742447 11g-sql-fundamentals-ii-additional-practices-and-solutionsAshwin Kumar
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMSMegha Patel
 
Find Anything In Your APEX App - Fuzzy Search with Oracle Text
Find Anything In Your APEX App - Fuzzy Search with Oracle TextFind Anything In Your APEX App - Fuzzy Search with Oracle Text
Find Anything In Your APEX App - Fuzzy Search with Oracle TextCarsten Czarski
 
Domain Modeling in a Functional World
Domain Modeling in a Functional WorldDomain Modeling in a Functional World
Domain Modeling in a Functional WorldDebasish Ghosh
 
Oracle Multitenant meets Oracle RAC - IOUG 2014 Version
Oracle Multitenant meets Oracle RAC - IOUG 2014 VersionOracle Multitenant meets Oracle RAC - IOUG 2014 Version
Oracle Multitenant meets Oracle RAC - IOUG 2014 VersionMarkus Michalewicz
 
Bootcamp sql fundamental
Bootcamp sql fundamentalBootcamp sql fundamental
Bootcamp sql fundamentalvarunbhatt23
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLanandology
 
Build Moses on Ubuntu (64-bit) in VirtualBox: recorded by Aaron
Build Moses on Ubuntu (64-bit) in VirtualBox: recorded by AaronBuild Moses on Ubuntu (64-bit) in VirtualBox: recorded by Aaron
Build Moses on Ubuntu (64-bit) in VirtualBox: recorded by AaronLifeng (Aaron) Han
 
How to Find Patterns in Your Data with SQL
How to Find Patterns in Your Data with SQLHow to Find Patterns in Your Data with SQL
How to Find Patterns in Your Data with SQLChris Saxon
 
Lecture 04 normalization
Lecture 04 normalization Lecture 04 normalization
Lecture 04 normalization emailharmeet
 

What's hot (20)

C#, imparare a programmare e sopravvivere
C#, imparare a programmare e sopravvivereC#, imparare a programmare e sopravvivere
C#, imparare a programmare e sopravvivere
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
utPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQLutPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQL
 
Introducing new AIOps innovations in Oracle 19c - San Jose AICUG
Introducing new AIOps innovations in Oracle 19c - San Jose AICUGIntroducing new AIOps innovations in Oracle 19c - San Jose AICUG
Introducing new AIOps innovations in Oracle 19c - San Jose AICUG
 
The PostgreSQL Query Planner
The PostgreSQL Query PlannerThe PostgreSQL Query Planner
The PostgreSQL Query Planner
 
48742447 11g-sql-fundamentals-ii-additional-practices-and-solutions
48742447 11g-sql-fundamentals-ii-additional-practices-and-solutions48742447 11g-sql-fundamentals-ii-additional-practices-and-solutions
48742447 11g-sql-fundamentals-ii-additional-practices-and-solutions
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
 
Find Anything In Your APEX App - Fuzzy Search with Oracle Text
Find Anything In Your APEX App - Fuzzy Search with Oracle TextFind Anything In Your APEX App - Fuzzy Search with Oracle Text
Find Anything In Your APEX App - Fuzzy Search with Oracle Text
 
Domain Modeling in a Functional World
Domain Modeling in a Functional WorldDomain Modeling in a Functional World
Domain Modeling in a Functional World
 
Oracle Multitenant meets Oracle RAC - IOUG 2014 Version
Oracle Multitenant meets Oracle RAC - IOUG 2014 VersionOracle Multitenant meets Oracle RAC - IOUG 2014 Version
Oracle Multitenant meets Oracle RAC - IOUG 2014 Version
 
SQL
SQL SQL
SQL
 
Bootcamp sql fundamental
Bootcamp sql fundamentalBootcamp sql fundamental
Bootcamp sql fundamental
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
 
Build Moses on Ubuntu (64-bit) in VirtualBox: recorded by Aaron
Build Moses on Ubuntu (64-bit) in VirtualBox: recorded by AaronBuild Moses on Ubuntu (64-bit) in VirtualBox: recorded by Aaron
Build Moses on Ubuntu (64-bit) in VirtualBox: recorded by Aaron
 
Get to know PostgreSQL!
Get to know PostgreSQL!Get to know PostgreSQL!
Get to know PostgreSQL!
 
How to Find Patterns in Your Data with SQL
How to Find Patterns in Your Data with SQLHow to Find Patterns in Your Data with SQL
How to Find Patterns in Your Data with SQL
 
Lecture 04 normalization
Lecture 04 normalization Lecture 04 normalization
Lecture 04 normalization
 
PostgreSQL: Advanced indexing
PostgreSQL: Advanced indexingPostgreSQL: Advanced indexing
PostgreSQL: Advanced indexing
 
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
Views, Triggers, Functions, Stored Procedures,  Indexing and JoinsViews, Triggers, Functions, Stored Procedures,  Indexing and Joins
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
 
DBMS Unit 2 ppt.ppt
DBMS Unit 2 ppt.pptDBMS Unit 2 ppt.ppt
DBMS Unit 2 ppt.ppt
 

Similar to Summary of C++17 features

PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12Andrew Dunstan
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0xppd1961
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side JavascriptJulie Iskander
 
Domain Specific Languages In Scala Duse3
Domain Specific Languages In Scala Duse3Domain Specific Languages In Scala Duse3
Domain Specific Languages In Scala Duse3Peter Maas
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojureAbbas Raza
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003R696
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introductioncaswenson
 
Cpp17 and Beyond
Cpp17 and BeyondCpp17 and Beyond
Cpp17 and BeyondComicSansMS
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossumoscon2007
 
from java to c
from java to cfrom java to c
from java to cVõ Hòa
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeMicrosoft Tech Community
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeMicrosoft Tech Community
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 

Similar to Summary of C++17 features (20)

Python 3000
Python 3000Python 3000
Python 3000
 
PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12PostgreSQL 8.4 TriLUG 2009-11-12
PostgreSQL 8.4 TriLUG 2009-11-12
 
Glimpses of C++0x
Glimpses of C++0xGlimpses of C++0x
Glimpses of C++0x
 
C to perl binding
C to perl bindingC to perl binding
C to perl binding
 
Go Lang Tutorial
Go Lang TutorialGo Lang Tutorial
Go Lang Tutorial
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
srgoc
srgocsrgoc
srgoc
 
Domain Specific Languages In Scala Duse3
Domain Specific Languages In Scala Duse3Domain Specific Languages In Scala Duse3
Domain Specific Languages In Scala Duse3
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
 
Cpp17 and Beyond
Cpp17 and BeyondCpp17 and Beyond
Cpp17 and Beyond
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossum
 
from java to c
from java to cfrom java to c
from java to c
 
C++11
C++11C++11
C++11
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
C++ theory
C++ theoryC++ theory
C++ theory
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 

More from Bartlomiej Filipek

Empty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
Empty Base Class Optimisation, [[no_unique_address]] and other C++20 AttributesEmpty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
Empty Base Class Optimisation, [[no_unique_address]] and other C++20 AttributesBartlomiej Filipek
 
C++17 std::filesystem - Overview
C++17 std::filesystem - OverviewC++17 std::filesystem - Overview
C++17 std::filesystem - OverviewBartlomiej Filipek
 
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++17Bartlomiej Filipek
 
Recent c++ goodies (March 2018)
Recent c++ goodies (March 2018)Recent c++ goodies (March 2018)
Recent c++ goodies (March 2018)Bartlomiej Filipek
 
WPF - the future of GUI is near
WPF - the future of GUI is nearWPF - the future of GUI is near
WPF - the future of GUI is nearBartlomiej Filipek
 

More from Bartlomiej Filipek (8)

Empty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
Empty Base Class Optimisation, [[no_unique_address]] and other C++20 AttributesEmpty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
Empty Base Class Optimisation, [[no_unique_address]] and other C++20 Attributes
 
Vocabulary Types in C++17
Vocabulary Types in C++17Vocabulary Types in C++17
Vocabulary Types in C++17
 
C++17 std::filesystem - Overview
C++17 std::filesystem - OverviewC++17 std::filesystem - Overview
C++17 std::filesystem - Overview
 
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
 
Recent c++ goodies (March 2018)
Recent c++ goodies (March 2018)Recent c++ goodies (March 2018)
Recent c++ goodies (March 2018)
 
GPU - how can we use it?
GPU - how can we use it?GPU - how can we use it?
GPU - how can we use it?
 
WPF - the future of GUI is near
WPF - the future of GUI is nearWPF - the future of GUI is near
WPF - the future of GUI is near
 
3D User Interface
3D User Interface3D User Interface
3D User Interface
 

Recently uploaded

Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
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
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
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
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 

Recently uploaded (20)

2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
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
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
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...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
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
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 

Summary of C++17 features

  • 1. Summary of C++17 features Is this release good, great, amazing or meh? Bartłomiej Filipek http://www.bfilipek.com/ Blog version, annotated Last update: 25th Nov 2017
  • 2. About me www.bfilipek.com 10y+ experience Currently @Xara.com Text related features Somehow addicted to Cpp :D
  • 3. The plan C++17 timeline What we get Fixes and deprecation Language clarification Templates Attributes Simplification Filesystem Parallel STL Utils Summary
  • 4. Timeline The new standard for C++17 was approved at the beginning of September. But what was the journey to that point? How it all started?
  • 5. https://isocpp.org/std/status Here’s the up-to-date version of the timeline for the C++ standard. Around 13 years we need to wait for C++11 (since 98), but then the work speeded up! It’s clear from that picture how much work is going on. There’s the current trunk, plus several major branches with larger features (TS). At some point those branches are merged into the trunk. The committee meets several times per year and votes on the proposals.
  • 6. https://isocpp.org/std/the-committee Here’s the overview of all the groups that work on new features. Each larger feature has it’s own group!
  • 7. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4700.pdf https://github.com/cplusplus/draft If you have problem with sleep just download the draft for the standard (for free) and start reading!
  • 8.
  • 9. Ship every 3 years As I see here’s the major changed that happened in the standardization process: C++11 was so late (we expected it to be before 2010!), but the committee waited until all the features were ready. Now we focus on the deadline. If a feature is not ready, then it’s simply moved to the next standard.
  • 10. Merged: The Library Fundamentals 1 TS (most parts) Removal of some deprecated types and functions, including std::auto_ptr, std::random_shuffle, and old function adaptors Merged: The Parallelism TS, a.k.a. “Parallel STL.”, Merged: File System TS, Merged: The Mathematical Special Functions IS, Improving std::pair and std::tuple std::shared_mutex (untimed) Variant, Optional, Any Splicing Maps and Sets New auto rules for direct-list-initialization static_assert with no message typename in a template template parameter Removing trigraphs Nested namespace definition Attributes for namespaces and enumerators u8 character literals Allow constant evaluation for all non-type template arguments Fold Expressions Unary fold expressions and empty parameter packs Remove Deprecated Use of the register Keyword Remove Deprecated operator++(bool) Removing Deprecated Exception Specifications from C++17 Make exception specifications part of the type system Aggregate initialization of classes with base classes Lambda capture of *this Using attribute namespaces without repetition Dynamic memory allocation for over-aligned data __has_include in preprocessor conditionals Template argument deduction for class templates Non-type template parameters with auto type Guaranteed copy elision New specification for inheriting constructors (DR1941 et al) Direct-list-initialization of enumerations Stricter expression evaluation order constexpr lambda expressions Different begin and end types in range-based for [[fallthrough]] attribute [[nodiscard]] attribute [[maybe_unused]] attribute Ignore unknown attributes Pack expansions in using-declarations Structured Binding Declarations Hexadecimal floating-point literals init-statements for if and switch Inline variables DR: Matching of template template-arguments excludes compatible templates std::uncaught_exceptions() constexpr if-statements 1. Fixes and deprecation 2. Language clarification 3. Templates 4. Attributes 5. Simplification 6. Filesystem 7. Parallel STL 8. Utils
  • 11. Deprecation & Removal Removing trigraphs Removing register keyword Remove Deprecated operator++(bool) Cannot inherit from std::iterator
  • 12. auto_ptr is gone! MSVC 2017 using /std:c++latest: error C2039: 'auto_ptr': is not a member of 'std'
  • 13. Removing Deprecated Exception Specifications from C++17 void fooThrowsInt(int a) throw(int) { printf_s("can throw intsn"); if (a == 0) throw 1; } Use “noexcept”
  • 14. Fixes static_assert with no message New auto rules for direct-list-initialization auto x5{ 3 }; // decltype(x5) is int, not initializer_list Different begin and end types in range-based for { auto && __range = for - range - initializer; for (auto __begin = begin - expr, __end = end - expr; __begin != __end; ++__begin) { for_range_declaration = *__begin; statement } } { auto && __range = for - range - initializer; auto __begin = begin - expr; auto __end = end - expr; for (; __begin != __end; ++__begin) { for_range_declaration = *__begin; statement } }
  • 15. Language clarifications Guaranteed copy elision (only for temporary objects, not for Named RVO) Exception specifications part of the type system void foo() noexcept; void foo(); Dynamic memory allocation for over-aligned data new is now aware of the alignment of the object.
  • 16. Stricter expression evaluation order Why do we need make_unique? foo(make_unique<T>(), otherFunction()); foo(unique_ptr<T>(new T), otherFunction());
  • 18. Template argument deduction for class templates std::pair<int, double> p(10, 0.0); // same as std::pair p(10, 0.0); // deduced automatically! std::lock_guard<std::shared_timed_mutex, std::shared_lock<std::shared_timed_mutex>> lck(mut_, r1); // Can now become : std::lock_guard lck(mut_, r1); custom class template deduction guides
  • 19. Fold expressions auto SumCpp11() { return 0; } template<typename T1, typename... T> auto SumCpp11(T1 s, T... ts) { return s + SumCpp11(ts...); } template<typename ...Args> auto sum(Args ...args) { return (args + ... + 0); } template<typename ...Args> void FoldPrint(Args&&... args) { (cout << ... << forward<Args>(args)) << 'n'; }
  • 20. // SFINAE template <typename T, std::enable_if_t < std::is_pointer<T>{} > * = nullptr > auto get_value(T t) { return *t; } template <typename T, std::enable_if_t < !std::is_pointer<T>{} > * = nullptr > auto get_value(T t) { return t; } // Tag dispatching template <typename T> auto get_value(T t, std::true_type) { return *t; } template <typename T> auto get_value(T t, std::false_type) { return t; } template <typename T> auto get_value(T t) { return get_value(t, std::is_pointer<T>{}); }https://blog.tartanllama.xyz/if-constexpr/ template <typename T> auto get_value(T t)
  • 21. constexpr if template <typename T> auto get_value(T t) { if constexpr (std::is_pointer_v<T>) return *t; else return t; }
  • 22. Attributes [[fallthrough]] [[nodiscard]] [[maybe_unused]] @cppreference.com Attributes available in C++17 [[noreturn]] [[carries_dependency]] [[deprecated]] [[deprecated("msg")]] [[fallthrough]] [[nodiscard]] [[maybe_unused]] enum class[[nodiscard]] ErrorCode{ OK, Fatal, System, FileIssue }; ErrorCode Compute() { ... } ... Compute(); // warning!
  • 23. How will it simplify the code? Inline variables Great for header-only libs! constexpr if
  • 24. Structured Binding Declarations // works with arrays: double myArray[3] = { 1.0, 2.0, 3.0 }; auto[a, b, c] = myArray; auto[a, b] = myPair; // binds myPair.first/second (must implement get<N>) // non static, public members struct S { int x1; double y1; }; S f(); const auto[x, y] = f(); std::map myMap; for (const auto &[key, val] : myMap) { }
  • 25. Init-statement for if/switch { auto val = GetValue(); if (condition(val)) // on success else // on false... } if (auto val = GetValue(); condition(val)) // on success else // on false... if (const auto it = myString.find("Hello"); it != std::string::npos) std::cout << it << " Hellon"; if (const auto it = myString.find("World"); it != std::string::npos) std::cout << it << " Worldn";
  • 26. Structured bindings & init in if statements // better together: structured bindings + if initializer if (auto[iter, succeeded] = mymap.insert(value); succeeded) { use(iter); // ok // ... } // iter and succeeded are destroyed here
  • 27. Filesystem namespace fs = std::experimental::filesystem; void DisplayDirTree(const fs::path& pathToShow, int level) { if (fs::exists(pathToShow) && fs::is_directory(pathToShow)) { auto lead = std::string(level * 3, ' '); for (const auto& entry : fs::directory_iterator(pathToShow)) { auto filename = entry.path().filename(); if (fs::is_directory(entry.status())) { cout << lead << "[+] " << filename << "n"; DisplayDirTree(entry, level + 1); cout << "n"; } else if (fs::is_regular_file(entry.status())) DisplayFileInfo(entry, lead, filename); else cout << lead << " [?]" << filename << "n"; } } }
  • 28. Parallel STL std::vector<int> v = genLargeVector(); // standard sequential sort std::sort(v.begin(), v.end()); // explicitly sequential sort std::sort(std::seq, v.begin(), v.end()); // permitting parallel execution std::sort(std::par, v.begin(), v.end()); // permitting vectorization as well std::sort(std::par_unseq, v.begin(), v.end());
  • 29. Utils std::any std::variant std::optional string_view Searchers http://www.bfilipek.com/2017/09/cpp17-details-utils.html auto a = std::any(12); a = std::string("hello world"); a = 10.0f; cout << std::any_cast<float>(a); std::variant<int, float, std::string> abc; // get<> // get_if<> // visit() std::optional<std::string> ostr = GetUserResponse(); default_searcher boyer_moore_searcher boyer_moore_horspool_searcher
  • 30. Compiler support GCC 7.0 is feature complete Clang 5.0 MSVC 2017.4 has most of the features The separate part is the standard library for each compiler. They might be delayed, especially regarding parallel versions of the algorithms.
  • 31. Summary Is C++17 great? Amazing? Or just meh… ? I think it’s a very decent version of the standard! Maybe people would like to see more, but it was not possible due to the deadline. Without this we would have to wait a year or two to have all the “desired” features to be accepted.
  • 32. Bonus – seemyfreePDFwithdescriptionofalloftheC++17 features! http://www.bfilipek.com/2017/09/c17-in-detail-summary-bonus.html

Editor's Notes

  1. The new standard for C++17 was approved at the beginning of September. But what was the journey to that point? How it all started?
  2. Here’s the up-to-date version of the timeline for the C++ standard. Around 13 years we need to wait for C++11 (since 98), but then the work speeded up! It’s clear from that picture how much work is going on. There’s the current trunk, plus several major branches with larger features (TS). At some point those branches are merged into the trunk. The committee meets several times per year and votes on the proposals.
  3. Here’s the overview of all the groups that work on new features. Each larger feature has it’s own group!
  4. If you have problem with sleep just download the draft for the standard (for free) and start reading!
  5. As I see here’s the major changed that happened in the standardization process: C++11 was so late (we expected it to be before 2010!), but the committee waited until all the features were ready. Now we focus on the deadline. If a feature is not ready, then it’s simply moved to the next standard.
  6. he above code is deprecated since C++11. The only practical exception declaration is throw() that mean - this code won’t throw anything. But since C++11 it’s advised to use noexcept.
  7. In the above code we know that new T is quaranteed to happen before unique_ptr construction, but that's all. For example, new T might happen first, then otherFunction(), and then unique_ptr constructor. When otherFunction throws, then new T generates a leak (as the unique pointer is not yet created). When you use make_unique, then it’s not possible to leak, even when the order of execution is random. More of such problems in GotW #56: Exception-Safe Function Calls
  8. I think it’s a very decent version of the standard! Maybe people would like to see more, but it was not possible due to the deadline. Without this we would have to wait a year or two to have all the “desired” features to be accepted.