{"id":4403,"date":"2026-11-13T14:25:22","date_gmt":"2026-11-13T08:55:22","guid":{"rendered":"https:\/\/www.rangakrish.com\/?p=4403"},"modified":"2026-11-13T14:25:30","modified_gmt":"2026-11-13T08:55:30","slug":"what-is-stdviewszip-in-c","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2026\/11\/13\/what-is-stdviewszip-in-c\/","title":{"rendered":"What is std::views::zip in C++?"},"content":{"rendered":"<p><em><strong>std::views::zip<\/strong><\/em> was introduced in the <em><strong>&lt;ranges&gt;<\/strong><\/em> library as part of <em><strong>C++23<\/strong><\/em>. This is quite convenient when we want to iterate over two or more ranges in lockstep, taking one element from each at every step. It is a superior alternative to the conventional index loop.<\/p>\n<p>The following example shows the typical usage:<\/p>\n<figure id=\"attachment_4404\" aria-describedby=\"caption-attachment-4404\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code1-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"4404\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/11\/13\/what-is-stdviewszip-in-c\/code1-20\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code1-1.jpg\" data-orig-size=\"1053,460\" data-comments-opened=\"1\" data-image-meta=\"{&quot;credit&quot;:&quot;Admin&quot;,&quot;created_timestamp&quot;:&quot;1794491695&quot;}\" data-image-title=\"std::views::zip\" data-image-description=\"&lt;p&gt;std::views::zip&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;std::views::zip&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code1-1-1024x447.jpg\" class=\"wp-image-4404\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code1-1.jpg?resize=600%2C262&#038;ssl=1\" alt=\"std::views::zip\" width=\"600\" height=\"262\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code1-1.jpg?resize=300%2C131&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code1-1.jpg?resize=1024%2C447&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code1-1.jpg?w=1053&amp;ssl=1 1053w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-4404\" class=\"wp-caption-text\"><strong>std::views::zip<\/strong><\/figcaption><\/figure>\n<p>The code above uses two vectors of different types, and the <em><strong>for<\/strong><\/em> loop uses <em><strong>zip<\/strong><\/em> to iterate over the different pairs. <em><strong>Zip<\/strong><\/em> takes any number of ranges (including zero) and returns <em><strong>std::views::zip_view<\/strong><\/em>. Each element of that view is a <em><strong>std::tuple<\/strong><\/em> containing elements at the corresponding position in each input range.<\/p>\n<p>Here is the output &#8211; no surprises:<\/p>\n<figure id=\"attachment_4405\" aria-describedby=\"caption-attachment-4405\" style=\"width: 450px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output1-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"4405\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/11\/13\/what-is-stdviewszip-in-c\/output1-24\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output1-1.jpg\" data-orig-size=\"619,183\" data-comments-opened=\"1\" data-image-meta=\"{&quot;credit&quot;:&quot;Admin&quot;,&quot;created_timestamp&quot;:&quot;1794491882&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\/11\/output1-1.jpg\" class=\"wp-image-4405\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output1-1.jpg?resize=450%2C133&#038;ssl=1\" alt=\"The output\" width=\"450\" height=\"133\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output1-1.jpg?resize=300%2C89&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output1-1.jpg?w=619&amp;ssl=1 619w\" sizes=\"(max-width: 450px) 100vw, 450px\" \/><\/a><figcaption id=\"caption-attachment-4405\" class=\"wp-caption-text\"><strong>The output<\/strong><\/figcaption><\/figure>\n<p>One nice thing to note is that the input elements passed need not all have the same size. <em><strong>Zip<\/strong><\/em> handles this correctly by stopping when any input ends. Naturally, an empty input makes the result empty.<\/p>\n<p>The number of inputs determines the number of tuple components. The zero argument call returns an empty view of <em><strong>std::tuple&lt;&gt;<\/strong><\/em>.<\/p>\n<p>Look at this example:<\/p>\n<figure id=\"attachment_4406\" aria-describedby=\"caption-attachment-4406\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code2-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"4406\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/11\/13\/what-is-stdviewszip-in-c\/code2-22\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code2-1.jpg\" data-orig-size=\"911,255\" data-comments-opened=\"1\" data-image-meta=\"{&quot;credit&quot;:&quot;Admin&quot;,&quot;created_timestamp&quot;:&quot;1794491921&quot;}\" data-image-title=\"Different input sizes\" data-image-description=\"&lt;p&gt;Different input sizes&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Different input sizes&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code2-1.jpg\" class=\"wp-image-4406\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code2-1.jpg?resize=600%2C168&#038;ssl=1\" alt=\"Different input sizes\" width=\"600\" height=\"168\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code2-1.jpg?resize=300%2C84&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code2-1.jpg?w=911&amp;ssl=1 911w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-4406\" class=\"wp-caption-text\"><strong>Different input sizes<\/strong><\/figcaption><\/figure>\n<p>Here each collection has a different size &#8211; minimum of 3 and maximum of 5. The result will therefore have only 3 tuples (with 3 elements each). Check the output:<\/p>\n<figure id=\"attachment_4407\" aria-describedby=\"caption-attachment-4407\" style=\"width: 400px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output2-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4407\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/11\/13\/what-is-stdviewszip-in-c\/output2-26\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output2-1.jpg\" data-orig-size=\"605,157\" data-comments-opened=\"1\" data-image-meta=\"{&quot;credit&quot;:&quot;Admin&quot;,&quot;created_timestamp&quot;:&quot;1794491987&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\/11\/output2-1.jpg\" class=\"wp-image-4407\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output2-1.jpg?resize=400%2C104&#038;ssl=1\" alt=\"Program output\" width=\"400\" height=\"104\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output2-1.jpg?resize=300%2C78&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output2-1.jpg?w=605&amp;ssl=1 605w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><figcaption id=\"caption-attachment-4407\" class=\"wp-caption-text\"><strong>Program output<\/strong><\/figcaption><\/figure>\n<p>It is important to keep in mind that the <em><strong>zip_view<\/strong><\/em> tuples hold <span style=\"text-decoration: underline;\">references<\/span> to the original elements. This can cause surprise if we inadvertently mutate them. This is shown in the following example:<\/p>\n<figure id=\"attachment_4408\" aria-describedby=\"caption-attachment-4408\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code3-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4408\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/11\/13\/what-is-stdviewszip-in-c\/code3-14\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code3-1.jpg\" data-orig-size=\"1235,741\" data-comments-opened=\"1\" data-image-meta=\"{&quot;credit&quot;:&quot;Admin&quot;,&quot;created_timestamp&quot;:&quot;1794492071&quot;}\" data-image-title=\"Holding references\" data-image-description=\"&lt;p&gt;Holding references&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Holding references&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code3-1-1024x614.jpg\" class=\"wp-image-4408\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code3-1.jpg?resize=600%2C360&#038;ssl=1\" alt=\"Holding references\" width=\"600\" height=\"360\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code3-1.jpg?resize=300%2C180&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code3-1.jpg?resize=1024%2C614&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code3-1.jpg?w=1235&amp;ssl=1 1235w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-4408\" class=\"wp-caption-text\"><strong>Holding references<\/strong><\/figcaption><\/figure>\n<p>Line 39, which checks if the values are indeed references, returns <em><strong>true<\/strong><\/em> to confirm this. Here is the output:<\/p>\n<figure id=\"attachment_4409\" aria-describedby=\"caption-attachment-4409\" style=\"width: 400px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output3-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4409\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/11\/13\/what-is-stdviewszip-in-c\/output3-17\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output3-1.jpg\" data-orig-size=\"621,300\" data-comments-opened=\"1\" data-image-meta=\"{&quot;credit&quot;:&quot;Admin&quot;,&quot;created_timestamp&quot;:&quot;1794492150&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\/11\/output3-1.jpg\" class=\"wp-image-4409\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output3-1.jpg?resize=400%2C193&#038;ssl=1\" alt=\"The output\" width=\"400\" height=\"193\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output3-1.jpg?resize=300%2C145&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output3-1.jpg?w=621&amp;ssl=1 621w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><figcaption id=\"caption-attachment-4409\" class=\"wp-caption-text\"><strong>The output<\/strong><\/figcaption><\/figure>\n<p><em><strong>C++23<\/strong><\/em> also introduced <em><strong>std::views::zip_transform<\/strong><\/em>. It passes the corresponding elements from <em><strong>std::views::zip<\/strong><\/em> as separate arguments to a callable and yields the callable\u2019s result. Take a look at this:<\/p>\n<figure id=\"attachment_4410\" aria-describedby=\"caption-attachment-4410\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code4-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4410\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/11\/13\/what-is-stdviewszip-in-c\/code4-7\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code4-1.jpg\" data-orig-size=\"1115,517\" data-comments-opened=\"1\" data-image-meta=\"{&quot;credit&quot;:&quot;Admin&quot;,&quot;created_timestamp&quot;:&quot;1794492302&quot;}\" data-image-title=\"The zip_transform function\" data-image-description=\"&lt;p&gt;The zip_transform function&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;The zip_transform function&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code4-1-1024x475.jpg\" class=\"wp-image-4410\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code4-1.jpg?resize=600%2C278&#038;ssl=1\" alt=\"The zip_transform function\" width=\"600\" height=\"278\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code4-1.jpg?resize=300%2C139&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code4-1.jpg?resize=1024%2C475&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/code4-1.jpg?w=1115&amp;ssl=1 1115w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-4410\" class=\"wp-caption-text\"><strong>The zip_transform function<\/strong><\/figcaption><\/figure>\n<p>The corresponding output is:<\/p>\n<figure id=\"attachment_4411\" aria-describedby=\"caption-attachment-4411\" style=\"width: 400px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output4-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4411\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2026\/11\/13\/what-is-stdviewszip-in-c\/output4-11\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output4-1.jpg\" data-orig-size=\"630,137\" data-comments-opened=\"1\" data-image-meta=\"{&quot;credit&quot;:&quot;Admin&quot;,&quot;created_timestamp&quot;:&quot;1794492348&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\/11\/output4-1.jpg\" class=\"wp-image-4411\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output4-1.jpg?resize=400%2C87&#038;ssl=1\" alt=\"Program output\" width=\"400\" height=\"87\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output4-1.jpg?resize=300%2C65&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/11\/output4-1.jpg?w=630&amp;ssl=1 630w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/a><figcaption id=\"caption-attachment-4411\" class=\"wp-caption-text\"><strong>Program output<\/strong><\/figcaption><\/figure>\n<p><em><strong>std::views::zip<\/strong><\/em> provides the same functionality as the <em><strong>zip()<\/strong><\/em> function does in <em><strong>Python<\/strong><\/em>. As the above examples illustrate, it is quite useful when working with multiple collections.<\/p>\n<p>You can download the source <span style=\"text-decoration: underline;\"><a href=\"https:\/\/www.rangakrish.com\/downloads\/ZipExample.cpp\">here<\/a>.<\/span><\/p>\n<p>Have a nice weekend!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>std::views::zip was introduced in the &lt;ranges&gt; library as part of C++23. This is quite convenient when we want to iterate over two or more ranges in lockstep, taking one element from each at every step. It is a superior alternative to the conventional index loop. The following example shows the typical usage: The code above [&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_seo_schema_type":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_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":[469,467,468],"class_list":["post-4403","post","type-post","status-publish","format-standard","hentry","category-c","category-programming","tag-collections","tag-stdviewszip","tag-zip_transform"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-191","jetpack-related-posts":[{"id":4299,"url":"https:\/\/www.rangakrish.com\/index.php\/2026\/05\/14\/c23-slicing-with-stdviewschunk\/","url_meta":{"origin":4403,"position":0},"title":"C++23: Slicing with std::views::chunk","author":"admin","date":"May 14, 2026","format":false,"excerpt":"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,\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Using the chunk function","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example1-300x259.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example1-300x259.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2026\/05\/example1-300x259.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2975,"url":"https:\/\/www.rangakrish.com\/index.php\/2022\/12\/25\/stdtie\/","url_meta":{"origin":4403,"position":1},"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":683,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/11\/05\/c17-stdvariant\/","url_meta":{"origin":4403,"position":2},"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":4403,"position":3},"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":[]},{"id":1973,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/04\/26\/stdis_base_of\/","url_meta":{"origin":4403,"position":4},"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":1091,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/10\/14\/c17-stdapply-and-stdinvoke\/","url_meta":{"origin":4403,"position":5},"title":"C++17 &#8211; std::apply() and std::invoke()","author":"admin","date":"October 14, 2018","format":false,"excerpt":"Calling a function (or function object) dynamically, through a pointer known at runtime, is a common programming scenario. Almost all languages support this use case. Lisp, for example, has apply and funcall. When using apply, you can see that the arguments are passed via a separate list object. With funcall,\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Calling Member Functions","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/10\/Code5.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/10\/Code5.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/10\/Code5.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/10\/Code5.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/4403","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=4403"}],"version-history":[{"count":11,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/4403\/revisions"}],"predecessor-version":[{"id":4422,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/4403\/revisions\/4422"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=4403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=4403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=4403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}