{"id":4299,"date":"2026-05-14T14:14:52","date_gmt":"2026-05-14T08:44:52","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=4299"},"modified":"2026-05-14T14:14:52","modified_gmt":"2026-05-14T08:44:52","slug":"c23-slicing-with-stdviewschunk","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2026\/05\/14\/c23-slicing-with-stdviewschunk\/","title":{"rendered":"C++23: Slicing with std::views::chunk"},"content":{"rendered":"<p>One of the common use cases in programming involves extracting fixed size chunks from a given sequence and operating on them. Not a big deal at all. As a <em><strong>C++<\/strong> <\/em>developer, I have coded this quite often and have wished that the language had a built-in function for this. Fortunately, <em><strong>C++23<\/strong><\/em> gives us <em><strong>std::views::chunk<\/strong><\/em> to simplify and standardize this use case.<\/p>\n<p>The following example shows how this is done.<\/p>\n<figure id=\"attachment_4300\" aria-describedby=\"caption-attachment-4300\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example1.png?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"4300\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/05\/14\/c23-slicing-with-stdviewschunk\/example1-35\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example1.png\" data-orig-size=\"1264,1090\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Using the chunk function\" data-image-description=\"&lt;p&gt;Using the chunk function&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Using the chunk function&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example1-1024x883.png\" class=\"wp-image-4300\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example1.png?resize=550%2C474&#038;ssl=1\" alt=\"Using the chunk function\" width=\"550\" height=\"474\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example1.png?resize=300%2C259&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example1.png?resize=1024%2C883&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example1.png?w=1264&amp;ssl=1 1264w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-4300\" class=\"wp-caption-text\"><strong>Using the chunk function<\/strong><\/figcaption><\/figure>\n<p>In the above, we extract 3 elements at a time from the given vector and print them. Next, we chunk in terms of 4 elements at a time. Treating this collection as an array, we extract and print the elements at index 1.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<p>Here is the output.<\/p>\n<figure id=\"attachment_4301\" aria-describedby=\"caption-attachment-4301\" style=\"width: 140px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/output1.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"4301\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/05\/14\/c23-slicing-with-stdviewschunk\/output1-21\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/output1.png\" data-orig-size=\"186,174\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"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\/2026\/05\/output1.png\" class=\"wp-image-4301\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/output1.png?resize=140%2C131&#038;ssl=1\" alt=\"Program output\" width=\"140\" height=\"131\" \/><\/a><figcaption id=\"caption-attachment-4301\" class=\"wp-caption-text\"><strong>Program output<\/strong><\/figcaption><\/figure>\n<p>It is important to understand that <em><strong>std::views::chunk<\/strong><\/em> is a <em><strong>\u201clazy adaptor\u201d<\/strong><\/em>; no unnecessary allocation or copying is done until we evaluate the underlying range. This has a significant impact on efficiency.<\/p>\n<p>In the following example, we generate an infinite sequence of integers and take only the first three chunks, where each chunk has 4 elements.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<figure id=\"attachment_4302\" aria-describedby=\"caption-attachment-4302\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example2.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"4302\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/05\/14\/c23-slicing-with-stdviewschunk\/example2-30\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example2.png\" data-orig-size=\"1236,632\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Working with infinite sequence\" data-image-description=\"&lt;p&gt;Working with infinite sequence&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Working with infinite sequence&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example2-1024x524.png\" class=\"wp-image-4302\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example2.png?resize=550%2C281&#038;ssl=1\" alt=\"Working with infinite sequence\" width=\"550\" height=\"281\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example2.png?resize=300%2C153&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example2.png?resize=1024%2C524&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example2.png?w=1236&amp;ssl=1 1236w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-4302\" class=\"wp-caption-text\"><strong>Working with infinite sequence<\/strong><\/figcaption><\/figure>\n<p>Here is the program output:<\/p>\n<figure id=\"attachment_4303\" aria-describedby=\"caption-attachment-4303\" style=\"width: 162px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/output2.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4303\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/05\/14\/c23-slicing-with-stdviewschunk\/output2-24\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/output2.png\" data-orig-size=\"182,74\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"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\/2026\/05\/output2.png\" class=\"wp-image-4303\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/output2.png?resize=162%2C66&#038;ssl=1\" alt=\"The output\" width=\"162\" height=\"66\" \/><\/a><figcaption id=\"caption-attachment-4303\" class=\"wp-caption-text\"><strong>The output<\/strong><\/figcaption><\/figure>\n<p>The next example uses another useful range adaptor &#8211; <em><strong>\u201cstride\u201d<\/strong><\/em>. This was also introduced in <em><strong>C++23<\/strong><\/em> and it produces a view of every <em><strong>\u201cNth\u201d<\/strong><\/em> element of an underlying range.<span class=\"Apple-converted-space\">\u00a0<\/span><\/p>\n<figure id=\"attachment_4304\" aria-describedby=\"caption-attachment-4304\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example3.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4304\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/05\/14\/c23-slicing-with-stdviewschunk\/example3-27\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example3.png\" data-orig-size=\"974,1020\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Combining &amp;#8220;stride&amp;#8221; and &amp;#8220;chunk&amp;#8221;\" data-image-description=\"&lt;p&gt;Combining &amp;#8220;stride&amp;#8221; and &amp;#8220;chunk&amp;#8221;&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Combining &amp;#8220;stride&amp;#8221; and &amp;#8220;chunk&amp;#8221;&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example3.png\" class=\"wp-image-4304\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example3.png?resize=500%2C524&#038;ssl=1\" alt=\"Combining &quot;stride&quot; and &quot;chunk&quot;\" width=\"500\" height=\"524\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example3.png?resize=286%2C300&amp;ssl=1 286w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example3.png?w=974&amp;ssl=1 974w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-4304\" class=\"wp-caption-text\"><em><strong>Combining &#8220;stride&#8221; and &#8220;chunk&#8221;<\/strong><\/em><\/figcaption><\/figure>\n<p>Notice how we are able to cleanly use the <em><strong>\u201cpipe\u201d<\/strong><\/em> operator for composing different functions &#8211; another elegant testimony for the evolution of <em><strong>C++<\/strong><\/em> from its earlier days1<\/p>\n<p>Here is the output for this example:<\/p>\n<figure id=\"attachment_4305\" aria-describedby=\"caption-attachment-4305\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/output3.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4305\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/05\/14\/c23-slicing-with-stdviewschunk\/output3-15\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/output3.png\" data-orig-size=\"680,36\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"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\/2026\/05\/output3.png\" class=\"wp-image-4305\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/output3.png?resize=500%2C26&#038;ssl=1\" alt=\"Program Output\" width=\"500\" height=\"26\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/output3.png?resize=300%2C16&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/output3.png?w=680&amp;ssl=1 680w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-4305\" class=\"wp-caption-text\"><strong>Program Output<\/strong><\/figcaption><\/figure>\n<p>As the above examples demonstrate, <em><strong>\u201cchunk\u201d<\/strong><\/em> is a simple but useful function in the <em><strong>C++23<\/strong><\/em> standard library.<\/p>\n<p>I used <a href=\"https:\/\/compiler-explorer.com\/z\/7cbb86ja8\" target=\"_blank\" rel=\"noopener\"><em><strong>compiler explorer<\/strong><\/em><\/a> for this experiment.<\/p>\n<p>Have a great day!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the common use cases in programming involves extracting fixed size chunks from a given sequence and operating on them. Not a big deal at all. As a C++ developer, I have coded this quite often and have wished that the language had a built-in function for this. Fortunately, C++23 gives us std::views::chunk to [&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_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},"jetpack_post_was_ever_published":false},"categories":[49,17],"tags":[361,458,459],"class_list":["post-4299","post","type-post","status-publish","format-standard","hentry","category-c","category-programming","tag-c23","tag-chunk","tag-stride"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-17l","jetpack-related-posts":[{"id":1386,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/01\/13\/chunking-in-opennlp\/","url_meta":{"origin":4299,"position":0},"title":"Chunking in OpenNLP","author":"admin","date":"January 13, 2019","format":false,"excerpt":"In my previous post, I showed how to parse sentences using OpenNLP. Another useful feature supported by OpenNLP is \"chunking\u201d. That is the subject of today\u2019s article. Chunking stands between part-of-speech tagging and full parse in terms of the information it captures. POS tagging assigns part of speech to individual\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Printing Chunked Tags with Probability","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Example3-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Example3-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/01\/Example3-1.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1817,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/12\/08\/using-definite-clause-grammars-dcg-for-information-extraction\/","url_meta":{"origin":4299,"position":1},"title":"Using Definite Clause Grammars (DCG) for Information Extraction","author":"admin","date":"December 8, 2019","format":false,"excerpt":"In the previous article, I showed how we can use ATNs for extracting key information from natural language text. I also pointed out in that article that Definite Clause Grammars (DCG) are a more compact formalism for doing this. That will be the focus of today's article. For a nice\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Processing the Text","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/12\/Processing-file-code.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/12\/Processing-file-code.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/12\/Processing-file-code.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3184,"url":"https:\/\/www.rangakrish.com\/index.php\/2023\/08\/13\/stdis_scoped_enum\/","url_meta":{"origin":4299,"position":2},"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":2876,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/07\/27\/understanding-stdspan\/","url_meta":{"origin":4299,"position":3},"title":"Understanding std::span","author":"admin","date":"July 27, 2022","format":false,"excerpt":"Introduced in C++20, std::span\u00a0is a light-weight abstraction that provides a convenient view\u00a0into a collection of contiguous elements. Note that it is not enough for the elements to be logically contiguous, but they must be contiguous in memory too. Thus, span will work with C-style arrays, C++ vectors and arrays. It\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Example-1: span","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/07\/code1-285x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":683,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/11\/05\/c17-stdvariant\/","url_meta":{"origin":4299,"position":4},"title":"C++17: std::variant","author":"admin","date":"November 5, 2017","format":false,"excerpt":"C++17 introduces a new type-safe union in the form of std::variant. At any time, it can store a single value from one of many types. We need to include <variant>\u00a0to use this feature. Let us look at a simple example to get started: First, we define a variant object v1\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Example1","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/11\/Example1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/11\/Example1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/11\/Example1.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2889,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/08\/09\/stdarray-vs-stdvector\/","url_meta":{"origin":4299,"position":5},"title":"std::array vs. std::vector","author":"admin","date":"August 9, 2022","format":false,"excerpt":"One of the common questions when starting to study the container abstractions in C++20 is \"Should I use std::array\u00a0or std::vector?\". The correct answer is \"use what is best suited for the current situation\". That is not good enough, obviously. In this short article, I will try to answer this question\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"std::array Example","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/08\/code1-300x150.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/08\/code1-300x150.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2022\/08\/code1-300x150.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/4299","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=4299"}],"version-history":[{"count":2,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/4299\/revisions"}],"predecessor-version":[{"id":4307,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/4299\/revisions\/4307"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=4299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=4299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=4299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}