{"id":262,"date":"2018-01-26T21:34:33","date_gmt":"2018-01-26T21:34:33","guid":{"rendered":"http:\/\/cppdepend.com\/blog\/?p=262"},"modified":"2018-02-02T18:25:11","modified_gmt":"2018-02-02T18:25:11","slug":"easily-detect-where-you-can-add-the-new-c-features-inside-your-codebase","status":"publish","type":"post","link":"https:\/\/cppdepend.com\/blog\/easily-detect-where-you-can-add-the-new-c-features-inside-your-codebase\/","title":{"rendered":"Easily detect where you can modernize your C++ codebase."},"content":{"rendered":"<p>C++11\/C++14\/C++17\u00a0 includes several additions to the core language and extends the C++ standard library. Some of these new features are very easy to use and bring a big added value to your C++ projects.<\/p>\n<p>It\u2019s interesting to detect automatically places where we can use some C++11 new features. For such needs\u00a0<a href=\"http:\/\/clang.llvm.org\/extra\/clang-tidy\/\">clang-tidy<\/a>\u00a0is a standalone tool used to automatically convert C++ code, written against old standards, to use features of the newest C++ standard where appropriate.\u00a0<span id=\"more-1566\"><\/span><\/p>\n<p>Developers who utilze\u00a0Clang could easilly use the clang-tidy tool. However for Visual C++ developers and other compilers users it\u2019s not an easy task to benefit from this interesting tool result.<\/p>\n<p>To let all C++ developers benefit from this amazing tool,\u00a0<a href=\"http:\/\/www.cppdepend.com\/\">CppDepend<\/a>\u00a0is integrating it now in its latest windows version\u00a02018.1 in order to detect the places where the following features could be used:<!--more--><\/p>\n<ul>\n<li>Override: Detect places where you can add the override specifier to member functions that override a virtual function in a base class and that don\u2019t already have the specifier<\/li>\n<li>Loop Convert: Detect loops like for(\u2026; \u2026; \u2026) to replace them with the new range-based loops in C++11 and give you the new range loop expression to use.<\/li>\n<li>Pass-By-Value: Detect const-ref parameters that would benefit from using the\u00a0<a href=\"http:\/\/clang.llvm.org\/extra\/PassByValueTransform.html\">pass-by-value idiom<\/a>.<\/li>\n<li>auto_ptr: Detect the uses of the deprecated std::auto_ptr to replace by std::unique_ptr.<\/li>\n<li>auto specifier: Detect places where to use the auto type specifier in variable declarations.<\/li>\n<li>nullptr: Detect null literals to be replaced by nullptr where applicable.<\/li>\n<li>std::bind:The check finds uses of\u00a0<code class=\"docutils literal\"><span class=\"pre\">std::bind<\/span><\/code>\u00a0and replaces simple uses with lambdas. Lambdas will use value-capture where required.<\/li>\n<li>Deprecated headers:Some headers from C library were deprecated in C++ and are no longer welcome in C++ codebases. Some have no effect in C++. For more details refer to the C++ 14 Standard [depr.c.headers] section.<\/li>\n<li>std::shared_ptr: This check finds the creation of\u00a0<code class=\"docutils literal\"><span class=\"pre\">std::shared_ptr<\/span><\/code>\u00a0objects by explicitly calling the constructor and a\u00a0<code class=\"docutils literal\"><span class=\"pre\">new<\/span><\/code>\u00a0expression, and replaces it with a call to\u00a0<code class=\"docutils literal\"><span class=\"pre\">std::make_shared<\/span><\/code>.<\/li>\n<li>std::unique_ptr: This check finds the creation of\u00a0<code class=\"docutils literal\"><span class=\"pre\">std::unique_ptr<\/span><\/code>\u00a0objects by explicitly calling the constructor and a\u00a0<code class=\"docutils literal\"><span class=\"pre\">new<\/span><\/code>\u00a0expression, and replaces it with a call to\u00a0<code class=\"docutils literal\"><span class=\"pre\">std::make_unique<\/span><\/code>, introduced in C++14.<\/li>\n<li>raw string literals: This check selectively replaces string literals containing escaped characters with raw string literals.<\/li>\n<\/ul>\n<hr \/>\n<p><span id=\"Part1\">How do I use\u00a0this feature?<\/span><\/p>\n<p>This feature is not enabled by default, and you can enable it from \u201cProject properties\u201d=&gt; Analysis=&gt;Modernize C++ Code.However, it will take more time to analyse your code base and it\u2019s recommended to disable it as soon as you no longer need its results.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.cppdepend.com\/img\/blog\/clangtidy.png\" width=\"781\" height=\"309\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>After the analysis you can find the CQLinq queries concerning the C++11 advices inside the \u201cModernize C++ Code\u201d group:<\/p>\n<p><a href=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/modernize2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.cppdepend.com\/img\/blog\/modernize.png\" width=\"696\" height=\"312\" \/><\/a><\/p>\n<p>And for each query, you can get the places where you can modernize your code. You can double click each result to go in your source code where the improvements could be applied.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.cppdepend.com\/img\/blog\/nullptr.png\" width=\"557\" height=\"660\" \/><\/p>\n<p>What\u2019s interesting in the advises given by the Clang modernizer tool is the fact that they concern some of the most interesting C++11 features which are very easy to introduce in your source code\u00a0and bring a big added value to your C++ projects.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C++11\/C++14\/C++17\u00a0 includes several additions to the core language and extends the C++ standard library. Some of these new features are very easy to use and bring a big added value to your C++ projects. It\u2019s interesting to detect automatically places where we can use some C++11 new features. For such needs\u00a0clang-tidy\u00a0is a standalone tool used &hellip; <a href=\"https:\/\/cppdepend.com\/blog\/easily-detect-where-you-can-add-the-new-c-features-inside-your-codebase\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Easily detect where you can modernize your C++ codebase.&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7,30],"class_list":["post-262","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-c","tag-modern-c"],"_links":{"self":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/comments?post=262"}],"version-history":[{"count":10,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/262\/revisions"}],"predecessor-version":[{"id":280,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/posts\/262\/revisions\/280"}],"wp:attachment":[{"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/media?parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/categories?post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cppdepend.com\/blog\/wp-json\/wp\/v2\/tags?post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}