6 Useful New Features in C++17 – Part 1

In this 5 parts of blog series, Patrik from Scionova will talk about useful features in C++17, that can help you write better codes. Every Monday and Thursday new posts in this series will come out.

Every now and again, I have some time to spare in which I try to brush up or gain some new knowledge in different areas. In the previous project I was working in, C++14 was used as the latest approved revision of the C++ standard. But the C++17 is (almost entirely) supported by commonly used compilers and can be used in new projects. Therefore, I was thinking that this time it might be a good idea to familiarise myself with C++17 revision.

And it was good stuff that I was finding, so why not share these findings with my colleagues, and why not everyone? So that is what I did,  and the following is a small set of features of the C++17 revision that can help you write better and more maintainable code. Keep in mind though that there are a lot more features in this revision, here is a compilation of all changes between C++14 and C++17.

Short hand for nested namespace declaration

Large projects I’ve been working in have had a lot of nested namespaces, in the format like company::area::component. This pattern is also found in Android Open Source Project, e.g., android::hardware::wifi::V1_0::IWifi. C++17 supports a short hand in writing these Nested namespace on one single, neat looking line:

What’s more is that one can attach attributes to entire namespaces as well. One convenient use case could be to deprecate an entire namespace in an API.

Compiler Support

These features are all fully supported by GCC, MSVC, and clang. Below follows a table showing which version enables support for each feature respectively.

For more a detailed matrix with more compilers and all features of C++17 listed, follow this link

READ PART 2 “6 Useful New Features in C++17” HERE.

 

// Patrik Ingmarsson