c++14 Function return type auto
Two ,lambda parameter auto
stay C++11 in ,lamdba Function arguments need to be declared as concrete types .C++14 Relaxed this requirement , allow lambda Function parameter types use type specifiers auto.
Simple code , And enhance refactoring .
utilize deprecated Miscellaneous notes , Function can be indicated , Type or any other identifier is no longer supported by future versions , Or they should not be used again .
#pragma deprecated( identifier1 [,identifier2, …] )
constexpr It means that this thing can be calculated at compile time （ The premise is that in order to calculate what it depends on, it can also be calculated at compile time ）. and const It only ensures that the runtime is not modified directly （ But it could still be a dynamic variable ）,const Decorated with type ,constexpr It's the code used to calculate the value .
stay C++11 in , use constexpr Declared functions can be executed at compile time , Generate a value , Used where constant expressions are required , For example, as the shape parameter of initialization template .C++11 Of constexpr Function can only contain one expression ,C++14 Relaxed these restrictions , Support such as if
and switch Equal conditional statement , Support cycle , This includes interval based （range） Of for loop .
C++17 One ,auto
from c++11 start ,auto Keyword can deduce the type of variable through initializer . stay c++14 in ,auto Further improve the ability of keywords , Able to pass return Statement derived function return type .
use auto Keywords can improve coding efficiency , At the same time, it can simplify the reconstruction process . however ,C++11 In auto deduction , Often the result is different from the expectation .
lambda It's also c++11 Introduced in , stay C++11 in ,lambda Expressions can only be captured with this,this Is a read-only reference to the current object .
stay C++17 in , Can capture this, this Is a copy of the current object , Capture a copy of the current object , Ensures that the current object is released ,
lambda Expression can be called safely this Variables and methods in .
Three , Conditional statement initialization
c++17 Supported in if perhaps switch Initialization in statement , This ability can make the code more concise .
std::optional Indicates a possible value . When we create an object through a function , Error codes are usually returned through functions , And return the object itself through the parameter .
has_value() // Check whether the object has a value
value() // Returns the value of the object , Thrown if the value does not exist std::bad_optional_access abnormal
value_or() // Return value when value exists , Return the default value when it does not exist
At the same time, there are other security functions