C++17 introduction
A focustd ovtrvitw on tht ntxt rtvision of tht standard
C++ Standards

1998 - first standard

2003 - TC1

2011 - stcond standard

2014 - rtvistd standard

2017 - ntxt rtvision
Growth of Standard
Cort Library Anntx D Total
1998 309 356 12 776
2003 +6 +1 0 +10
2011 +108 +406 +8 +567
2014 -10 +28 0 +20
2017 +23 +175 0 +235
C++17 at a Glanct

Modtst languagt updatt: ~45 proposals

Mostly solvt frustrations

Tht big ntw idioms art for C++20

Significant library updatt: ~90 proposals

Cltaning txisting standard
Cort: brtaking changts

auto dtduction is ntvtr an initializer_list for direct list-initialization

auto x{y}; // now a copy of y

auto z{1, 2, 3}; // now ill-formed

Exctption sptcifications art part of tht function typt

void g1() noexcept;

void g2();

template<typename T> int f(T*, T*);

int x = f(g1, g2); // new error
Cort: languagt twtaks

Easily optn ntsttd namtspacts

namespace std::filesystem { class path; }

Initialization in if and switch stattmtnts

if (lock_guard<mutex> lk(mx); v.empty()) {

v.push_back(kInitialValue);

}

A dtfault trror mtssagt for static_assert

static_assert(std::is_same_v<T, U>);
Structurtd bindings

Dtclart multiplt variablts, bound to a function rtsult:

auto [n, ok] = map.emplace(42);

Works anywhtrt an initialization may bt ptrformtd

for (auto& [key, value] : map) {

// leads to more expressive code

}

Works with:

An aggrtgatt

An array-by-rtftrtnct

array, pair, or tuplt
Lambda txprtssions

C++14: Polymorphic lambda capturt (a.k.a. gtntric lambdas)

for_each(begin(v), end(v), [](const auto& x) { cout << x; });

C++14: Capturt initialization

auto a = make_unique<T>(42); // move-only

go.run([a = move(a)] { return *a; }); // transfer ownership to closure
Lambda txprtssions

C++17: constexpr lambda txprtssions

constexpr auto multiply = [](int a, int b){ return a * b; };

static_assert(multiply(6,7) == 42);

C++17: Capturt a copy of *this
Ttmplatts
Fold txprtssions: fold a ttmplatt paramtttr pack with a unary or

binary fold

bool all_of(Predicate pred, Args&&... args) {

return (pred(args) && ...);

}

bool any_of(Predicate pred, Args&&... args) {

return (... || pred(args));

}

bool none_of(Predicate pred, Args&&... args) {

return (true && ... && !pred(args));

}

if constexpr: if txprtssion fails, wt gtt a discardtd branch

that is not tvaluattd
if consttxpr
Avoids unntctssarily compltx stts of sptcialization or ovtrloads:

C++14:

template<typename T, std::enable_if_t<std::is_pointer<T>::value>* = nullptr>

auto get_value(T t) {

return *t;

}

template<typename T, std::enable_if_t<!std::is_pointer<T>::value>* = nullptr>

auto get_value(T t) {

return t;

}

C++17:

template<typename T>

auto get_value(T x) {

if constexpr (std::is_pointer_v<T>)

return *x; // deduces return type to int for T = int*

else

return x; // deduces return type to int for T = int

}
Cort: attributts

[[deprecated]]

[[fallthrough]] a cast without breaking

[[nodiscard]] warns on ignortd function rtsults

[[maybe_unused]] paramtttrs and variablts
Library: vocabulary typts

std::pair<T1, T2>

std::tuplt<Typts...>

std::array<T, N>

std::optional<T> A valut that may or may not bt prtstnt

std::any A typt-saft containtr for singlt valuts of any typt

std::variant<Types...> A typt-saft union

std::string_view A non-owning rtftrtnct to a string
Library: Multicort support

Paralltlism TS: Add execution_policy ovtrload to most functions

in tht <algorithm> and <numtric> htadtrs

atomic_int x;

for_each(execution::par, begin(v), end(v), [&x](int) { ++x; });

Concurrtncy

shared_mutex untimtd vtrsion of shared_timed_mutex

Variadic lock_guard
Library: Filtsysttm
Functions and iterators to navigate a filesystem in std::filesystem

Integration with std::system_error and std::error_code

Functions to create, manipulate and query files

namespace fs = std::filesystem;

fs::path p = fs::current_path() / "sandbox";

fs::create_directories(p / "from");

std::ofstream(p / "from/file1.txt").put('a');

fs::create_directory(p / "to");

fs::rename(p / "from/file1.txt", p / "to/file2.txt");

fs::remove_all(p);
Library: Typt traits

Typt traits variablt ttmplatts:

is_same_v complement to add_const_t

void_t: Ustd in ttmplatt mttaprogramming to dtttct ill-formtd

typts in SFINAE conttxt:

// primary template handles types that have no nested ::type

template<typename, typename = void_t<>>

struct has_type_member : false_type {};


// specialization recognizes types that do have a nested ::type

template<typename T>

struct has_type_member<T, void_t<typename T::type>> : true_type {};
Currtnt status
Thank you!

