C++17: global changes

Exception specification as part of the type system

A prvalue of type “pointer to noexcept function” can be converted to a prvalue of type “pointer to function”. The result is a pointer to the function. A prvalue of type “pointer to member of type noexcept function” can be converted to a prvalue of type “pointer to member of type function”. The result points to the member function.

Example:

Continue reading “C++17: global changes”

C++17: Guaranted copy elision

From C++17 compilers are required to omit copy/move construction resulting in zero-copy pass-by-value semantics. Objects will be created directly in storage where they would copy/move.

  • In return statement when operand is prvalue:

  • In the initialization of a variable, when initialization expression is a prvalue of the same type:

C++17 core language specification of prvalues and temporaries is fundamentally different from that of the earlier C++ revisions: there is no longer a temporary to copy/move from. Another way to describe C++17 mechanics is “unmaterialized value passing”: prvalues are returned and used without ever materializing a temporary.

Continue reading “C++17: Guaranted copy elision”

C++17: Deprecated features

Deprecate redeclaration of static constexpr class members

When inline variables are presented in C++17, static constexpr redeclaration is not needed.

 

Deprecate C library headers

List of C libraries which are deprecated from C++17:

<ccomplex> – simply deleting the requirement for a <ccomplex> header is simpler, and may be better, than making it optional. Of course an implementation would not need to change in order to conform to the new state of affairs, but programs that use <ccomplex> instead of <complex> would cease to be strictly conforming.

<ctgmath> – simply includes header <ccomplex> and <cmath>

<cstdalign> – mentioned as pointless in C++

<cstdbool> – mentioned as pointless in C++

Continue reading “C++17: Deprecated features”

C++17: std::invoke & std::apply

std::invoke

std::invoke is used for calling function objects, like lambdas, methods, functions without knowing about type this function.

For example , before we needed to use pointer to function, pointer to method:

Continue reading “C++17: std::invoke & std::apply”