{"id":1992,"date":"2020-05-24T11:07:40","date_gmt":"2020-05-24T05:37:40","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=1992"},"modified":"2020-05-25T04:57:45","modified_gmt":"2020-05-24T23:27:45","slug":"stdis_convertible","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2020\/05\/24\/stdis_convertible\/","title":{"rendered":"std::is_convertible<>"},"content":{"rendered":"<p>The type trait <em><strong>is_convertible&lt;From, To&gt;<\/strong><\/em> checks if an object of type <em><strong>From<\/strong><\/em> can be <em><strong>&#8220;implicitly&#8221;<\/strong><\/em> converted to an object of type <em><strong>To<\/strong><\/em>. The expression <em><strong>is_convertible&lt;From, To&gt;::value<\/strong><\/em> returns <em><strong>true<\/strong><\/em> if implicit conversion is possible, else it returns <em><strong>false<\/strong><\/em>. For more details, please check out the <a href=\"http:\/\/www.cplusplus.com\/reference\/type_traits\/is_convertible\/\" target=\"_blank\" rel=\"noopener noreferrer\"><em><strong>reference<\/strong><\/em><\/a>.<\/p>\n<p>Let us look at three primary cases.<\/p>\n<h3>Case-1: Pre-defined Types<\/h3>\n<p>Let us start with the simplest case involving pre-defined types. Look at the example code below:<\/p>\n<figure id=\"attachment_1994\" aria-describedby=\"caption-attachment-1994\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case1-2.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"1994\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/05\/24\/stdis_convertible\/case1-3\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case1-2.jpg\" data-orig-size=\"850,871\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1590259048&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=\"Pre-defined Types\" data-image-description=\"&lt;p&gt;Pre-defined Types&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Pre-defined Types&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case1-2.jpg\" class=\"wp-image-1994\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case1-2.jpg?resize=650%2C666&#038;ssl=1\" alt=\"Pre-defined Types\" width=\"650\" height=\"666\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case1-2.jpg?w=850&amp;ssl=1 850w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case1-2.jpg?resize=293%2C300&amp;ssl=1 293w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case1-2.jpg?resize=768%2C787&amp;ssl=1 768w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/a><figcaption id=\"caption-attachment-1994\" class=\"wp-caption-text\"><strong>Pre-defined Types<\/strong><\/figcaption><\/figure>\n<p>The macro <em><strong>&#8220;CHECK&#8221;<\/strong><\/em> expands to code that applies the type trait and prints a meaningful message. This reduces clutter and makes the code more readable.<span class=\"Apple-converted-space\"> For convenience, the expected outcome is also shown commented on each line.<\/span><\/p>\n<p>The printed output is as follows:<\/p>\n<figure id=\"attachment_1995\" aria-describedby=\"caption-attachment-1995\" style=\"width: 471px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output1.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"1995\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/05\/24\/stdis_convertible\/output1-5\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output1.jpg\" data-orig-size=\"471,278\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1590259626&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=\"The Output\" data-image-description=\"&lt;p&gt;The Output&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;The Output&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output1.jpg\" class=\"size-full wp-image-1995\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output1.jpg?resize=471%2C278&#038;ssl=1\" alt=\"The Output\" width=\"471\" height=\"278\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output1.jpg?w=471&amp;ssl=1 471w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output1.jpg?resize=300%2C177&amp;ssl=1 300w\" sizes=\"(max-width: 471px) 100vw, 471px\" \/><\/a><figcaption id=\"caption-attachment-1995\" class=\"wp-caption-text\"><strong>The Output<\/strong><\/figcaption><\/figure>\n<p>I guess there are no surprises here.<\/p>\n<h3>Case-2: Classes Involving Hierarchy<\/h3>\n<p>This is more interesting and challenging compared to the previous case. We have a bunch of classes that form a hierarchy, including multiple inheritance. Here is the example code.<\/p>\n<figure id=\"attachment_1996\" aria-describedby=\"caption-attachment-1996\" style=\"width: 596px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case2-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"1996\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/05\/24\/stdis_convertible\/case2-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case2-1.jpg\" data-orig-size=\"596,591\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1590312109&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=\"Complex Class Hierarchy\" data-image-description=\"&lt;p&gt;Complex Class Hierarchy&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Complex Class Hierarchy&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case2-1.jpg\" class=\"size-full wp-image-1996\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case2-1.jpg?resize=596%2C591&#038;ssl=1\" alt=\"Complex Class Hierarchy\" width=\"596\" height=\"591\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case2-1.jpg?w=596&amp;ssl=1 596w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case2-1.jpg?resize=300%2C297&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case2-1.jpg?resize=150%2C150&amp;ssl=1 150w\" sizes=\"(max-width: 596px) 100vw, 596px\" \/><\/a><figcaption id=\"caption-attachment-1996\" class=\"wp-caption-text\"><strong>Complex Class Hierarchy<\/strong><\/figcaption><\/figure>\n<p>Let us look at the 6 different conversion attempts. Line 26 checks if class <em><strong>A<\/strong><\/em> can be implicitly converted to class <em><strong>F<\/strong><\/em>. Since <em><strong>A<\/strong><\/em> and <em><strong>F<\/strong><\/em> are unrelated classes, <em><strong>A<\/strong><\/em> cannot be converted to <em><strong>F<\/strong><\/em> (nor vice versa). In line 27, we check if <em><strong>B<\/strong><\/em> can be converted to <em><strong>A<\/strong><\/em>. This is fine because <em><strong>A<\/strong><\/em> is the unambiguous public base class of <em><strong>A<\/strong><\/em>. Line 28 fails because there is no implicit conversion from a base class to its derived class.<\/p>\n<p>What about line 29? <em><strong>A<\/strong><\/em> is the base class of <em><strong>C<\/strong><\/em>, but since the derivation is private, the conversion fails when attempted from <em><strong>&#8220;main&#8221;<\/strong><\/em> (doesn&#8217;t have any special privilege). Line 30 tries to convert the derived type <em><strong>E<\/strong><\/em> to its public base class <em><strong>A<\/strong><\/em>, but this too fails because the conversion is ambiguous (<em><strong>A<\/strong><\/em> is included twice along two different paths). In contrast, line 31 is fine because there is only a single shared instance of <em><strong>A<\/strong><\/em> in <em><strong>H<\/strong><\/em> (due to virtual derivation via all paths). Here is the actual output:<\/p>\n<figure id=\"attachment_1997\" aria-describedby=\"caption-attachment-1997\" style=\"width: 452px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1997\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/05\/24\/stdis_convertible\/output2-5\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output2.jpg\" data-orig-size=\"452,161\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1590311976&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=\"The Output\" data-image-description=\"&lt;p&gt;The Output&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;The Output&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output2.jpg\" class=\"size-full wp-image-1997\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output2.jpg?resize=452%2C161&#038;ssl=1\" alt=\"The Output\" width=\"452\" height=\"161\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output2.jpg?w=452&amp;ssl=1 452w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output2.jpg?resize=300%2C107&amp;ssl=1 300w\" sizes=\"(max-width: 452px) 100vw, 452px\" \/><\/a><figcaption id=\"caption-attachment-1997\" class=\"wp-caption-text\"><strong>The Output<\/strong><\/figcaption><\/figure>\n<h3>Case-3: Explicit Support for Conversion<\/h3>\n<p>In this example, we have three classes. See the code below.<\/p>\n<figure id=\"attachment_1998\" aria-describedby=\"caption-attachment-1998\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case3-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1998\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/05\/24\/stdis_convertible\/case3-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case3-1.jpg\" data-orig-size=\"683,432\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1590258998&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=\"Support for Implicit Conversion\" data-image-description=\"&lt;p&gt;Support for Implicit Conversion&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Support for Implicit Conversion&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case3-1.jpg\" class=\"wp-image-1998\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case3-1.jpg?resize=650%2C411&#038;ssl=1\" alt=\"Support for Implicit Conversion\" width=\"650\" height=\"411\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case3-1.jpg?w=683&amp;ssl=1 683w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case3-1.jpg?resize=300%2C190&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case3-1.jpg?resize=140%2C90&amp;ssl=1 140w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/a><figcaption id=\"caption-attachment-1998\" class=\"wp-caption-text\"><strong>Support for Implicit Conversion<\/strong><\/figcaption><\/figure>\n<p>Class<em><strong> B<\/strong><\/em> defines a constructor that takes an <em><strong>A<\/strong><\/em> object as argument. Since this constructor is not declared <em><strong>&#8220;explicit&#8221;<\/strong><\/em>, it acts as an implicit conversion mechanism from <em><strong>A<\/strong><\/em> to <em><strong>B<\/strong><\/em>. That is why line 24 succeeds.<\/p>\n<p>Line 25 fails because <em><strong>C<\/strong><\/em> (unlike <em><strong>B<\/strong><\/em>) does not have an implicit constructor taking <em><strong>A<\/strong><\/em> argument.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>If you look at class <em><strong>C<\/strong><\/em>, you will notice a conversion operator that converts a <em><strong>C<\/strong><\/em> object to an <em><strong>A<\/strong><\/em> object, and hence supports implicit conversion from <em><strong>C<\/strong><\/em> to <em><strong>A<\/strong><\/em>. This is the reason why line 26 works. See the corresponding output:<\/p>\n<figure id=\"attachment_1999\" aria-describedby=\"caption-attachment-1999\" style=\"width: 406px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output3.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1999\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/05\/24\/stdis_convertible\/output3-5\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output3.jpg\" data-orig-size=\"406,88\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Admin&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1590259799&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=\"The Output\" data-image-description=\"&lt;p&gt;The Output&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;The Output&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output3.jpg\" class=\"size-full wp-image-1999\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output3.jpg?resize=406%2C88&#038;ssl=1\" alt=\"The Output\" width=\"406\" height=\"88\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output3.jpg?w=406&amp;ssl=1 406w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output3.jpg?resize=300%2C65&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Output3.jpg?resize=400%2C88&amp;ssl=1 400w\" sizes=\"(max-width: 406px) 100vw, 406px\" \/><\/a><figcaption id=\"caption-attachment-1999\" class=\"wp-caption-text\"><strong>The Output<\/strong><\/figcaption><\/figure>\n<p>The above 3 cases pretty much cover the different scenarios where the type trait <em><strong>is_convertible&lt;From, To&gt;<\/strong><\/em> operates. Hope you now have a better understanding of its usage.<\/p>\n<p>You can download the examples from <a href=\"http:\/\/www.rangakrish.com\/downloads\/IsConvertible.zip\" target=\"_blank\" rel=\"noopener noreferrer\"><em><strong>here<\/strong><\/em><\/a>.<\/p>\n<p>Have a nice wekeend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The type trait is_convertible&lt;From, To&gt; checks if an object of type From can be &#8220;implicitly&#8221; converted to an object of type To. The expression is_convertible&lt;From, To&gt;::value returns true if implicit conversion is possible, else it returns false. For more details, please check out the reference. Let us look at three primary cases. Case-1: Pre-defined Types [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[49,17],"tags":[67,239,235],"class_list":["post-1992","post","type-post","status-publish","format-standard","hentry","category-c","category-programming","tag-c","tag-is_convertible","tag-type-trait"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-w8","jetpack-related-posts":[{"id":2011,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/06\/06\/stdis_trivial\/","url_meta":{"origin":1992,"position":0},"title":"std::is_trivial","author":"admin","date":"June 6, 2020","format":false,"excerpt":"Today let us try to understand the type trait std::is_trivial<T>. This trait checks if the given type is a trivial type. For a precise definition of what trivial means, please visit the official page. As usual, we will go through three cases: - Primitive types - Classes without inheritance -\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Program Output","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output2.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3184,"url":"https:\/\/www.rangakrish.com\/index.php\/2023\/08\/13\/stdis_scoped_enum\/","url_meta":{"origin":1992,"position":1},"title":"std::is_scoped_enum","author":"admin","date":"August 13, 2023","format":false,"excerpt":"The type trait \"std::is_scoped_enum<T>::value\" was introduced in C++23 to check whether the type \u201cT\u201d is a scoped enum type. Another way to use this is std::is_scoped_enum_v<T>. Before getting into this trait in detail, let us briefly recap the differences between unscoped and scoped enums. Unscoped Enums Unscoped enums are the\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Unscoped Enums","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/unscoped-300x110.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/unscoped-300x110.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/unscoped-300x110.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1960,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/04\/12\/stdcommon_type-type-trait\/","url_meta":{"origin":1992,"position":2},"title":"std::common_type Type Trait","author":"admin","date":"April 12, 2020","format":false,"excerpt":"In today's post, I would like to go over the type trait std::common_type<>. This trait was introduced in C++11. As per the specification, std::common_type<T1, T2, ...Tn>::type refers to a type Tx in the given list, which the rest of the types in the list can be implicitly converted to. This\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Program Output","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/04\/Fig5.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2024,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/06\/21\/stdis_standard_layout\/","url_meta":{"origin":1992,"position":3},"title":"std::is_standard_layout","author":"admin","date":"June 21, 2020","format":false,"excerpt":"In our last post, we learnt about the type trait std::is_trivial<T>. Today, let us go through another type trait that is quite similar. The expression\u00a0is_standard_layout<T>::value returns true if the layout of objects of type T is compiler independent, and hence is of standard format. Else, it returns false. This is\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"The Difference","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/Example4.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/Example4.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/Example4.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/Example4.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":666,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/10\/21\/c17-initalization-in-selection-statements\/","url_meta":{"origin":1992,"position":4},"title":"C++17: Initialization in Selection Statements","author":"admin","date":"October 21, 2017","format":false,"excerpt":"C++17 enhances if and switch statements with the ability to define\u00a0 variables whose life-time is limited to the corresponding scope. This is in keeping with the general guideline that variables should have a tight scope, i.e.,\u00a0 should be defined as close to the point of use as possible and should\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Sample Class","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/10\/classdefn.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1981,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/05\/09\/dynamic_cast-vs-stdis_base_of\/","url_meta":{"origin":1992,"position":5},"title":"dynamic_cast vs. std::is_base_of","author":"admin","date":"May 9, 2020","format":false,"excerpt":"In the last article, we looked at the std:is_base_of<T1, T2> type trait. One question that a reader asked since that article appeared is \"How does is_base_of<> differ from the dynamic_cast<> operator?\" Good question! In today's post let me try to address the key differences between the two. I am not\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Case-4: Complex Hierarchy","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case4.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case4.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case4.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/1992","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=1992"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/1992\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=1992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=1992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=1992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}