{"id":267,"date":"2018-08-29T10:58:18","date_gmt":"2018-08-29T08:58:18","guid":{"rendered":"https:\/\/www.scionova.com\/?p=267"},"modified":"2019-01-10T11:25:23","modified_gmt":"2019-01-10T10:25:23","slug":"6-useful-new-features-in-c17-part-1","status":"publish","type":"post","link":"https:\/\/www.scionova.com\/en\/6-useful-new-features-in-c17-part-1\/","title":{"rendered":"6 Useful New Features in C++17 &#8211; Part 1"},"content":{"rendered":"<p><em>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\u00a0will come out.<\/em><\/p>\n<p>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.<\/p>\n<p>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, \u00a0and 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.<\/p>\n<h3>Short hand for nested namespace declaration<\/h3>\n<p>Large projects I&#8217;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 <a href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2014\/n4230.html\">Nested namespace<\/a> on one single, neat looking line:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-268\" src=\"https:\/\/scionova.evdy.se\/wp-content\/uploads\/2018\/08\/namespace1-300x62.png\" alt=\"\" width=\"774\" height=\"160\" srcset=\"https:\/\/www.scionova.com\/wp-content\/uploads\/2018\/08\/namespace1-300x62.png 300w, https:\/\/www.scionova.com\/wp-content\/uploads\/2018\/08\/namespace1-768x158.png 768w, https:\/\/www.scionova.com\/wp-content\/uploads\/2018\/08\/namespace1-1024x211.png 1024w, https:\/\/www.scionova.com\/wp-content\/uploads\/2018\/08\/namespace1.png 1360w\" sizes=\"(max-width: 774px) 100vw, 774px\" \/><\/p>\n<p>What&#8217;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.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-269\" src=\"https:\/\/scionova.evdy.se\/wp-content\/uploads\/2018\/08\/namespace2-300x87.png\" alt=\"\" width=\"768\" height=\"223\" srcset=\"https:\/\/www.scionova.com\/wp-content\/uploads\/2018\/08\/namespace2-300x87.png 300w, https:\/\/www.scionova.com\/wp-content\/uploads\/2018\/08\/namespace2-768x222.png 768w, https:\/\/www.scionova.com\/wp-content\/uploads\/2018\/08\/namespace2-1024x297.png 1024w, https:\/\/www.scionova.com\/wp-content\/uploads\/2018\/08\/namespace2.png 1360w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/p>\n<h3>Compiler Support<\/h3>\n<p>These features are all fully supported by GCC, MSVC, and clang. Below follows a table showing which version enables support for each feature respectively.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-280 alignnone\" src=\"https:\/\/scionova.evdy.se\/wp-content\/uploads\/2018\/08\/part1-300x35.png\" alt=\"\" width=\"685\" height=\"80\" srcset=\"https:\/\/www.scionova.com\/wp-content\/uploads\/2018\/08\/part1-300x35.png 300w, https:\/\/www.scionova.com\/wp-content\/uploads\/2018\/08\/part1-768x89.png 768w, https:\/\/www.scionova.com\/wp-content\/uploads\/2018\/08\/part1-1024x118.png 1024w, https:\/\/www.scionova.com\/wp-content\/uploads\/2018\/08\/part1.png 1248w\" sizes=\"(max-width: 685px) 100vw, 685px\" \/><\/p>\n<p>For more a detailed matrix with more compilers and all features of C++17 listed, follow this <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/compiler_support\">link<\/a><\/p>\n<h4><\/h4>\n<h4>READ PART 2 &#8220;6 Useful New Features in C++17&#8221;\u00a0<a href=\"https:\/\/scionova.evdy.se\/2018\/09\/03\/6-useful-new-features-in-c17-part-2\/\">HERE.<\/a><\/h4>\n<p>&nbsp;<\/p>\n<p>\/\/ Patrik Ingmarsson<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u00a0will come out. Every now and again, I have some time to spare in which I try to brush up or gain some [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":""},"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.scionova.com\/en\/wp-json\/wp\/v2\/posts\/267"}],"collection":[{"href":"https:\/\/www.scionova.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scionova.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scionova.com\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scionova.com\/en\/wp-json\/wp\/v2\/comments?post=267"}],"version-history":[{"count":0,"href":"https:\/\/www.scionova.com\/en\/wp-json\/wp\/v2\/posts\/267\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.scionova.com\/en\/wp-json\/wp\/v2\/media?parent=267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scionova.com\/en\/wp-json\/wp\/v2\/categories?post=267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scionova.com\/en\/wp-json\/wp\/v2\/tags?post=267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}