{"id":3184,"date":"2023-08-13T18:10:51","date_gmt":"2023-08-13T12:40:51","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=3184"},"modified":"2023-08-13T18:10:51","modified_gmt":"2023-08-13T12:40:51","slug":"stdis_scoped_enum","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2023\/08\/13\/stdis_scoped_enum\/","title":{"rendered":"std::is_scoped_enum<>"},"content":{"rendered":"<p>The <em>type trait<\/em><em><strong> &#8220;std::is_scoped_enum&lt;T&gt;::value&#8221;<\/strong><\/em> was introduced in <em><strong>C++23<\/strong><\/em> to check whether the type <em><strong>\u201cT\u201d<\/strong><\/em> is a <em><strong>scoped enum<\/strong><\/em> type. Another way to use this is <em><strong>std::is_scoped_enum_v&lt;T&gt;<\/strong><\/em>.<\/p>\n<p>Before getting into this trait in detail, let us briefly recap the differences between <em><strong>unscoped<\/strong><\/em> and <em><strong>scoped<\/strong><\/em> enums.<\/p>\n<h3>Unscoped Enums<\/h3>\n<p><em><strong>Unscoped<\/strong><\/em> enums are the <em><strong>old-style<\/strong><\/em> enums. Look at the following example:<\/p>\n<figure id=\"attachment_3186\" aria-describedby=\"caption-attachment-3186\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/unscoped.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"3186\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/08\/13\/stdis_scoped_enum\/unscoped\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/unscoped.jpg\" data-orig-size=\"1123,412\" 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;1691935814&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=\"Unscoped Enums\" data-image-description=\"&lt;p&gt;Unscoped Enums&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Unscoped Enums&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/unscoped-1024x376.jpg\" class=\"wp-image-3186\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/unscoped.jpg?resize=580%2C213&#038;ssl=1\" alt=\"Unscoped Enums\" width=\"580\" height=\"213\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/unscoped.jpg?resize=300%2C110&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/unscoped.jpg?resize=1024%2C376&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/unscoped.jpg?resize=768%2C282&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/unscoped.jpg?w=1123&amp;ssl=1 1123w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/a><figcaption id=\"caption-attachment-3186\" class=\"wp-caption-text\"><strong>Unscoped Enums<\/strong><\/figcaption><\/figure>\n<p>The <em><strong>enum<\/strong><\/em> keyword is usually followed by a <em><strong>name<\/strong><\/em> (optional) followed by a list of symbols within braces. <em><strong>Line 11<\/strong><\/em> is a special case where the underlying type of the enum elements is explicitly stated. When this is not given, the compiler is free to choose any underlying integral type.<\/p>\n<p>The above example shows that such enums are <em><strong>unsafe<\/strong><\/em> because of implicit conversion to integral type. Also note that the enum elements are visible at the scope where the enums are defined, and there is no need to use the scope resolution operator to access them. This can easily lead to problems later on.<\/p>\n<p>Here is the output from the program:<\/p>\n<figure id=\"attachment_3187\" aria-describedby=\"caption-attachment-3187\" style=\"width: 480px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/example1.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"3187\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/08\/13\/stdis_scoped_enum\/example1-33\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/example1.jpg\" data-orig-size=\"637,127\" 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;1691850548&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\/2023\/08\/example1.jpg\" class=\"wp-image-3187\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/example1.jpg?resize=480%2C96&#038;ssl=1\" alt=\"Program Output\" width=\"480\" height=\"96\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/example1.jpg?resize=300%2C60&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/example1.jpg?w=637&amp;ssl=1 637w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/a><figcaption id=\"caption-attachment-3187\" class=\"wp-caption-text\"><strong>Program Output<\/strong><\/figcaption><\/figure>\n<p>Unscoped enums are not recommended in newer programs.<\/p>\n<h3>Scoped Enums<\/h3>\n<p>Scoped enums were introduced in <em><strong>C++11<\/strong><\/em>. In contrast to unstopped enums, these enums are type safe without implicit conversion to the underlying type. The following example illustrates this:<\/p>\n<figure id=\"attachment_3188\" aria-describedby=\"caption-attachment-3188\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/scoped.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"3188\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/08\/13\/stdis_scoped_enum\/scoped\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/scoped.jpg\" data-orig-size=\"1082,403\" 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;1691935892&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=\"Scoped Enums\" data-image-description=\"&lt;p&gt;Scoped Enums&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Scoped Enums&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/scoped-1024x381.jpg\" class=\"wp-image-3188\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/scoped.jpg?resize=580%2C216&#038;ssl=1\" alt=\"Scoped Enums\" width=\"580\" height=\"216\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/scoped.jpg?resize=300%2C112&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/scoped.jpg?resize=1024%2C381&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/scoped.jpg?resize=768%2C286&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/scoped.jpg?w=1082&amp;ssl=1 1082w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/a><figcaption id=\"caption-attachment-3188\" class=\"wp-caption-text\"><strong>Scoped Enums<\/strong><\/figcaption><\/figure>\n<p>The key difference is the use of the keyword <em><strong>class<\/strong><\/em> or <em><strong>struct<\/strong><\/em> as part of the enum definition. Although either of them can be used with the same effect, the preferred convention is to use <em><strong>class<\/strong><\/em>.<\/p>\n<p>Note that we need to use <em><strong>explicit type casting<\/strong><\/em> to convert the enum elements to the underlying integral type. In addition, we have to use the scope resolution operator to access the members.<\/p>\n<p>If we uncomment <em><strong>lines 39 &#8211; 41<\/strong><\/em>, the program won\u2019t compile!<\/p>\n<h3>std::is_scoped_enum&lt;T&gt;<\/h3>\n<p>Now we return to our type trait <em><strong>is_scoped_enum&lt;T&gt;::value<\/strong><\/em>, where <em><strong>\u201cT\u201d<\/strong><\/em> is a type name. Its abbreviated form is <em><strong>is_scoped_enum_v&lt;T&gt;<\/strong><\/em>. This returns <em><strong>\u201ctrue\u201d<\/strong><\/em> if <em><strong>\u201cT\u201d<\/strong><\/em> happens to be a <em><strong>scoped<\/strong><\/em> enum, else it returns <em><strong>\u201cfalse\u201d<\/strong><\/em>. Here is an example:<\/p>\n<figure id=\"attachment_3190\" aria-describedby=\"caption-attachment-3190\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/is_scoped.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3190\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/08\/13\/stdis_scoped_enum\/is_scoped\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/is_scoped.jpg\" data-orig-size=\"1097,459\" 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;1691947538&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=\"is_scoped_enum_v&lt;T&gt; Example\" data-image-description=\"&lt;p&gt;is_scoped_enum_v&lt;T&gt; Example&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;is_scoped_enum_v&lt;T&gt; Example&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/is_scoped-1024x428.jpg\" class=\"wp-image-3190\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/is_scoped.jpg?resize=580%2C243&#038;ssl=1\" alt=\"is_scoped_enum_v&lt;T&gt; Example\" width=\"580\" height=\"243\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/is_scoped.jpg?resize=300%2C126&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/is_scoped.jpg?resize=1024%2C428&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/is_scoped.jpg?resize=768%2C321&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/is_scoped.jpg?w=1097&amp;ssl=1 1097w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/a><figcaption id=\"caption-attachment-3190\" class=\"wp-caption-text\"><strong>is_scoped_enum_v Example<\/strong><\/figcaption><\/figure>\n<p>The corresponding output is:<\/p>\n<figure id=\"attachment_3191\" aria-describedby=\"caption-attachment-3191\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/example3.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3191\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/08\/13\/stdis_scoped_enum\/example3-25\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/example3.jpg\" data-orig-size=\"656,225\" 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;1691850497&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\/2023\/08\/example3.jpg\" class=\"wp-image-3191\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/example3.jpg?resize=500%2C171&#038;ssl=1\" alt=\"Program Output\" width=\"500\" height=\"171\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/example3.jpg?resize=300%2C103&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/example3.jpg?w=656&amp;ssl=1 656w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-3191\" class=\"wp-caption-text\"><strong>Program Output<\/strong><\/figcaption><\/figure>\n<p>As expected, the trait correctly differentiates between scoped enums and other types.<\/p>\n<p>OK, how do we use this feature in a program? One usage scenario is to take advantage of <em><strong>C++23 \u201cConcepts\u201d<\/strong><\/em> to define constraints on function argument types. The following example shows how to do this:<\/p>\n<figure id=\"attachment_3192\" aria-describedby=\"caption-attachment-3192\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/usage.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3192\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2023\/08\/13\/stdis_scoped_enum\/usage\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/usage.jpg\" data-orig-size=\"1118,483\" 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;1691947612&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=\"Constraining Function Argument\" data-image-description=\"&lt;p&gt;Constraining Function Argument&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Constraining Function Argument&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/usage-1024x442.jpg\" class=\"wp-image-3192\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/usage.jpg?resize=580%2C251&#038;ssl=1\" alt=\"Constraining Function Argument\" width=\"580\" height=\"251\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/usage.jpg?resize=300%2C130&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/usage.jpg?resize=1024%2C442&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/usage.jpg?resize=768%2C332&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/08\/usage.jpg?w=1118&amp;ssl=1 1118w\" sizes=\"(max-width: 580px) 100vw, 580px\" \/><\/a><figcaption id=\"caption-attachment-3192\" class=\"wp-caption-text\"><strong>Constraining Function Argument<\/strong><\/figcaption><\/figure>\n<p>The <em><strong>\u201cfoo()\u201d<\/strong><\/em> function is defined to accept argument of any <em><strong>scoped enum<\/strong><\/em> type by constraining the type. That way, the compiler can easily differentiate between valid and valid argument types, especially with <em><strong>template<\/strong><\/em> functions.<\/p>\n<p>The example <em><strong>C++<\/strong><\/em> program can be downloaded <a href=\"https:\/\/www.rangakrish.com\/downloads\/IsScopedEnum.cpp\" target=\"_blank\" rel=\"noopener\"><em><strong>here<\/strong><\/em><\/a>. I used <em><strong>Visual Studio Professional 2022 Ver 17.6.5<\/strong><\/em> to build this program.<\/p>\n<p>Have a nice weekend!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The type trait &#8220;std::is_scoped_enum&lt;T&gt;::value&#8221; 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&lt;T&gt;. Before getting into this trait in detail, let us briefly recap the differences between unscoped and scoped enums. Unscoped Enums Unscoped enums are the old-style enums. Look at the [&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,235],"class_list":["post-3184","post","type-post","status-publish","format-standard","hentry","category-c","category-programming","tag-c","tag-type-trait"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-Pm","jetpack-related-posts":[{"id":1946,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/03\/28\/stdis_empty\/","url_meta":{"origin":3184,"position":0},"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":1973,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/04\/26\/stdis_base_of\/","url_meta":{"origin":3184,"position":1},"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":3184,"position":2},"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":1960,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/04\/12\/stdcommon_type-type-trait\/","url_meta":{"origin":3184,"position":3},"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":2011,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/06\/06\/stdis_trivial\/","url_meta":{"origin":3184,"position":4},"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":2280,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/01\/17\/c20-nodiscard-attribute\/","url_meta":{"origin":3184,"position":5},"title":"C++20 [[nodiscard]] Attribute","author":"admin","date":"January 17, 2021","format":false,"excerpt":"[[nodiscard]]\u00a0attribute \u201cencourages\u201d the compiler to issue a warning when the return value from a function is ignored. It was introduced in C++ 17 and enhanced in C++ 20 to include a string literal that can be used as an explanation of the warning. Let us look at different cases one\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Case-1: Enumeration","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/01\/Example1-src-300x261.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/01\/Example1-src-300x261.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/01\/Example1-src-300x261.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/3184","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=3184"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/3184\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=3184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=3184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=3184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}