Reading about the C++ language I have seen that some developers talk about C++17 and it is not clear to me if it is the same as C++ or if it is another language.
What is C++17?
Reading about the C++ language I have seen that some developers talk about C++17 and it is not clear to me if it is the same as C++ or if it is another language.
What is C++17?
C++17 is C++!
It is the sixth revision of the C++ Programming Language, it is not called C++6 because the revisions are not numbered by the revision order but by the year in which the International Organization for Standardization (ISO) approves the revision. language revision (also known as Programming Language Dialect ).
What came before C++17?
This is a brief summary of the history of the C++ language:
What does C++17 add?
Thus, C++17 is nothing more than a revision of the C++ language. What does this revision add compared to previous versions?
Parameter Deduction in Template Objects .Template objects can infer template parameters in a similar way to how they are inferred in template functions:
However, this deduction does not work exactly the same as the template deduction function, as it does not support partial deduction .
Type deduction in non-typed template parameters .It can be used
Allowauto
as a template parameter so that the template infers the underlying type of the supplied non-type parameter:typename
in templates-template .When declaring a template-template can now be used interchangeably
Folding Expressions .typename
orclass
( previously it couldn't ):It is possible to apply certain operators on parameter packs in variadic templates:
The folding operators are :
New deduction rules for values in curly braces (+
,,,,,,,,,,,,,,,,,,,,,,,,,, y and can be deployed like this : _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _-
*
/
%
^
&
|
~
=
<
>
<<
>>
+=
-=
*=
/=
%=
^=
&=
|=
<<=
>>=
==
!=
<=
>=
&&
||
,
.*
->*
{}
) .When there is only one value between braces, it will be deduced as a value, not as a list:
Expand parameter packs into clausesusing
.Having a base object like the following:
And an object that derives from several
base
:We can bring into scope
Lambdas constant expression .derivado
all versions ofbase<T>::f(T)
with a using clause:If the lambda meets the requirements to be a constant expression, it can be used as such:
It could be omitted
Captureconstexpr
from the lambda declaration as they will be constant expressions by default if they meet the requirements to be so.*this
in lambdas .In a lambda declared inside an object's method, generic catches catch
attributethis
as a pointer:[[fallthrough]]
.It tells the compiler that the absence of a statement
attributebreak
at the end ofcase
aswitch
is intentional:[[nodiscard]]
.Indicates to the compiler that a data type or the return of a function should not be discarded.
attribute[[maybe_unused]]
.Indicates to the compiler that an entity might not be used intentionally.
The code above will not display alarms for not using the function
Namespaced and Enumerated Attributes .debug
or not using the valuevalor
.It is possible to apply attributes on namespaces and enumerated values:
Variablesinline
.It is possible to make variables behave like functions
Nested Namespaces .inline
, that is, to treat multiple identical definitions of the variable as the same definition.The namespace:
can be declared as
Simplification ofstatic_assert
.It is no longer mandatory to add a text to
Exception Specifications .static_assert
.As of C++17, if a function does not have a clause
Structured Matching .throw
in its signature, it is considered that it does not throw exceptions.For functions with multiple return values (returning
Initializer in control structures .std::pair
,std::tuple
,std::array
and aggregates) it is possible to get each return value separately:It is possible to declare and initialize variables in
if
andswitch
:for
Generalized Range Loop .begin
And in the range for are now allowed toend
be of different types.if
constant condition .It can be added
WIP... .constexpr
to the clauseif
. If the condition of the constant condition is not met, the code inside that condition will not compile.Adding more stuff.