{"id":1917,"date":"2021-04-01T00:51:56","date_gmt":"2021-04-01T04:51:56","guid":{"rendered":"https:\/\/blog.wholetomato.com\/?p=1917"},"modified":"2021-04-01T08:49:09","modified_gmt":"2021-04-01T12:49:09","slug":"how-to-modernize-with-visual-assist-part-2","status":"publish","type":"post","link":"https:\/\/stage.wholetomato.com\/blog\/how-to-modernize-with-visual-assist-part-2\/","title":{"rendered":"How To Modernize With Visual Assist Part 2"},"content":{"rendered":"\n<p>In the previous article, you read about five popular techniques to improve your projects and apply several Modern C++ patterns. Here&#8217;s a list of five more things! We&#8217;ll go from the override keyword to nullptr, scoped enums, and more. All techniques are super-easy with Visual Assist!<\/p>\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_76 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\r\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\r\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/stage.wholetomato.com\/blog\/how-to-modernize-with-visual-assist-part-2\/#1_Override\" >1. Override<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/stage.wholetomato.com\/blog\/how-to-modernize-with-visual-assist-part-2\/#2_nullptr\" >2. nullptr<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/stage.wholetomato.com\/blog\/how-to-modernize-with-visual-assist-part-2\/#3_Convert_enum_to_scoped_enum\" >3. Convert enum to scoped enum<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/stage.wholetomato.com\/blog\/how-to-modernize-with-visual-assist-part-2\/#4_Use_more_auto\" >4. Use more auto<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/stage.wholetomato.com\/blog\/how-to-modernize-with-visual-assist-part-2\/#5_Deprecated_functionality\" >5. Deprecated functionality<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/stage.wholetomato.com\/blog\/how-to-modernize-with-visual-assist-part-2\/#Some_other_handy_fixes\" >Some other handy fixes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/stage.wholetomato.com\/blog\/how-to-modernize-with-visual-assist-part-2\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\r\n<h2><span class=\"ez-toc-section\" id=\"1_Override\"><\/span><span style=\"color:#4f81bd;\"><strong>1. <span style=\"color:#4f81bd;\">Override<\/span><\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Let&#8217;s have a look at the following code with a simple class hierarchy:<\/p>\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">using BmpData = std::vector&lt;int&gt;;\n\nclass BaseBrush {\npublic:\nvirtual ~BaseBrush() = default;\n\nvirtual bool Generate() = 0;\n\nvirtual BmpData ApplyFilter(const std::string&amp;) { return BmpData{}; }\n};\n\nclass PBrush : public BaseBrush {\npublic:\nPBrush() = default;\n\nbool Generate() { return true; }\n\nBmpData ApplyFilter(const std::string&amp; filterName) {\nstd::cout &lt;&lt; \"applying filter: \" &lt;&lt; filterName;\nreturn BmpData{};\n}\n\nprivate:\nBmpData m_data;\n};<\/pre>\n\n\n\n<p>When you run VA code inspections, you&#8217;ll immediately see that it complains about not using the override keyword on those two virtual methods.<\/p>\n\n\n<p><img decoding=\"async\" data-attachment-id=\"1874\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/everything-you-need-to-know-about-code-inspections\/image1\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image1.png?fit=752%2C382&amp;ssl=1\" data-orig-size=\"752,382\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image1.png?fit=300%2C152&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image1.png?fit=752%2C382&amp;ssl=1\" class=\"alignnone size-full wp-image-1874\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image1.png?resize=752%2C382&#038;ssl=1\" alt=\"image1\" width=\"752\" height=\"382\" srcset=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image1.png?w=752&amp;ssl=1 752w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image1.png?resize=300%2C152&amp;ssl=1 300w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image1.png?resize=360%2C183&amp;ssl=1 360w\" sizes=\"(max-width: 752px) 100vw, 752px\" data-recalc-dims=\"1\" \/><\/p>\n<p>In short, the override keyword allows us to explicitly specify that a given member function overrides a function from a base class. It&#8217;s a new keyword available since C++11.<\/p>\n<p>As you might already know, you can go to VA Code Inspection Results and apply the fixes automatically. You&#8217;ll get the following code:<\/p>\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">class PBrush : public BaseBrush {\npublic:\nPBrush() = default;\n\nbool Generate() override;\n\nBmpData ApplyFilter(const std::string&amp; filterName) override;\nprivate:\nBmpData m_data;\n};<\/pre>\n\n\n\n<p>What are the benefits of using override?<\/p>\n\n\n\n<p>The most significant advantage is that we can now easily catch mismatches between the virtual base function and its override. When you have even a slight difference in the declaration, then the virtual polymorphism <em>will <\/em><s>might<\/s> not work.&nbsp;<\/p>\n\n\n\n<p>Another critical point is code expressiveness. With override, it&#8217;s effortless to read what the function is supposed to do.<\/p>\n\n\n\n<p>And another one is being more modern as this keyword is also available in other languages like C#, Visual Basic, Java, and Delphi.<\/p>\n\n\n\n<h2 class=\"has-text-color wp-block-heading\" style=\"color:#4f81bd;\"><span class=\"ez-toc-section\" id=\"2_nullptr\"><\/span><strong>2. <\/strong><strong>nullptr<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When I work with legacy code, my Visual Assist Code Inspection Result is often filled with lots of the following items:<\/p>\n\n\n<p><img decoding=\"async\" data-attachment-id=\"1889\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/image3\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image3.png?fit=867%2C411&amp;ssl=1\" data-orig-size=\"867,411\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image3\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image3.png?fit=300%2C142&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image3.png?fit=867%2C411&amp;ssl=1\" class=\"alignnone size-full wp-image-1889\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image3.png?resize=867%2C411&#038;ssl=1\" alt=\"image3\" width=\"867\" height=\"411\" srcset=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image3.png?w=867&amp;ssl=1 867w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image3.png?resize=300%2C142&amp;ssl=1 300w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image3.png?resize=768%2C364&amp;ssl=1 768w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image3.png?resize=360%2C171&amp;ssl=1 360w\" sizes=\"(max-width: 867px) 100vw, 867px\" data-recalc-dims=\"1\" \/><\/p>\n<p><span style=\"font-weight:400;\">This often happens with code like:<\/span><\/p>\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">if (pInput == NULL) {\n    LOG(Error, \"input is null!\")\n    return;\n}<\/pre>\n\n\n\n<p>or<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">pObject-&gt;Generate(\"image.bmp\", NULL, NULL, 32);<\/pre>\n\n\n\n<p>Why does Visual Assist complain about the code? It&#8217;s because NULL is just a define and means only 0, so it doesn&#8217;t mean a null pointer, but it means 0. This is also a problem when you have code like:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">int func(int param);\nint func(float* data);\nif you call:\nfunc(NULL);\n<\/pre>\n\n\n\n<p>You could expect that the function with the pointer should be called, but it&#8217;s not. That&#8217;s why it&#8217;s often a guideline in C or early C++ that suggests not making function overrides with pointers and integral types.<\/p>\n\n\n\n<p>The solution? Just use nullptr from C++11.<\/p>\n\n\n\n<p>nullptr is not 0, but it has a distinct type nullptr_t.<\/p>\n\n\n\n<p>Now when you write:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">func(nullptr);<\/pre>\n\n\n\n<p>you can expect the proper function invocation. The version with func(float* data) will be invoked.<\/p>\n\n\n\n<p>Not to mention that nullptr is a separate keyword in C++, so it stands out from the regular code. Sometimes NULL is displayed in a different color, but sometimes it is not.<\/p>\n\n\n\n<p>Visual Assist makes it super easy to apply the fix, and it&#8217;s a very safe change.<\/p>\n\n\n\n<h2 class=\"has-text-color wp-block-heading\" style=\"color:#4f81bd;\"><span class=\"ez-toc-section\" id=\"3_Convert_enum_to_scoped_enum\"><\/span><strong>3. Convert <\/strong><strong>enum<\/strong><strong> to scoped <\/strong><strong>enum<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Another pattern that is enhanced with Modern C++ is a way you can define enums.<\/p>\n\n\n\n<p>It was popular to write the following code:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">enum ActionType {\n    atNone,\n    atProcess,\n    atRemove,\n    atAdd\n};\n\nActionType action = atNone;\nSince C++11 it's better to you can define this type in the following way:\nenum class ActionType {\n    None,\n    Process,\n    Remove,\n    Add\n};\n\nActionType action = ActionType::None;<\/pre>\n\n\n\n<p>What are the benefits of such transformations?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>They don&#8217;t pollute the global namespace. As you may have noticed, it was often necessary to add various prefixes so the names wouldn&#8217;t clash. That&#8217;s why you see atNone. But in the scoped enum version, we can write None.<\/li><li>You get strong typing, and the compiler will warn when you want to convert into some integral value accidentally.<\/li><li>You can forward scope enums and thus save some file dependencies.<\/li><\/ul>\n\n\n\n<p>What&#8217;s best about Visual Assist is that it has a separate tool to convert unscoped enums to enum classes, all with proper renames and changes in all places where this particular type was used. Right-click on the type and select &#8220;Convert Unscoped Enum to Scoped Enum.&#8221;. This opens a preview window where you can see and select which references will be replaced.<\/p>\n\n\n<p><img decoding=\"async\" data-attachment-id=\"1888\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/image2\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image2.png?fit=1239%2C618&amp;ssl=1\" data-orig-size=\"1239,618\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image2\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image2.png?fit=300%2C150&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image2.png?fit=1024%2C511&amp;ssl=1\" class=\"alignnone size-full wp-image-1888\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image2.png?resize=1140%2C569&#038;ssl=1\" alt=\"image2\" width=\"1140\" height=\"569\" srcset=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image2.png?w=1239&amp;ssl=1 1239w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image2.png?resize=300%2C150&amp;ssl=1 300w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image2.png?resize=1024%2C511&amp;ssl=1 1024w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image2.png?resize=768%2C383&amp;ssl=1 768w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image2.png?resize=360%2C180&amp;ssl=1 360w\" sizes=\"(max-width: 1140px) 100vw, 1140px\" data-recalc-dims=\"1\" \/><\/p>\n<p><span style=\"font-weight:400;\">Read more in <\/span><a href=\"https:\/\/docs.wholetomato.com\/default.asp?W861\"><span style=\"font-weight:400;\">Convert Unscoped Enum to Scoped Enum<\/span><\/a><span style=\"font-weight:400;\"> in the VA documentation.<\/span><\/p>\n\n\n<h2 class=\"has-text-color wp-block-heading\" style=\"color:#4f81bd;\"><span class=\"ez-toc-section\" id=\"4_Use_more_auto\"><\/span><strong>4. Use more <\/strong><strong>auto<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>One of the key characteristics of Modern C++ is shorter and more expressive code. You saw one example where we converted from for loops with long names for iterators into a nice and compact range-based for loops.<\/p>\n\n\n\n<p>What&#8217;s more, we can also apply shorter syntax to regular variables thanks to automatic type deduction. In C++11, we have a &#8220;reused&#8221; keyword auto for that.<\/p>\n\n\n\n<p>Have a look:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">std::vector&lt;int&gt; vec { 1, 2, 3, 4, 5, 6, 7, 8};\nstd::vector&lt;int&gt;::const_iterator cit = vec.cbegin();<\/pre>\n\n\n\n<p>We can now replace it with:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">std::vector&lt;int&gt; vec { 1, 2, 3, 4, 5, 6, 7, 8};\nauto cit = vec.cbegin();<\/pre>\n\n\n\n<p>Previously, template-type deduction worked only for functions, but now it&#8217;s enabled for variables. It&#8217;s similar to the following code:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">template &lt;typename T&gt; func(T cit) {\n    \/\/ use cit...\n}\nstd::vector&lt;int&gt; vec { 1, 2, 3, 4, 5, 6, 7, 8};\nfunc(vec.cbegin()); \/\/ template deduction here!<\/pre>\n\n\n\n<p>Following are some other examples:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">auto counter = 0;   \/\/ deduced int\nauto factor = 42.5; \/\/ deduces double\nauto start = myVector.begin(); \/\/ deduces iterator type\nauto&amp; ref = counter; \/\/ reference to int\nauto ptr = &amp;factor;  \/\/ a pointer to double\nauto myPtr = std::make_unique&lt;int&gt;(42);\nauto lam = [](int x) { return x*x; };<\/pre>\n\n\n<p><span style=\"font-weight:400;\">Have a look at the last line above. Without <\/span><span style=\"font-weight:400;\">auto<\/span><span style=\"font-weight:400;\">, it wouldn&#8217;t be possible to name a type of a lambda expression as it&#8217;s only known to the compiler and generated uniquely.<\/span><\/p>\n<p><span style=\"font-weight:400;\">What do you get by using auto?<\/span><\/p>\n<ul>\n<li style=\"font-weight:400;\"><span style=\"font-weight:400;\">Much shorter code, especially for types with long names<\/span><\/li>\n<li style=\"font-weight:400;\"><span style=\"font-weight:400;\">Auto<\/span><span style=\"font-weight:400;\"> variables must always be initialized, so you cannot write unsafe code in that regard<\/span><\/li>\n<li style=\"font-weight:400;\"><span style=\"font-weight:400;\">Helps with refactoring when you want to change types<\/span><\/li>\n<li style=\"font-weight:400;\"><span style=\"font-weight:400;\">Helps with avoiding unwanted conversions<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight:400;\">As for other features, you&#8217;re also covered by Visual Assist, which can automatically apply <\/span><span style=\"font-weight:400;\">auto<\/span><span style=\"font-weight:400;\">. In many places, you&#8217;ll see the following suggestions:<\/span><\/p>\n<p><img decoding=\"async\" data-attachment-id=\"1891\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/image5\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image5.png?fit=832%2C199&amp;ssl=1\" data-orig-size=\"832,199\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image5\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image5.png?fit=300%2C72&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image5.png?fit=832%2C199&amp;ssl=1\" class=\"alignnone size-full wp-image-1891\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image5.png?resize=832%2C199&#038;ssl=1\" alt=\"image5\" width=\"832\" height=\"199\" srcset=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image5.png?w=832&amp;ssl=1 832w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image5.png?resize=300%2C72&amp;ssl=1 300w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image5.png?resize=768%2C184&amp;ssl=1 768w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image5.png?resize=360%2C86&amp;ssl=1 360w\" sizes=\"(max-width: 832px) 100vw, 832px\" data-recalc-dims=\"1\" \/><\/p>\n<p><span style=\"font-weight:400;\">This often happens in places like<\/span><\/p>\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">SomeLongClassName* pDowncasted = static_cast&lt;SomeLongClassName*&gt;(pBtrToBase); \n\/\/ no need to write SomeLongClassName twice:\nauto pDonwcasted = static_cast&lt;SomeLongClassName*&gt;(pBtrToBase);<\/pre>\n\n\n\n<p>or<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">unsigned int val = static_cast&lt;unsigned int&gt;(some_computation \/ factor);\n\/\/ just use:\nauto val = static_cast&lt;unsigned int&gt;(some_computation \/ factor);<\/pre>\n\n\n\n<p>As you can see, thanks to auto, we get shorter code and, in most cases, more comfortable to read. If you think that auto hides a type name for you, you can hover on it, and the Visual Studio will show you that name. Additionally, things like &#8220;go to definition&#8221; from Visual Assist work regularly.<\/p>\n\n\n\n<h2 class=\"has-text-color wp-block-heading\" style=\"color:#4f81bd;\"><span class=\"ez-toc-section\" id=\"5_Deprecated_functionality\"><\/span><strong>5. Deprecated functionality<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>With C++11, a lot of functionality was marked as deprecated and was removed in C++17. Visual Assist helps with conversion to new types and functions.<\/p>\n\n\n\n<p>For example, it&#8217;s now considered unsafe to use random_shuffle as it internally relied on simple rand(), which is very limited as a random function generator.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">std::vector&lt;int&gt; vec { 1, 2, 3, 4, 5, 6, 7, 8 };\nstd::random_shuffle(vec.begin(), vec.end());<\/pre>\n\n\n\n<p>Visual Assist can replace the above code with the following:<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">std::shuffle(vec.begin(), vec.end(), std::mt19937(std::random_device()()));<\/pre>\n\n\n\n<p>Additionally, you&#8217;ll get suggestions to improve old C-style headers and convert them into C++ style:<\/p>\n\n\n<p><img decoding=\"async\" data-attachment-id=\"1890\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/image4\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image4.png?fit=710%2C231&amp;ssl=1\" data-orig-size=\"710,231\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image4\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image4.png?fit=300%2C98&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image4.png?fit=710%2C231&amp;ssl=1\" class=\"alignnone size-full wp-image-1890\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image4.png?resize=710%2C231&#038;ssl=1\" alt=\"image4\" width=\"710\" height=\"231\" srcset=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image4.png?w=710&amp;ssl=1 710w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image4.png?resize=300%2C98&amp;ssl=1 300w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/image4.png?resize=360%2C117&amp;ssl=1 360w\" sizes=\"(max-width: 710px) 100vw, 710px\" data-recalc-dims=\"1\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Some_other_handy_fixes\"><\/span><span style=\"color:#4f81bd;\"><b>Some other handy fixes<\/b><\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight:400;\">We have covered a few inspections, but there&#8217;s much more! Here are some exciting items that you might want to see:<\/span><\/p>\n<ul>\n<li style=\"font-weight:400;\"><span style=\"font-weight:400;\">Standard algorithm can be replaced by container&#8217;s more efficient implementation: <\/span><a href=\"https:\/\/clang.llvm.org\/extra\/clang-tidy\/checks\/performance-inefficient-algorithm.html\"><span style=\"font-weight:400;\">clang-tidy &#8211; performance-inefficient-algorithm<\/span><\/a><\/li>\n<li style=\"font-weight:400;\"><span style=\"font-weight:400;\">typedef<\/span><span style=\"font-weight:400;\"> can be converted to <\/span><span style=\"font-weight:400;\">using<\/span><span style=\"font-weight:400;\"> declaration: <\/span><a href=\"https:\/\/clang.llvm.org\/extra\/clang-tidy\/checks\/modernize-use-using.html\"><span style=\"font-weight:400;\">clang-tidy &#8211; modernize-use-using<\/span><\/a><\/li>\n<li style=\"font-weight:400;\"><span style=\"font-weight:400;\">Redundant call to <\/span><span style=\"font-weight:400;\">c_str()<\/span><span style=\"font-weight:400;\"> or <\/span><span style=\"font-weight:400;\">data()<\/span><span style=\"font-weight:400;\"> on <\/span><span style=\"font-weight:400;\">string:<\/span> <a href=\"https:\/\/clang.llvm.org\/extra\/clang-tidy\/checks\/readability-redundant-smartptr-get.html\"><span style=\"font-weight:400;\">clang-tidy &#8211; readability-redundant-smartptr-get<\/span><\/a><\/li>\n<li style=\"font-weight:400;\"><span style=\"font-weight:400;\">Optimize call to <\/span><span style=\"font-weight:400;\">std::string::find()<\/span><span style=\"font-weight:400;\"> to use single character literal: <\/span><a href=\"https:\/\/clang.llvm.org\/extra\/clang-tidy\/checks\/performance-faster-string-find.html\"><span style=\"font-weight:400;\">clang-tidy &#8211; performance-faster-string-find<\/span><\/a><\/li>\n<\/ul>\n<p><span style=\"font-weight:400;\">The whole list is available here: <\/span><a href=\"https:\/\/docs.wholetomato.com\/default.asp?W761\"><span style=\"font-weight:400;\">List of Code Inspections<\/span><\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Summary\"><\/span><span style=\"color:#4f81bd;\"><b>Summary<\/b><\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight:400;\">Thanks for reading our small series on Clang Tidy, Code Inspections, and Visual Assist. We covered a lot of items, and I hope you learned something new. The techniques I presented in most cases are very easy to use, especially thanks to VA support, and you can gradually refactor your code into Modern C++.<\/span><\/p>\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.wholetomato.com\/downloads\" target=\"_blank\"><img decoding=\"async\" width=\"600\" height=\"200\" data-attachment-id=\"1811\" data-permalink=\"https:\/\/stage.wholetomato.com\/blog\/007_banner_wholetomato_resize_emiliano_600x200\/\" data-orig-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/01\/007_banner_wholetomato_resize_emiliano_600x200.png?fit=600%2C200&amp;ssl=1\" data-orig-size=\"600,200\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"007_banner_wholetomato_resize_emiliano_600x200\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/01\/007_banner_wholetomato_resize_emiliano_600x200.png?fit=300%2C100&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/01\/007_banner_wholetomato_resize_emiliano_600x200.png?fit=600%2C200&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/01\/007_banner_wholetomato_resize_emiliano_600x200.png?resize=600%2C200&#038;ssl=1\" alt=\"\" class=\"wp-image-1811\" srcset=\"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/01\/007_banner_wholetomato_resize_emiliano_600x200.png?w=600&amp;ssl=1 600w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/01\/007_banner_wholetomato_resize_emiliano_600x200.png?resize=300%2C100&amp;ssl=1 300w, https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/01\/007_banner_wholetomato_resize_emiliano_600x200.png?resize=360%2C120&amp;ssl=1 360w\" sizes=\"(max-width: 600px) 100vw, 600px\" data-recalc-dims=\"1\" \/><\/a><figcaption><a href=\"https:\/\/www.wholetomato.com\/downloads\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.wholetomato.com\/downloads<\/a><\/figcaption><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous article, you read about five popular techniques to improve your projects and apply several Modern C++ patterns. Here&#8217;s a list of five more things! We&#8217;ll go from the override keyword to nullptr,&#8230;<\/p>\n","protected":false},"author":183830964,"featured_media":1943,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[672],"tags":[2426,54971,78684782,12004844,6678],"class_list":["post-1917","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips-and-tricks","tag-c","tag-c11","tag-modern-c","tag-visual-assist","tag-visual-studio"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/stage.wholetomato.com\/blog\/wp-content\/uploads\/2021\/03\/smartmockups_kmyeghw5.jpg?fit=1920%2C1080&ssl=1","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pfhqii-uV","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/1917","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/users\/183830964"}],"replies":[{"embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/comments?post=1917"}],"version-history":[{"count":25,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/1917\/revisions"}],"predecessor-version":[{"id":1947,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/posts\/1917\/revisions\/1947"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/media\/1943"}],"wp:attachment":[{"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/media?parent=1917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/categories?post=1917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stage.wholetomato.com\/blog\/wp-json\/wp\/v2\/tags?post=1917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}