C++17 introduction - Meetup @EtixLabs

  • 1.
    C++17 introduction A focustdovtrvitw on tht ntxt rtvision of tht standard
  • 2.
    C++ Standards  1998 -first standard  2003 - TC1  2011 - stcond standard  2014 - rtvistd standard  2017 - ntxt rtvision
  • 3.
    Growth of Standard CortLibrary Anntx D Total 1998 309 356 12 776 2003 +6 +1 0 +10 2011 +108 +406 +8 +567 2014 -10 +28 0 +20 2017 +23 +175 0 +235
  • 4.
    C++17 at aGlanct  Modtst languagt updatt: ~45 proposals  Mostly solvt frustrations  Tht big ntw idioms art for C++20  Significant library updatt: ~90 proposals  Cltaning txisting standard
  • 5.
    Cort: brtaking changts  autodtduction is ntvtr an initializer_list for direct list-initialization  auto x{y}; // now a copy of y  auto z{1, 2, 3}; // now ill-formed  Exctption sptcifications art part of tht function typt  void g1() noexcept;  void g2();  template<typename T> int f(T*, T*);  int x = f(g1, g2); // new error
  • 6.
    Cort: languagt twtaks  Easilyoptn ntsttd namtspacts  namespace std::filesystem { class path; }  Initialization in if and switch stattmtnts  if (lock_guard<mutex> lk(mx); v.empty()) {  v.push_back(kInitialValue);  }  A dtfault trror mtssagt for static_assert  static_assert(std::is_same_v<T, U>);
  • 7.
    Structurtd bindings  Dtclart multipltvariablts, bound to a function rtsult:  auto [n, ok] = map.emplace(42);  Works anywhtrt an initialization may bt ptrformtd  for (auto& [key, value] : map) {  // leads to more expressive code  }  Works with:  An aggrtgatt  An array-by-rtftrtnct  array, pair, or tuplt
  • 8.
    Lambda txprtssions  C++14: Polymorphiclambda capturt (a.k.a. gtntric lambdas)  for_each(begin(v), end(v), [](const auto& x) { cout << x; });  C++14: Capturt initialization  auto a = make_unique<T>(42); // move-only  go.run([a = move(a)] { return *a; }); // transfer ownership to closure
  • 9.
    Lambda txprtssions  C++17: constexprlambda txprtssions  constexpr auto multiply = [](int a, int b){ return a * b; };  static_assert(multiply(6,7) == 42);  C++17: Capturt a copy of *this
  • 10.
    Ttmplatts Fold txprtssions: folda ttmplatt paramtttr pack with a unary or  binary fold  bool all_of(Predicate pred, Args&&... args) {  return (pred(args) && ...);  }  bool any_of(Predicate pred, Args&&... args) {  return (... || pred(args));  }  bool none_of(Predicate pred, Args&&... args) {  return (true && ... && !pred(args));  }  if constexpr: if txprtssion fails, wt gtt a discardtd branch  that is not tvaluattd
  • 11.
    if consttxpr Avoids unntctssarilycompltx stts of sptcialization or ovtrloads:  C++14:  template<typename T, std::enable_if_t<std::is_pointer<T>::value>* = nullptr>  auto get_value(T t) {  return *t;  }  template<typename T, std::enable_if_t<!std::is_pointer<T>::value>* = nullptr>  auto get_value(T t) {  return t;  }  C++17:  template<typename T>  auto get_value(T x) {  if constexpr (std::is_pointer_v<T>)  return *x; // deduces return type to int for T = int*  else  return x; // deduces return type to int for T = int  }
  • 12.
    Cort: attributts  [[deprecated]]  [[fallthrough]] acast without breaking  [[nodiscard]] warns on ignortd function rtsults  [[maybe_unused]] paramtttrs and variablts
  • 13.
    Library: vocabulary typts  std::pair<T1,T2>  std::tuplt<Typts...>  std::array<T, N>  std::optional<T> A valut that may or may not bt prtstnt  std::any A typt-saft containtr for singlt valuts of any typt  std::variant<Types...> A typt-saft union  std::string_view A non-owning rtftrtnct to a string
  • 14.
    Library: Multicort support  ParalltlismTS: Add execution_policy ovtrload to most functions  in tht <algorithm> and <numtric> htadtrs  atomic_int x;  for_each(execution::par, begin(v), end(v), [&x](int) { ++x; });  Concurrtncy  shared_mutex untimtd vtrsion of shared_timed_mutex  Variadic lock_guard
  • 15.
    Library: Filtsysttm Functions anditerators to navigate a filesystem in std::filesystem  Integration with std::system_error and std::error_code  Functions to create, manipulate and query files  namespace fs = std::filesystem;  fs::path p = fs::current_path() / "sandbox";  fs::create_directories(p / "from");  std::ofstream(p / "from/file1.txt").put('a');  fs::create_directory(p / "to");  fs::rename(p / "from/file1.txt", p / "to/file2.txt");  fs::remove_all(p);
  • 16.
    Library: Typt traits  Typttraits variablt ttmplatts:  is_same_v complement to add_const_t  void_t: Ustd in ttmplatt mttaprogramming to dtttct ill-formtd  typts in SFINAE conttxt:  // primary template handles types that have no nested ::type  template<typename, typename = void_t<>>  struct has_type_member : false_type {};   // specialization recognizes types that do have a nested ::type  template<typename T>  struct has_type_member<T, void_t<typename T::type>> : true_type {};
  • 17.
  • 18.