{"id":1630,"date":"2017-08-01T09:33:43","date_gmt":"2017-08-01T08:33:43","guid":{"rendered":"http:\/\/www.nuonsoft.com\/blog\/?p=1630"},"modified":"2017-08-01T09:33:43","modified_gmt":"2017-08-01T08:33:43","slug":"c17-nested-namespaces","status":"publish","type":"post","link":"https:\/\/www.nuonsoft.com\/blog\/2017\/08\/01\/c17-nested-namespaces\/","title":{"rendered":"C++17: Nested Namespaces"},"content":{"rendered":"<p>The second post in this series of C++17 features highlights a tiny but very useful new feature called\u00a0<strong>nested namespaces<\/strong>.<\/p>\n<p>Using multi-level namespaces in C++ has always been a pain. Suppose you are writing a game and you have a namespace called Core::Graphics::Rendering. Before C++17 you had to resort to something as follows<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">namespace Core {\r\n    namespace Graphics {\r\n        namespace Rendering {\r\n\r\n            class PostProcessor\r\n            {\r\n            };\r\n\r\n        }\r\n    }\r\n}<\/pre>\n<p>This leaves you with a very big indentation scheme. You could try to make it look a bit better as follows:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">namespace Core { namespace Graphics { namespace Rendering {\r\n\r\n    class PostProcessor\r\n    {\r\n    };\r\n\r\n}}}<\/pre>\n<p>But this does not always plays nice with the auto formatting functionality of your IDE.<\/p>\n<p>Say hello to C++17 <strong>nested namespaces<\/strong>. Now you can simply write the following:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">namespace Core::Graphics::Rendering {\r\n\r\n    class PostProcessor\r\n    {\r\n    };\r\n\r\n}<\/pre>\n<p>Nested namespaces are supported in Microsoft Visual C++ 2015 since Update 3.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The second post in this series of C++17 features highlights a tiny but very useful new feature called\u00a0nested namespaces. Using multi-level namespaces in C++ has always been a pain. Suppose you are writing a game and you have a namespace called Core::Graphics::Rendering. Before C++17 you had to resort to something as follows namespace Core { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[222,228],"class_list":["post-1630","post","type-post","status-publish","format-standard","hentry","category-c","tag-c17","tag-visual-c-2017"],"_links":{"self":[{"href":"https:\/\/www.nuonsoft.com\/blog\/wp-json\/wp\/v2\/posts\/1630","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nuonsoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nuonsoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nuonsoft.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nuonsoft.com\/blog\/wp-json\/wp\/v2\/comments?post=1630"}],"version-history":[{"count":3,"href":"https:\/\/www.nuonsoft.com\/blog\/wp-json\/wp\/v2\/posts\/1630\/revisions"}],"predecessor-version":[{"id":1633,"href":"https:\/\/www.nuonsoft.com\/blog\/wp-json\/wp\/v2\/posts\/1630\/revisions\/1633"}],"wp:attachment":[{"href":"https:\/\/www.nuonsoft.com\/blog\/wp-json\/wp\/v2\/media?parent=1630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nuonsoft.com\/blog\/wp-json\/wp\/v2\/categories?post=1630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nuonsoft.com\/blog\/wp-json\/wp\/v2\/tags?post=1630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}