{"id":2540,"date":"2021-09-19T09:39:30","date_gmt":"2021-09-19T04:09:30","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=2540"},"modified":"2021-09-19T09:39:30","modified_gmt":"2021-09-19T04:09:30","slug":"c-20-concepts","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2021\/09\/19\/c-20-concepts\/","title":{"rendered":"C++ 20: Concepts"},"content":{"rendered":"<p><em><strong>Concepts<\/strong><\/em>, introduced in <em><strong>C++20<\/strong><\/em>, are predicates that act as contraints on template parameters. As you would expect, the nice thing is that the constraint checking happens as part of template instantiation at compile time and not at run time!<\/p>\n<p>Since templates can have type as well as non-type parameters, <em><strong>Concepts<\/strong><\/em> can be applied to both these parameter categories.<\/p>\n<p>Let us first look at an example where a <em><strong>Concept<\/strong><\/em> is associated with a type parameter:<\/p>\n<figure id=\"attachment_2541\" aria-describedby=\"caption-attachment-2541\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example1.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"2541\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/09\/19\/c-20-concepts\/example1-23\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example1.jpg\" data-orig-size=\"835,592\" 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;1632034371&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=\"Constraint on Type\" data-image-description=\"&lt;p&gt;Constraint on Type&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Constraint on Type&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example1.jpg\" class=\"wp-image-2541\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example1.jpg?resize=500%2C354&#038;ssl=1\" alt=\"Constraint on Type\" width=\"500\" height=\"354\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example1.jpg?resize=300%2C213&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example1.jpg?resize=768%2C544&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example1.jpg?w=835&amp;ssl=1 835w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2541\" class=\"wp-caption-text\"><strong>Constraint on Type<\/strong><\/figcaption><\/figure>\n<p>In this example, we are defining a <em><strong>Concept<\/strong><\/em> that requires a type to be of <em><strong>&#8220;pointer&#8221;<\/strong><\/em>. This makes use of the standard library predicate <em><strong>is_pointer_v&lt;T&gt;<\/strong><\/em>.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Lines 14 &#8211; 18 define a function <em><strong>&#8220;foo&#8221;<\/strong><\/em> that takes a <em><strong>PointerType<\/strong><\/em> argument. Notice how the template declaration constrains the type argument.<\/p>\n<p>Interestingly, there are 3 other equivalent ways to specify the constraint:<\/p>\n<figure id=\"attachment_2542\" aria-describedby=\"caption-attachment-2542\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Alternative-syntax.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2542\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/09\/19\/c-20-concepts\/alternative-syntax\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Alternative-syntax.jpg\" data-orig-size=\"656,653\" 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;1632039693&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=\"Alternative syntax\" data-image-description=\"&lt;p&gt;Alternative Syntax&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Alternative Syntax&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Alternative-syntax.jpg\" class=\"wp-image-2542\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Alternative-syntax.jpg?resize=500%2C498&#038;ssl=1\" alt=\"Alternative Syntax\" width=\"500\" height=\"498\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Alternative-syntax.jpg?resize=300%2C300&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Alternative-syntax.jpg?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Alternative-syntax.jpg?w=656&amp;ssl=1 656w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2542\" class=\"wp-caption-text\"><strong>Alternative Syntax<\/strong><\/figcaption><\/figure>\n<p>The following code fragment shows how we can call the <em><strong>&#8220;foo&#8221;<\/strong><\/em> function by passing pointers.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<figure id=\"attachment_2543\" aria-describedby=\"caption-attachment-2543\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/main1.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"2543\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/09\/19\/c-20-concepts\/main1\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/main1.jpg\" data-orig-size=\"562,372\" 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;1632039830&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=\"Calling &amp;#8220;foo()&amp;#8221;\" data-image-description=\"&lt;p&gt;Calling &amp;#8220;foo()&amp;#8221;&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Calling &amp;#8220;foo()&amp;#8221;&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/main1.jpg\" class=\"wp-image-2543\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/main1.jpg?resize=500%2C331&#038;ssl=1\" alt=\"Calling &quot;foo()&quot;\" width=\"500\" height=\"331\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/main1.jpg?resize=300%2C199&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/main1.jpg?w=562&amp;ssl=1 562w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2543\" class=\"wp-caption-text\"><strong>Calling &#8220;foo()&#8221;<\/strong><\/figcaption><\/figure>\n<p>Any attempt to pass a non-pointer will trigger compiler error. So if we uncomment line 70, we will get a compiler error like the following:<\/p>\n<figure id=\"attachment_2544\" aria-describedby=\"caption-attachment-2544\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/error1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2544\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/09\/19\/c-20-concepts\/error1\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/error1.jpg\" data-orig-size=\"701,110\" 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;1632034799&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=\"Invalid Argument Type Error\" data-image-description=\"&lt;p&gt;Invalid Argument Type Error&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Invalid Argument Type Error&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/error1.jpg\" class=\"wp-image-2544\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/error1.jpg?resize=500%2C78&#038;ssl=1\" alt=\"Invalid Argument Type Error\" width=\"500\" height=\"78\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/error1.jpg?resize=300%2C47&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/error1.jpg?w=701&amp;ssl=1 701w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2544\" class=\"wp-caption-text\"><strong>Invalid Argument Type Error<\/strong><\/figcaption><\/figure>\n<p>Our next example is about defining a <em><strong>Concept<\/strong><\/em> that applies to a <em><strong>non-type<\/strong><\/em> template argument.<\/p>\n<figure id=\"attachment_2545\" aria-describedby=\"caption-attachment-2545\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2545\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/09\/19\/c-20-concepts\/example2-19\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example2.jpg\" data-orig-size=\"977,434\" 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;1632040626&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=\"Concept Applied to Non-type\" data-image-description=\"&lt;p&gt;Concept Applied to Non-type&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Concept Applied to Non-type&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example2.jpg\" class=\"wp-image-2545\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example2.jpg?resize=550%2C244&#038;ssl=1\" alt=\"Concept Applied to Non-type\" width=\"550\" height=\"244\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example2.jpg?resize=300%2C133&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example2.jpg?resize=768%2C341&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example2.jpg?resize=680%2C300&amp;ssl=1 680w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/Example2.jpg?w=977&amp;ssl=1 977w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-2545\" class=\"wp-caption-text\"><strong>Concept Applied to Non-type<\/strong><\/figcaption><\/figure>\n<p>Here, we are defining a predicate on an integer, constraining it to be between 5 and 10 (both included).<span class=\"Apple-converted-space\">\u00a0 <\/span>Notice the use of <em><strong>nested<\/strong><\/em> <em><strong>&#8220;requires&#8221;<\/strong><\/em>.<\/p>\n<p>Lines 72-73 show how this is used.<\/p>\n<figure id=\"attachment_2546\" aria-describedby=\"caption-attachment-2546\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/main2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2546\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/09\/19\/c-20-concepts\/main2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/main2.jpg\" data-orig-size=\"613,532\" 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;1632039894&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\" data-image-description=\"&lt;p&gt;Example&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Example&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/main2.jpg\" class=\"wp-image-2546\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/main2.jpg?resize=500%2C434&#038;ssl=1\" alt=\"Example\" width=\"500\" height=\"434\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/main2.jpg?resize=300%2C260&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/main2.jpg?w=613&amp;ssl=1 613w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2546\" class=\"wp-caption-text\"><strong>Example<\/strong><\/figcaption><\/figure>\n<p>If we uncomment lines 74 and 75, we will get a compiler error:<\/p>\n<figure id=\"attachment_2547\" aria-describedby=\"caption-attachment-2547\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/error2.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2547\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2021\/09\/19\/c-20-concepts\/error2\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/error2.jpg\" data-orig-size=\"641,169\" 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;1632035121&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=\"Compiler Error\" data-image-description=\"&lt;p&gt;Compiler Error&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Compiler Error&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/error2.jpg\" class=\"wp-image-2547\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/error2.jpg?resize=500%2C132&#038;ssl=1\" alt=\"Compiler Error\" width=\"500\" height=\"132\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/error2.jpg?resize=300%2C79&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/09\/error2.jpg?w=641&amp;ssl=1 641w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2547\" class=\"wp-caption-text\"><strong>Compiler Error<\/strong><\/figcaption><\/figure>\n<p>As I mentioned earlier,\u00a0<em><strong>Concepts<\/strong><\/em> are checked at compile-time, and that is a great thing!<\/p>\n<p><em><strong>Concepts<\/strong><\/em> are a major addition to <em><strong>C++20<\/strong><\/em> and I have just scratched the surface. For a formal reference, please visit this <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/constraints\" target=\"_blank\" rel=\"noopener\"><em><strong>page<\/strong><\/em><\/a>.<\/p>\n<p>You can download the example file <a href=\"http:\/\/www.rangakrish.com\/downloads\/ConceptsExample.cpp\" target=\"_blank\" rel=\"noopener\"><em><strong>here<\/strong><\/em><\/a>. I used <em><strong>Visual Studio Pro 2019 Version 16.11.2<\/strong><\/em> for compiling the example. It is important to select <em><strong>&#8220;ISO C++20 Standard&#8221;<\/strong><\/em> as the <em><strong>&#8220;C++ Language Standard&#8221;<\/strong><\/em> property when building the project.<\/p>\n<p>Have a nice weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Concepts, introduced in C++20, are predicates that act as contraints on template parameters. As you would expect, the nice thing is that the constraint checking happens as part of template instantiation at compile time and not at run time! Since templates can have type as well as non-type parameters, Concepts can be applied to both [&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":[293,294],"class_list":["post-2540","post","type-post","status-publish","format-standard","hentry","category-c","category-programming","tag-c-20","tag-concepts"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-EY","jetpack-related-posts":[{"id":3675,"url":"https:\/\/www.rangakrish.com\/index.php\/2025\/04\/24\/interfaces-without-inheritance-comparing-c-and-common-lisp\/","url_meta":{"origin":2540,"position":0},"title":"Interfaces Without Inheritance: Comparing C++ and Common Lisp","author":"admin","date":"April 24, 2025","format":false,"excerpt":"Clean interface design is a crucial aspect of software engineering since it enables code flexibility, reuse, and maintainability. Developers who prefer an object-oriented approach typically rely on inheritance to define the interface and thus establish type relationships. While this can lead to a good design if approached carefully, detractors of\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Rectangle and Circle Defined","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/04\/cpp2-251x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2804,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/05\/15\/students-assessment-advisor-in-prolog\/","url_meta":{"origin":2540,"position":1},"title":"Students Assessment Advisor in Prolog","author":"admin","date":"May 15, 2022","format":false,"excerpt":"A close relative of mine teaches Maths to school students in different Grades. During a casual chat some time ago, he mentioned that he was trying to adopt an automated approach to selecting assignment problems based on each student's performance so far. Obviously, there are many ways in which this\u2026","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/www.rangakrish.com\/index.php\/category\/programming\/"},"img":{"alt_text":"Concept Dependencies","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/05\/Concept-Dependencies-300x128.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/05\/Concept-Dependencies-300x128.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/05\/Concept-Dependencies-300x128.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2975,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/12\/25\/stdtie\/","url_meta":{"origin":2540,"position":2},"title":"Std::tie","author":"admin","date":"December 25, 2022","format":false,"excerpt":"std::tuple is a widely used abstraction in C++ and has been around since C++11. It is a generalization of std::pair. std::tie is convenient when we want to create a tuple of lvalue references to existing variables. It is a function template commonly used to unpack a tuple into individual objects.\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"std::tie Example","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/12\/Example1-300x142.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/12\/Example1-300x142.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/12\/Example1-300x142.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2668,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/01\/23\/template-mixins-in-d-programming-language\/","url_meta":{"origin":2540,"position":3},"title":"Template Mixins in D Programming Language","author":"admin","date":"January 23, 2022","format":false,"excerpt":"When I heard the name Mixin\u00a0for the first time in the context of Dlang, I imagined it would be something similar to the mixins\u00a0of Common Lisp, but I was completely wrong!\u00a0 Mixins are a very interesting feature of D language. They allow code to be \"injected\" into the source at\u2026","rel":"","context":"In &quot;D Language&quot;","block_context":{"text":"D Language","link":"https:\/\/www.rangakrish.com\/index.php\/category\/d-language\/"},"img":{"alt_text":"Simple Template Mixin","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/01\/Defn-300x98.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2722,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/03\/06\/lazy-parameter-evaluation-in-d-language\/","url_meta":{"origin":2540,"position":4},"title":"Lazy Parameter Evaluation in D Language","author":"admin","date":"March 6, 2022","format":false,"excerpt":"Languages such as C\/C++ and Java follow an\u00a0\"eager\" argument evaluation approach, where function arguments are evaluated before the function is entered. Of course, there are idioms and tricks that one can use to force \"lazy\" evaluation. The primary benefit of \"lazy\" parameter evaluation is that the parameter is evaluated only\u2026","rel":"","context":"In &quot;D Language&quot;","block_context":{"text":"D Language","link":"https:\/\/www.rangakrish.com\/index.php\/category\/d-language\/"},"img":{"alt_text":"Example Program","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/03\/eagercode-237x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2162,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/10\/11\/template-based-text-generation-part-2\/","url_meta":{"origin":2540,"position":5},"title":"Template-based Text Generation &#8211; Part 2","author":"admin","date":"October 11, 2020","format":false,"excerpt":"In my previous article, I showed how \u201ciLangGen\u201d framework facilitates text generation using templates. I talked about the various \u201cpatterns\u201d that can be used in a template. However, in that article, I did not go into the details of the \u201cEmbedded Template\u201d pattern. That is the focus of today\u2019s article.\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Main Template","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/10\/main-template-300x137.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2540","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=2540"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/2540\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=2540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=2540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=2540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}