
{"id":1566,"date":"2015-01-31T15:10:10","date_gmt":"2015-01-31T15:10:10","guid":{"rendered":"http:\/\/www.codergears.com\/Blog\/?p=1566"},"modified":"2015-02-04T23:36:40","modified_gmt":"2015-02-04T23:36:40","slug":"modernize-your-c-code","status":"publish","type":"post","link":"https:\/\/codergears.com\/Blog\/?p=1566","title":{"rendered":"Modernize your C++ code"},"content":{"rendered":"<p><span style=\"color: #474747;\">C++11 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.<\/span><br style=\"color: #474747;\" \/><br style=\"color: #474747;\" \/><span style=\"color: #474747;\">It&#8217;s interesting to detect automatically places where we can use some C++11 new features. For such needs\u00a0<\/span><a style=\"color: #0274bd;\" href=\"http:\/\/clang.llvm.org\/extra\/clang-modernize.html\">clang-modernize<\/a><span style=\"color: #474747;\">\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><!--more--><\/p>\n<p>Developers who utilze\u00a0Clang could easilly use the clang-modernize tool. However for Visual C++ developers and other compilers users it&#8217;s not an easy task to benefit from this interesting tool result.<br style=\"color: #474747;\" \/><br style=\"color: #474747;\" \/><span style=\"color: #474747;\">To let all C++ developers benefit from this amazing tool, <a href=\"http:\/\/www.cppdepend.com\">CppDepend<\/a> is \u00a0integrating it now in its latest windows version 5.1 in order to detect the places where the following features could be used:<\/span><\/p>\n<ul style=\"color: #474747;\">\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\">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<\/span><\/li>\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\">Loop Convert: Detect loops like for(&#8230;; &#8230;; &#8230;) to replace them with the new range-based loops in C++11 and give you the new range loop expression to use.<\/span><\/li>\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\">Pass-By-Value: Detect const-ref parameters that would benefit from using the\u00a0<a style=\"font-weight: inherit; font-style: inherit; color: #0274bd;\" href=\"http:\/\/clang.llvm.org\/extra\/PassByValueTransform.html\">pass-by-value idiom<\/a>.<\/span><\/li>\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\">auto_ptr: Detect the uses of the deprecated std::auto_ptr to replace by std::unique_ptr.<\/span><\/li>\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\">auto specifier: Detect places where to use the auto type specifier in variable declarations.<\/span><\/li>\n<li style=\"font-weight: inherit; font-style: inherit;\"><span style=\"font-weight: inherit; font-style: inherit;\">nullptr: Detect null literals to be replaced by nullptr where applicable.<\/span><\/li>\n<\/ul>\n<hr style=\"color: #474747;\" \/>\n<p><span id=\"Part1\" style=\"font-weight: bold; color: #496ca0;\">How do I use\u00a0this feature?<\/span><span style=\"color: #474747;\">\u00a0<\/span><br style=\"color: #474747;\" \/><br style=\"color: #474747;\" \/><span style=\"color: #474747;\">This feature is not enabled by default, and you can enable it from &#8220;Project properties&#8221;=&gt; Analysis=&gt;Modernize C++ Code.However, it will take more time to analyse your code base and it&#8217;s recommended to disable it as soon as you no longer need its results.\u00a0<\/span><br style=\"color: #474747;\" \/><br style=\"color: #474747;\" \/><\/p>\n<p><a href=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/modernize.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1570\" src=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/modernize.png\" alt=\"modernize\" width=\"872\" height=\"388\" \/><\/a>After the analysis you can find the CQLinq queries concerning the C++11 advices inside the &#8220;Modernize C++ Code&#8221; group:<\/p>\n<p><a href=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/modernize2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1571\" src=\"http:\/\/www.codergears.com\/Blog\/wp-content\/uploads\/modernize2.png\" alt=\"modernize2\" width=\"748\" height=\"229\" \/><\/a>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\" id=\"ctl00_MyContentPH_Image2\" class=\"aligncenter\" style=\"font-weight: inherit; font-style: inherit;\" src=\"http:\/\/cppdepend.com\/Img\/modernize3.png\" alt=\"\" width=\"404\" height=\"525\" \/><\/p>\n<p>What&#8217;s interesting in the advices 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\u00a0<span style=\"color: #474747;\">and bring a big added value to your C++ projects.<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C++11 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&#8217;s interesting to detect automatically places where we can use some C++11 new features. For such needs\u00a0clang-modernize\u00a0is a standalone tool used to &hellip; <a href=\"https:\/\/codergears.com\/Blog\/?p=1566\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Modernize your C++ code&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-1566","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/1566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1566"}],"version-history":[{"count":10,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/1566\/revisions"}],"predecessor-version":[{"id":1579,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=\/wp\/v2\/posts\/1566\/revisions\/1579"}],"wp:attachment":[{"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codergears.com\/Blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}