Construction for values of fixed enums
Before C++17, variable of fixed enumeration was initialized like this:
1 2 3 |
enum class E: unsigned char{}; E e{E(5)}; |
if we will try to initialize like this:
1 |
E e{ 5 }; |
we will have error: cannot convert ‘int’ to ‘E’ in initialization.
In C++17 it’s allowed to build.
uncaught_exceptions()
New function which returns count of exceptions which were thrown before.
For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
class A { public: ~A() { if (exception_count != std::uncaught_exceptions()) { std::cout << "execption during execution!!" << std::endl; } else { std::cout << "normal execution!" << std::endl; } } private: int exception_count = std::uncaught_exceptions(); }; int main() { try { A a; throw 1; } catch (...) { std::cout << "exception!" << std::endl; } return 0; } |
Attributes in namespaces and enumerators
In C++17 it’s allowed to use attributes in namespace and enums.
For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
enum Level { A1, A2 [[deprecated]], A3, A4 }; namespace A [[deprecated]] { //... } int main() { Level one = Level::A2; // WARNING: used deprecated enum value return 0; } |
Attribute namespaces without repetition
In C++17 atributes can be used without repetition namespace.
For example:
1 2 3 4 5 |
void g() { [[ using rpr: kernel, target(cpu,gpu)]] do task(); } |
Before C++17 it was like this:
1 2 3 4 5 |
void f() { [[rpr:: kernel, rpr:: target(cpu,gpu)]] do task(); } |
A variadic version of lock_guard called scoped_lock
In case if need to lock more than one mutex, code will be looks like this:
1 2 3 4 5 6 |
void f() { std::lock_guard lock_(m1); std::lock_guard lock2_(m2); std::lock_guard lock3_(m3); //... } |
To simplify code, in C++17 was added scoped_lock, which allows lock more then one lock.
For example:
1 2 3 4 5 6 7 8 9 10 11 12 |
class A { public: void f() { std::scoped_lock lock_(m1, m2, m3); //... } private: std::mutex m1; std::mutex m2; std::mutex m3; }; |
Variable templates for traits
For every standard type trait foo with a single, static member constant foo<Args…>::value, there is now a variable template foo_v<Args…>.
Related standard document: p0006r0.
Three-dimensional hypotenuse
In C++17 in <cmath> was added function for hypotenuse in 3-dimensonal space.
For example:
1 2 |
std::hypot(1, 2, 3) // returns std::sqrt(x^2 + y^2 + z^2)<strong> </strong> |
Non-const string::data
New method data() which returns non-const data
const CharT* data() const;
CharT* data(); |
Improving pair and tuple
Improved code in std::pair and std::tuple.
Standard related document: n4387.
Constexpr for char_traits
Added constexpr to char_traits.
Related standard document: p0426r1.
Changes to <chrono>
Adds floor, ceiling, division and rounding for time points; makes most member functions constexpr.
Related standard document: p0092r1.
shared_ptr for arrays
The class template shared_ptr now supports C-style arrays by passing T[] or T[N] as the template argument, and the constructor from a raw pointer will install an appropriate array deleter.
Related standard document: p0414r2.
shared_ptr::weak_type
The class shared_ptr<T> now has a member type weak_type which is weak_ptr<T>. This allows generic code to name the corresponding weak pointer type without having to destructure the shared pointer type.
Related standard document: p0163r0.
atomic::is_always_lock_free
A new static member constant is_always_lock_free that documents whether the operations of a given atomic type are always lock-free. The existing non-static member function is_lock_free may give different answers for different values of the atomic type.
Improved insertion for unique-key maps
Two new methods:
insert_or_assign() – do not needs default constructor of the mapped type and returns more information, then operator[]. Method returns pair of reference and bool value which indicates, object was inserted or not.
try_emplace(key, arg1, arg2, arg3) – does nothing if key already exists in the map, and otherwise inserts a new element constructed from the arguments. This interface guarantees that even if the arguments are bound to rvalue references, they are not moved from if the insertion does not take place.
Return type of emplace
Sequence containers whose emplace{,_front,_back} member function templates used to return void now return a reference to the newly inserted element. (Associative containers are not affected, since their insertion functions have always returned iterators to the relevant element.)
Splicing maps and sets
A new mechanism, node handles, has been added to the container library that allows transplanting elements between different map/set objects without touching the contained object. Moreover, this technique enables mutable access to key values of extracted nodes.
Related standard document: p0083r3.
Incomplete type support for allocators
This change relaxes the requirements on allocators to have complete value types, and allows, for example, recursive structures like:
1 2 3 |
struct X { std::vector<X> data; }; |
Related standard document: n4510.
Write more, thats all I have to say. Literally, it seems as though
you relied on the video to make your point. You obviously know what youre talking about, why waste your
intelligence on just posting videos to your site
when you could be giving us something informative to read?