Due to constant С++ extension developers have to be in-the-know and regularly follow all the changes, introduced by the new standard. So, new possibilities and rules have been introduced in C++17. GCC, Clang, Visual Studio compiler developers are already actively adding them.

One of the developers of PVS-Studio static code analyzer wrote an overview article with the most interesting innovations and also demonstrated them with examples.

For instance, new logical meta functions std::conjunction, std:: disjunction and std::negation have been introduced. They are used to perform a logical AND, OR, NOT on a set of traits, respectively. Here is also a small example with std::conjunction:

Code:
// C++17
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>

template<typename... Args>
std::enable_if_t<std::conjunction_v<std::is_integral<Args>...>>
Func(Args... args)
{
  std::cout << "All types are integral.\n";
}

template<typename... Args>
std::enable_if_t<!std::conjunction_v<std::is_integral<Args>...>>
Func(Args... args)
{
  std::cout << "Not all types are integral.\n";
}

int main()
{
  Func(42, true); // All types are integral.
  Func(42, "hello"); // Not all types are integral. 

  return 0;
}

Besides, the article touches upon such examples, as:

  • Fold expressions
  • template<auto>
  • Class template argument deduction
  • Constexpr if
  • Constexpr lambdas
  • *this capture in lambda expressions
  • inline variables
  • Structured bindings
  • Initializer in 'if' and 'switch'
  • __has_include
  • and many other interesting features



The full version of the article is available by the link: https://www.viva64.com/en/b/0533/