{"id":2011,"date":"2020-06-06T16:06:21","date_gmt":"2020-06-06T10:36:21","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=2011"},"modified":"2020-06-06T18:34:44","modified_gmt":"2020-06-06T13:04:44","slug":"stdis_trivial","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2020\/06\/06\/stdis_trivial\/","title":{"rendered":"std::is_trivial<>"},"content":{"rendered":"<p>Today let us try to understand the type trait <em><strong>std::is_trivial&lt;T&gt;<\/strong><\/em>. This trait checks if the given type is a <em><strong>trivial<\/strong><\/em> type. For a precise definition of what <em><strong>trivial<\/strong><\/em> means, please visit the official <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/types\/is_trivial\" target=\"_blank\" rel=\"noopener noreferrer\"><em><strong>page<\/strong><\/em><\/a>.<\/p>\n<p>As usual, we will go through three cases:<\/p>\n<p style=\"padding-left: 40px;\">&#8211; Primitive types<\/p>\n<p style=\"padding-left: 40px;\">&#8211; Classes without inheritance<\/p>\n<p style=\"padding-left: 40px;\">&#8211; Classes involving inheritance<\/p>\n<h3>Case-1: Primitive Types<\/h3>\n<p>Take a look at the example below (as in the previous post, I am using the macro <em><strong>CHECK(T)<\/strong><\/em> to save some typing).<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<figure id=\"attachment_2012\" aria-describedby=\"caption-attachment-2012\" style=\"width: 450px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example1.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"2012\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/06\/06\/stdis_trivial\/example1-19\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example1.jpg\" data-orig-size=\"619,683\" 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;1591453596&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=\"Primitive Types\" data-image-description=\"&lt;p&gt;Primitive Types&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Primitive Types&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example1.jpg\" class=\"wp-image-2012\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example1.jpg?resize=450%2C497&#038;ssl=1\" alt=\"Primitive Types\" width=\"450\" height=\"497\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example1.jpg?w=619&amp;ssl=1 619w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example1.jpg?resize=272%2C300&amp;ssl=1 272w\" sizes=\"(max-width: 450px) 100vw, 450px\" \/><\/a><figcaption id=\"caption-attachment-2012\" class=\"wp-caption-text\"><strong>Primitive Types<\/strong><\/figcaption><\/figure>\n<p>The output is:<\/p>\n<figure id=\"attachment_2013\" aria-describedby=\"caption-attachment-2013\" style=\"width: 400px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output1.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2013\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/06\/06\/stdis_trivial\/output1-6\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output1.jpg\" data-orig-size=\"423,180\" 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;1591453421&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=\"Output From The Program\" data-image-description=\"&lt;p&gt;Output From The Program&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Output From The Program&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output1.jpg\" class=\"wp-image-2013\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output1.jpg?resize=400%2C170&#038;ssl=1\" alt=\"Output From The Program\" width=\"400\" height=\"170\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output1.jpg?w=423&amp;ssl=1 423w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output1.jpg?resize=300%2C128&amp;ssl=1 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><figcaption id=\"caption-attachment-2013\" class=\"wp-caption-text\"><strong>Program Output<\/strong><\/figcaption><\/figure>\n<p>For convenience, the expected output is shown commented alongside the code. It is interesting that <em><strong>lvalue<\/strong><\/em> and <em><strong>rvalue references<\/strong><\/em> are not considered trivial, but <em><strong>pointer<\/strong><\/em> type is.<\/p>\n<h3>Case-2: Classes without Inheritance<\/h3>\n<p>Let us look at the more interesting case involving classes. The image below shows different <em><strong>struct\/class\/union<\/strong><\/em> definitions.<\/p>\n<figure id=\"attachment_2014\" aria-describedby=\"caption-attachment-2014\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example2a.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2014\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/06\/06\/stdis_trivial\/example2a\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example2a.jpg\" data-orig-size=\"710,1208\" 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;1591452566&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=\"User-defined Types\" data-image-description=\"&lt;p&gt;User-defined Types&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;User-defined Types&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example2a-602x1024.jpg\" class=\"wp-image-2014\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example2a.jpg?resize=500%2C851&#038;ssl=1\" alt=\"User-defined Types\" width=\"500\" height=\"851\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example2a.jpg?resize=602%2C1024&amp;ssl=1 602w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example2a.jpg?resize=176%2C300&amp;ssl=1 176w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example2a.jpg?w=710&amp;ssl=1 710w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2014\" class=\"wp-caption-text\"><strong>User-defined Types<\/strong><\/figcaption><\/figure>\n<p>Class <em><strong>&#8220;A&#8221;<\/strong><\/em> has some instance variables and a member function. However, it does not have a constructor or destructor.<\/p>\n<p>struct <em><strong>&#8220;B&#8221;<\/strong><\/em> does an inline initialization of a &#8220;const&#8221; field.<\/p>\n<p>struct <em><strong>&#8220;C&#8221;<\/strong><\/em> defines a constructor but no destructor.<\/p>\n<p>struct <em><strong>&#8220;D&#8221;<\/strong><\/em> defines a destructor but no constructor.<\/p>\n<p>struct <em><strong>&#8220;E&#8221;<\/strong><\/em> defines an instance variable of user-defined type <em><strong>&#8220;A&#8221;<\/strong><\/em>.<\/p>\n<p><em><strong>&#8220;EArray&#8221;<\/strong><\/em> is a type that maps to an array of 10 elements of <em><strong>&#8220;E&#8221;<\/strong><\/em> type.<\/p>\n<p>struct <em><strong>&#8220;F&#8221;<\/strong><\/em> declares a <em><strong>deleted<\/strong><\/em> assignment operator.<\/p>\n<p>Finally, <em><strong>&#8220;U&#8221;<\/strong><\/em> is a union of three different types, one of which is a user-defined type <em><strong>&#8220;E&#8221;<\/strong><\/em>.<\/p>\n<p>Here is the code that checks these types:<\/p>\n<figure id=\"attachment_2015\" aria-describedby=\"caption-attachment-2015\" style=\"width: 350px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example2b.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2015\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/06\/06\/stdis_trivial\/example2b-2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example2b.jpg\" data-orig-size=\"465,410\" 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;1591452610&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=\"Example Program\" data-image-description=\"&lt;p&gt;Example Program&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Example Program&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example2b.jpg\" class=\"wp-image-2015\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example2b.jpg?resize=350%2C309&#038;ssl=1\" alt=\"Example Program\" width=\"350\" height=\"309\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example2b.jpg?w=465&amp;ssl=1 465w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example2b.jpg?resize=300%2C265&amp;ssl=1 300w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/a><figcaption id=\"caption-attachment-2015\" class=\"wp-caption-text\"><strong>Example Program<\/strong><\/figcaption><\/figure>\n<p>What is the expected output? Here it is:<\/p>\n<figure id=\"attachment_2016\" aria-describedby=\"caption-attachment-2016\" style=\"width: 249px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2016\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/06\/06\/stdis_trivial\/output2-6\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output2.jpg\" data-orig-size=\"395,206\" 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;1591452174&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=\"Program Output\" data-image-description=\"&lt;p&gt;Program Output&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Program Output&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output2.jpg\" class=\"wp-image-2016\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output2.jpg?resize=249%2C130&#038;ssl=1\" alt=\"Program Output\" width=\"249\" height=\"130\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output2.jpg?w=395&amp;ssl=1 395w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output2.jpg?resize=300%2C156&amp;ssl=1 300w\" sizes=\"(max-width: 249px) 100vw, 249px\" \/><\/a><figcaption id=\"caption-attachment-2016\" class=\"wp-caption-text\"><strong>Program Output<\/strong><\/figcaption><\/figure>\n<h3>Case-3: Classes Involving Inheritance<\/h3>\n<p>Our final example uses a few classes as part of inheritance. Take a look:<\/p>\n<figure id=\"attachment_2017\" aria-describedby=\"caption-attachment-2017\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example3.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2017\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/06\/06\/stdis_trivial\/example3-15\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example3.jpg\" data-orig-size=\"679,1085\" 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;1591452719&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=\"Inheritance Example\" data-image-description=\"&lt;p&gt;Inheritance Example&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Inheritance Example&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example3-641x1024.jpg\" class=\"wp-image-2017\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example3.jpg?resize=500%2C799&#038;ssl=1\" alt=\"Inheritance Example\" width=\"500\" height=\"799\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example3.jpg?resize=641%2C1024&amp;ssl=1 641w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example3.jpg?resize=188%2C300&amp;ssl=1 188w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/example3.jpg?w=679&amp;ssl=1 679w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2017\" class=\"wp-caption-text\"><strong>Inheritance Example<\/strong><\/figcaption><\/figure>\n<p>Here is the output from the program:<\/p>\n<figure id=\"attachment_2018\" aria-describedby=\"caption-attachment-2018\" style=\"width: 251px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output3.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2018\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2020\/06\/06\/stdis_trivial\/output3-6\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output3.jpg\" data-orig-size=\"332,86\" 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;1591452222&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=\"Program Output\" data-image-description=\"&lt;p&gt;Program Output&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Program Output&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output3.jpg\" class=\"wp-image-2018\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output3.jpg?resize=251%2C65&#038;ssl=1\" alt=\"Program Output\" width=\"251\" height=\"65\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output3.jpg?w=332&amp;ssl=1 332w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/06\/output3.jpg?resize=300%2C78&amp;ssl=1 300w\" sizes=\"(max-width: 251px) 100vw, 251px\" \/><\/a><figcaption id=\"caption-attachment-2018\" class=\"wp-caption-text\"><strong>Program Output<\/strong><\/figcaption><\/figure>\n<p>The reason why <em><strong>&#8220;G&#8221;<\/strong><\/em> is not trivial is because it defines a <em><strong>virtual<\/strong><\/em> function. Since <em><strong>&#8220;H&#8221;<\/strong><\/em> derives from a <em><strong>trivial<\/strong><\/em> class <em><strong>&#8220;E&#8221;<\/strong><\/em> and adds nothing by itself, it is also a <em><strong>trivial<\/strong><\/em> type. Class <em><strong>&#8220;C&#8221;<\/strong><\/em> is not <em><strong>trivial<\/strong><\/em> and hence <em><strong>&#8220;I&#8221;<\/strong><\/em> is not <em><strong>trivial<\/strong><\/em> as well.<\/p>\n<p>The above use cases cover the essential properties of<em><strong> is_trivial&lt;T&gt;<\/strong><\/em> trait. I hope you get the picture now.<\/p>\n<p>You can download the source code from <a href=\"http:\/\/www.rangakrish.com\/downloads\/IsTrivial.zip\" target=\"_blank\" rel=\"noopener noreferrer\"><em><strong>here.<\/strong><\/em><\/a><\/p>\n<p>Have a nice weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today let us try to understand the type trait std::is_trivial&lt;T&gt;. 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: &#8211; Primitive types &#8211; Classes without inheritance &#8211; Classes involving inheritance Case-1: Primitive [&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,240,235],"class_list":["post-2011","post","type-post","status-publish","format-standard","hentry","category-c","category-programming","tag-c","tag-is_trivial","tag-type-trait"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-wr","jetpack-related-posts":[{"id":2024,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/06\/21\/stdis_standard_layout\/","url_meta":{"origin":2011,"position":0},"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":1946,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/03\/28\/stdis_empty\/","url_meta":{"origin":2011,"position":1},"title":"std::is_empty","author":"admin","date":"March 28, 2020","format":false,"excerpt":"In the previous post, we looked at the std::is_destructible<T> type trait. Today, let us try to understand another type trait std::is_empty<T>. As per the specification, is_empty<T>::value will return true in the following cases: - The class\/struct has no non-static data member - The class\/struct does not define a virtual function\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Example4: Union and Bit Field","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/03\/Example4-1.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/03\/Example4-1.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/03\/Example4-1.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":2011,"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":1973,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/04\/26\/stdis_base_of\/","url_meta":{"origin":2011,"position":3},"title":"std::is_base_of","author":"admin","date":"April 26, 2020","format":false,"excerpt":"In our on-going series on C++ Type Traits, today's topic is about the trait std::is_base_of<>. For the official description, see this. std::is_base_of<A, B>::value takes two arguments, both classes (or structs), and returns true if A is a base class of B and false otherwise. Trivially, std::<A, A>::value is true. Let\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Output","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/04\/Output.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1928,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/03\/15\/stdis_destructible\/","url_meta":{"origin":2011,"position":4},"title":"std::is_destructible","author":"admin","date":"March 15, 2020","format":false,"excerpt":"In the last article, I explained the deleted destructor in some detail. Today, I would like to talk about a related construct, a type trait called std::is_destructible. Type traits, defined in the header <type_traits>, are a big help when it comes to implementing template metaprogramming. \u00a0See this\u00a0article for a nice\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Private\/Protected Destructor","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/03\/Example7.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/03\/Example7.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/03\/Example7.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1992,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/05\/24\/stdis_convertible\/","url_meta":{"origin":2011,"position":5},"title":"std::is_convertible","author":"admin","date":"May 24, 2020","format":false,"excerpt":"The type trait is_convertible<From, To> checks if an object of type From can be \"implicitly\" converted to an object of type To. The expression is_convertible<From, To>::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\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Support for Implicit Conversion","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case3-1.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case3-1.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/05\/Case3-1.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2011","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=2011"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2011\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=2011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=2011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=2011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}