<div dir="auto">The problem is why use branch constructs to branch through multiple branches that call the same functions on a list of objects? <div dir="auto"><br></div><div dir="auto">Please tell me what am I missing?</div><div dir="auto">If you want, I can research the exact terms from the standard and replace my proposal with terms from the standard to describe what I want to propose.</div><div dir="auto">Regards, Muneem</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sat, 4 Apr 2026, 6:57 am Muneem, &lt;<a href="mailto:itfllow123@gmail.com">itfllow123@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">In standardese:<div dir="auto">I want the abstract machine to render any of the values chosen at runtime to be rendered in place regardless of their type.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 4 Apr 2026, 6:54 am Muneem, &lt;<a href="mailto:itfllow123@gmail.com" target="_blank" rel="noreferrer">itfllow123@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Think of intermediate code representation as the process where the c++ compiler is officially over and the backend of the compiler takes over (llvms that then translate code to assembly).</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 4 Apr 2026, 6:47 am Muneem, &lt;<a href="mailto:itfllow123@gmail.com" rel="noreferrer noreferrer" target="_blank">itfllow123@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">I really wish that you can advice me on how to present this problem because it does seem like I may be incapable of putting it into words. Like please do a counter proposal, I would really appreciate it.<div dir="auto">Regards, Muneem.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 4 Apr 2026, 6:43 am Muneem, &lt;<a href="mailto:itfllow123@gmail.com" rel="noreferrer noreferrer noreferrer" target="_blank">itfllow123@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">I am really really sorry if my response was no satisfactory.<div dir="auto">In short, all I want is to solve the problem where we can&#39;t tell the compiler to &quot;render an object of any type in place at the intermediate code level&quot;. This problem is a problem because we have to do it our selves unlike in languages like GO. One this problem is solved then heterogenous lists would be possible.</div><div dir="auto">Regards, Muneem</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 4 Apr 2026, 6:24 am Steve Weinrich via Std-Proposals, &lt;<a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals@lists.isocpp.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Hi Maneem,<div dir="auto"><br></div><div dir="auto">I had hoped by asking you to explain the problem you are trying to solve, I might be able to help you describe things in a way that would make it easier for you to describe the exact language feature you are proposing.</div><div dir="auto"><br></div><div dir="auto">Either am not smart enough to understand you (a good probability) or you are incapable of describing what you seek in C++ language terms.  Keep in mind that the committee only deals on the language!</div><div dir="auto"><br></div><div dir="auto">I wish you all the best.</div><div dir="auto"><br></div><div dir="auto">Cheers,</div><div dir="auto">Steve</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Apr 3, 2026, 19:09 Muneem via Std-Proposals &lt;<a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals@lists.isocpp.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Thank you for your response!<div dir="auto">what is the problem(the question you asked)?</div><div dir="auto">There are many possible answers to what your question might have meant(hope any of these answer you):</div><div dir="auto"><br></div><div dir="auto">1.This problem before c++ existed and before it had this static type system could be quantified as branching overhead and verbosity, and why we needed better techniques that avoided it.</div><div dir="auto">This wilkipedia article explains the first time that branching was a problem(all credits to wilkipedia:<a href="https://en.wikipedia.org/wiki/Branch_table" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://en.wikipedia.org/wiki/Branch_table</a>):</div><div dir="auto">Use of branch tables and other raw data encoding was common in the early days of computing when memory was expensive, CPUs were slower and compact data representation and efficient choice of alternatives were important. This fact is truer now more than ever. In particular the issue in branching: pointer redirection using any implementation like vtables or function pointers. Sometimes, branching may infact be faster, but again, constructs that give no context and intent to the compiler are hard for the compiler to decide what to do with. This is why c++ came and provides if statements, switch statements, ternary statements, and many more so that it can provide the best intermediate code representation possible. Each type of branch statements isn&#39;t just a new syntax but it makes a user write a certain way, and let&#39;s the compiler do optimizations before the compiler backend reads the code.</div><div dir="auto"><br></div><div dir="auto">2. The problem is the lack of a construct for describing a language level construct for type erasure that can result in optimized intermediate representation of the code.</div><div dir="auto"><br></div><div dir="auto">3.The problem is virtual functions don&#39;t do it, switch case statements don&#39;t do it, nothing does, manual type erasure code dosent so it. The &quot;it&quot; is type erasure patterns. Switch case (and others) statements fails completely if you don&#39;t write code for each object again and again.</div><div dir="auto"><br></div><div dir="auto">4. The problem is verbosity of current branching/polymorphism techniques for type erasure. Not only that but you can&#39;t even overload a polymorphic function to return a different type based on an argument(unless the return type is a polymorphic class(known as &quot;Return Type Relaxation&quot; in C++ 4th by Bajrne Stroustrup&quot; section 20.3.6)) in order to fix this problem by the visitor pattern or some other double dispatch pattern.</div><div dir="auto"><br></div><div dir="auto">5. The problem is lack of clear expression of type erasure. </div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div dir="auto">2. I don&#39;t want make an heterogeneous list in the traditional sense, but rather a list of const references of any type, so it isnt against c++ philosophies, it&#39;s just trying to automate the process of manual type erasure and leave it to the compiler to produce optimal intermediate code representation based on the specific program, context of every subscripting, and the source of every subscripting operation. That is as c++ as one can get. It would not be c++ if I were to just ask for heterogeneous list that is completely up to the implementation, but rather I want type erasure for const lvalue references at a language level(optimized intermediate code representation). Think of it like templates, if it helps making it easy to reason. In fact, this is a form of &quot;Return Type Relaxation&quot;(in C++ 4th by Bajrne Stroustrup&quot; section 20.3.6), but instead of pointers and references, but I want only want to use const references.</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 4 Apr 2026, 5:22 am Steve Weinrich via Std-Proposals, &lt;<a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals@lists.isocpp.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word"><div><p class="MsoNormal"><span style="font-size:11.0pt">Hi Muneem,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt">I am not trying to be difficult, but the “problems” that you have described are {potentially} the result of implementation choices and/or C++ limitations.  What I am currently interested in is the problem that was presented before making those choices.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt">Let me see if I can give an example.  Someone says, I have a problem.  Every time I insert on object into std::vector, I have to re-sort the vector.  Obviously, they are using the wrong container.  <u>But even if they switch to a std::map, we don’t know if the data truly needs to be sorted.  Or how frequently it needs to be sorted.<u></u><u></u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt">You say, “</span>You want to choose between three container objects but they don&#39;t have different type.”<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">That could look like:<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">std::vector&lt;int&gt; alpha;<span style="font-size:11.0pt"><u></u><u></u></span></p><p class="MsoNormal">std::vector&lt;int&gt; beta;<span style="font-size:11.0pt"><u></u><u></u></span></p><p class="MsoNormal">std::vector&lt;int&gt; gamma;<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">This immediately raises the question, “Why three vectors?”<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">You say, “You want to choose between any three objects but they have different types.”<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">That could look like:<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">class Alpha<u></u><u></u></p><p class="MsoNormal">{<u></u><u></u></p><p class="MsoNormal"> public:<u></u><u></u></p><p class="MsoNormal">    int funcA ();<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"> private:<u></u><u></u></p><p class="MsoNormal">    // Some Alpha specific data<u></u><u></u></p><p class="MsoNormal">};<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">class Beta<u></u><u></u></p><p class="MsoNormal">{<u></u><u></u></p><p class="MsoNormal"> public:<u></u><u></u></p><p class="MsoNormal">    int funcA ();<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"> private:<u></u><u></u></p><p class="MsoNormal">    // Some Beta specific data<u></u><u></u></p><p class="MsoNormal">};<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">class Gamma<u></u><u></u></p><p class="MsoNormal">{<u></u><u></u></p><p class="MsoNormal"> public:<u></u><u></u></p><p class="MsoNormal">    int funcA ();<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"> private:<u></u><u></u></p><p class="MsoNormal">    // Some Gamma specific data<u></u><u></u></p><p class="MsoNormal">};<u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt">That immediately raises the question, “Will virtual functions work?”<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt">So I ask again, what is the problem (not the solution)?<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt">Cheers,<br>Steve<u></u><u></u></span></p><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"> Std-Proposals &lt;<a href="mailto:std-proposals-bounces@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals-bounces@lists.isocpp.org</a>&gt; <b>On Behalf Of </b>Muneem via Std-Proposals<br><b>Sent:</b> Friday, April 3, 2026 6:03 PM<br><b>To:</b> <a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals@lists.isocpp.org</a><br><b>Cc:</b> Muneem &lt;<a href="mailto:itfllow123@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">itfllow123@gmail.com</a>&gt;<br><b>Subject:</b> Re: [std-proposals] Fwd: Extension to runtime polymorphism proposed<u></u><u></u></span></p></div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">An extended reason to why this class of problems described in the previous emails exists is because the current constructs dosent give enough context to intermediate code generation, and solely rely on llvms or other backends to be advanced enough, which for languages don&#39;t make sense because language are meant to be less verbose and more explicit than a compiler backend code generation tools.<u></u><u></u></p><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">(Really Sorry for sending two emails at one)<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">Regards, Muneem.<u></u><u></u></p></div></div><p class="MsoNormal"><u></u> <u></u></p><div><div><p class="MsoNormal">On Sat, 4 Apr 2026, 4:54<span style="font-family:&quot;Arial&quot;,sans-serif"> </span>am Muneem, &lt;<a href="mailto:itfllow123@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">itfllow123@gmail.com</a>&gt; wrote:<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in"><div><p class="MsoNormal">The actual class of problems is code repitition and obscurement of intent:<u></u><u></u></p><div><p class="MsoNormal">1.Say you want to choose between three container objects but they don&#39;t have different type.<u></u><u></u></p></div><div><p class="MsoNormal">2. Say you want to choose between any three objects but they have different types.<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">The current fix for both, to allocate those objects in a std::vector/array of std::variant element type or to use switch statements. All of these obscure intent making it hard to optimize code in intermediate code generation. This is actually more common than we think, infact, we can destroy 99% of germs(branch statements) with function objects that can be indexed.<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">In short the class of problems is using too many branch statements for everything that can&#39;t be indexed by current containers.<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div></div><p class="MsoNormal"><u></u> <u></u></p><div><div><p class="MsoNormal">On Sat, 4 Apr 2026, 4:24<span style="font-family:&quot;Arial&quot;,sans-serif"> </span>am Steve Weinrich via Std-Proposals, &lt;<a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals@lists.isocpp.org</a>&gt; wrote:<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in"><div><div><p class="MsoNormal"><span style="font-size:11.0pt">Hi Muneem,</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">You mention “this class of problems”  I would like to know what that is?  Please forget about a heterogenous list.  What is the root problem that the heterogenous list solves?  Please describe an actual problem, not a “it would be nice to solve.”</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">To make this a little easier and to involve less people, here is my email: <a href="mailto:weinrich.steve@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">weinrich.steve@gmail.com</a></span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">Cheers,<br>Steve</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"> Std-Proposals &lt;<a href="mailto:std-proposals-bounces@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals-bounces@lists.isocpp.org</a>&gt; <b>On Behalf Of </b>Muneem via Std-Proposals<br><b>Sent:</b> Friday, April 3, 2026 5:17 PM<br><b>To:</b> <a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals@lists.isocpp.org</a><br><b>Cc:</b> Muneem &lt;<a href="mailto:itfllow123@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">itfllow123@gmail.com</a>&gt;<br><b>Subject:</b> Re: [std-proposals] Fwd: Extension to runtime polymorphism proposed</span><u></u><u></u></p></div><p class="MsoNormal"> <u></u><u></u></p><div><p class="MsoNormal">Thanks for your interested <span style="font-family:&quot;Segoe UI Emoji&quot;,sans-serif">❤️❤️❤️</span> <u></u><u></u></p><div><p class="MsoNormal">If you believe that any other solution maybe a better option for this class of problems then please let me know. In fact, we would collaborate on the proposal. This is not at odds with c++ because the (recommended) semantics is a construct that captures values using const references, as opposed to storing them directly as a struct would, and for the compiler to access the value by reference, inline code for each branch, or do what it thinks it best. It is similiar to the heterogeneous lists provided by GO but it isn&#39;t because it captures by const value reference, and references aren&#39;t the same as non const pointers, in the that they can be optimized like const pointer can&#39;t be. Sorry for writing too much, I just got too excited by someone taking openly interest in this proposal <span style="font-family:&quot;Segoe UI Emoji&quot;,sans-serif">❤️❤️❤️❤️</span>.<u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal">Regards, Muneem <u></u><u></u></p></div></div><p class="MsoNormal"> <u></u><u></u></p><div><div><p class="MsoNormal">On Sat, 4 Apr 2026, 4:11<span style="font-family:&quot;Arial&quot;,sans-serif"> </span>am Steve Weinrich via Std-Proposals, &lt;<a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals@lists.isocpp.org</a>&gt; wrote:<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt"><div><div><p class="MsoNormal"><span style="font-size:11.0pt">Hi Muneem,</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">Thanks.  I am interested in the original problem.  I am curious if a heterogeneous list is the optimal solution for the problem at hand.  Over the last 50+ years of programming, I have encountered many questions like yours, which presume a particular solution.  Sometimes that solution is at odds with the language at hand (or other issues).  I find that understanding the original problem allows me to better understand why one is suggesting a particular language enhancement.</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">Cheers,<br>Steve</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"> Std-Proposals &lt;<a href="mailto:std-proposals-bounces@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals-bounces@lists.isocpp.org</a>&gt; <b>On Behalf Of </b>Muneem via Std-Proposals<br><b>Sent:</b> Friday, April 3, 2026 5:03 PM<br><b>To:</b> <a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals@lists.isocpp.org</a><br><b>Cc:</b> Muneem &lt;<a href="mailto:itfllow123@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">itfllow123@gmail.com</a>&gt;<br><b>Subject:</b> Re: [std-proposals] Fwd: Extension to runtime polymorphism proposed</span><u></u><u></u></p></div><p class="MsoNormal"> <u></u><u></u></p><div><div><p class="MsoNormal">&gt;context for readers:second one was a class of problems fixed by heterogeneous lists.<u></u><u></u></p></div><p class="MsoNormal">It&#39;s the second one, and I am really really sorry for the confusion. <u></u><u></u></p><div><p class="MsoNormal"> <u></u><u></u></p></div></div><p class="MsoNormal"> <u></u><u></u></p><div><div><p class="MsoNormal">On Sat, 4 Apr 2026, 3:58<span style="font-family:&quot;Arial&quot;,sans-serif"> </span>am Steve Weinrich via Std-Proposals, &lt;<a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals@lists.isocpp.org</a>&gt; wrote:<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt"><div><div><p class="MsoNormal"><span style="font-size:11.0pt">If I may, a </span>heterogeneous list is not a problem, it is a solution to a problem.  So there are now two possibilities:<u></u><u></u></p><ol start="1" type="1"><li class="MsoNormal"><span style="font-size:11.0pt">You are trying to create a new std container to solve a class of problems.</span><u></u><u></u></li><li class="MsoNormal"><span style="font-size:11.0pt">You have some other problem that you have used a heterogenous list to solve.</span><u></u><u></u></li></ol><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">What say you?</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">Cheers,<br>Steve</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"> Std-Proposals &lt;<a href="mailto:std-proposals-bounces@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals-bounces@lists.isocpp.org</a>&gt; <b>On Behalf Of </b>Muneem via Std-Proposals<br><b>Sent:</b> Friday, April 3, 2026 4:54 PM<br><b>To:</b> <a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals@lists.isocpp.org</a><br><b>Cc:</b> Muneem &lt;<a href="mailto:itfllow123@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">itfllow123@gmail.com</a>&gt;<br><b>Subject:</b> Re: [std-proposals] Fwd: Extension to runtime polymorphism proposed</span><u></u><u></u></p></div><p class="MsoNormal"> <u></u><u></u></p><div><p class="MsoNormal">Sorry, I meant &quot;heterogeneous lists is the problem&quot;, so really really sorry for that mistake, It was an auto correct mistake. <u></u><u></u></p></div><p class="MsoNormal"> <u></u><u></u></p><div><div><p class="MsoNormal">On Sat, 4 Apr 2026, 3:52<span style="font-family:&quot;Arial&quot;,sans-serif"> </span>am Muneem, &lt;<a href="mailto:itfllow123@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">itfllow123@gmail.com</a>&gt; wrote:<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt"><div><div><p class="MsoNormal">Heterogeneous problems is the problem that leads to the code bloat or verbosity that I described, but it&#39;s hard to chose weather chicken came first or the egg in this regard.<u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal">Regards, Muneem<u></u><u></u></p></div></div><p class="MsoNormal"> <u></u><u></u></p><div><div><p class="MsoNormal">On Sat, 4 Apr 2026, 3:50<span style="font-family:&quot;Arial&quot;,sans-serif"> </span>am Steve Weinrich via Std-Proposals, &lt;<a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals@lists.isocpp.org</a>&gt; wrote:<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt"><div><div><p class="MsoNormal"><span style="font-size:11.0pt">Hi Muneem,</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">If you don’t mind, I would like to limit this portion of our interaction to simply describing the problem.  I want to get a 100% understanding of the problem, unfettered by any assumptions (including C++ limitations) or previous solutions.  Is a heterogenous list actually the problem or is that simply a solution that you think fits the problem at hand?</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">Cheers,<br>Steve</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"> Std-Proposals &lt;</span><a href="mailto:std-proposals-bounces@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">std-proposals-bounces@lists.isocpp.org</span></a><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">&gt; <b>On Behalf Of </b>Muneem via Std-Proposals<br><b>Sent:</b> Friday, April 3, 2026 4:40 PM<br><b>To:</b> </span><a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">std-proposals@lists.isocpp.org</span></a><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><br><b>Cc:</b> Muneem &lt;</span><a href="mailto:itfllow123@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">itfllow123@gmail.com</span></a><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">&gt;<br><b>Subject:</b> Re: [std-proposals] Fwd: Extension to runtime polymorphism proposed</span><u></u><u></u></p></div><p class="MsoNormal"> <u></u><u></u></p><div><div><p class="MsoNormal">Hi!<u></u><u></u></p></div><div><p class="MsoNormal">Thanks for your response!!!<u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><p class="MsoNormal">Yes, your  understanding of the problem is mostly correct with a few details left out. The alternative to using classes would be switch statements that as discussed would lead to code bloat and might backfire. The goal is to make a construct that makes the indexing into heterogenous lists more easy. There is how ever one thing that I would like to clarify:<u></u><u></u></p><div><p class="MsoNormal">The goal isn&#39;t the classic polymorphism but to be able to return an object of any type through a specified interface(indexing heterogenous lists), which your example dosent do. Basically, just like GO and many other compiled languages support heterogenous lists, I want c++ to do so as well. Say you want index a bunch of containers(to use top() function),std::visit fails because it can&#39;t return any return type that you would wish for, so you can either use switch case to write expression top for each container or this long verbose technique:<u></u><u></u></p></div><div><div><p class="MsoNormal">#include&lt;vector&gt;<u></u><u></u></p></div><div><p class="MsoNormal">#include&lt;deque&gt;<u></u><u></u></p></div><div><p class="MsoNormal">template&lt;typename T&gt;<u></u><u></u></p></div><div><p class="MsoNormal">struct Base{<u></u><u></u></p></div><div><p class="MsoNormal">     virtual T top_wrapper();<u></u><u></u></p></div><div><p class="MsoNormal">};<u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal">template&lt;typename T&gt;<u></u><u></u></p></div><div><p class="MsoNormal">struct Derived_1: Base&lt;T&gt;, std::vector&lt;T&gt;{<u></u><u></u></p></div><div><p class="MsoNormal">      T top_wrapper() override{<u></u><u></u></p></div><div><p class="MsoNormal">           return T{*this.top()};//T{} is just to show that it works even if top had some other return type <u></u><u></u></p></div><div><p class="MsoNormal">     }<u></u><u></u></p></div><div><p class="MsoNormal">};<u></u><u></u></p></div><div><p class="MsoNormal">template&lt;typename T&gt;<u></u><u></u></p></div><div><p class="MsoNormal">struct Derived_2: Base&lt;T&gt;, std:: deque&lt;T&gt;{<u></u><u></u></p></div><div><p class="MsoNormal">      T top_wrapper() override{<u></u><u></u></p></div><div><p class="MsoNormal">           return T{*this.top()};//T{} is just to show that it works even if top had some other return type <u></u><u></u></p></div><div><p class="MsoNormal">     }<u></u><u></u></p></div><div><p class="MsoNormal">};<u></u><u></u></p></div><div><p class="MsoNormal">int main(){<u></u><u></u></p></div><div><p class="MsoNormal">std::vector&lt;Base&lt;int&gt;&gt; a;<u></u><u></u></p></div><div><p class="MsoNormal">//The compiler would probably optimize this example, but not an example where you index the vector using real time input<u></u><u></u></p></div><div><p class="MsoNormal">return 0;<u></u><u></u></p></div><div><p class="MsoNormal">}<u></u><u></u></p></div></div><div><p class="MsoNormal">//An vector of std::variant only works if I am willing to write a helper top(std::variant&lt;Args...&gt; obj) function that includes std::visit to call top(), that in of itself is not only verbose but obscures intent and context. <u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal">Regards, Muneem.<u></u><u></u></p></div></div><p class="MsoNormal"> <u></u><u></u></p><div><div><p class="MsoNormal">On Sat, 4 Apr 2026, 2:43<span style="font-family:&quot;Arial&quot;,sans-serif"> </span>am Steve Weinrich via Std-Proposals, &lt;<a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals@lists.isocpp.org</a>&gt; wrote:<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt"><div><div><p class="MsoNormal"><span style="font-size:11.0pt">Hi Muneem,</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">I would like to make sure that I understand this problem before going on.</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">I think there are several classes that have a portion (or all) of their interface in common.  Each method of the interface returns a constant value:</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">class First</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">{</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">public:</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">  int funcA () const { return 1123; }</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">  int funcB () const ( return 1234; }</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">  int funcC () const { return 1456; }</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">};</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">class Second</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">{</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">public:</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">  int funcA () const { return 2123; }</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">  int funcB () const ( return 2234; }</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> int funcC () const { return 2456; }</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">};</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">class Third</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">{</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">public:</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">  int funcA () const { return 3123; }</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">  int funcB () const ( return 3234; }</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> int funcC () const { return 3456; }</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">};</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><ol start="1" type="1"><li class="MsoNormal"><span style="font-size:11.0pt">We would like a means to be able to add more classes easily.</span><u></u><u></u></li><li class="MsoNormal"><span style="font-size:11.0pt">We would like a means to be able to add to the shared interface easily.</span><u></u><u></u></li><li class="MsoNormal"><span style="font-size:11.0pt">We would like to be able to use the shared interface in a polymorphic way (like a virtual method).</span><u></u><u></u></li><li class="MsoNormal"><span style="font-size:11.0pt">Performance is of the utmost importance.</span><u></u><u></u></li></ol><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">Is my understanding correct?</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt"> </span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:11.0pt">Steve</span><u></u><u></u></p><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"> Std-Proposals &lt;</span><a href="mailto:std-proposals-bounces@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">std-proposals-bounces@lists.isocpp.org</span></a><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">&gt; <b>On Behalf Of </b>Muneem via Std-Proposals<br><b>Sent:</b> Friday, April 3, 2026 1:54 PM<br><b>To:</b> </span><a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">std-proposals@lists.isocpp.org</span></a><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif"><br><b>Cc:</b> Muneem &lt;</span><a href="mailto:itfllow123@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">itfllow123@gmail.com</span></a><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif">&gt;<br><b>Subject:</b> Re: [std-proposals] Fwd: Extension to runtime polymorphism proposed</span><u></u><u></u></p></div><p class="MsoNormal"> <u></u><u></u></p><div><p class="MsoNormal">Sorry for sending two emails at once!<u></u><u></u></p><div><p class="MsoNormal">I just wanted to revise the fact that the point of the whole proposal is to provide intent, the code that Mr. Maciera was kind enough to bring forward proves my exact point, that with enough intent, the compiler can optimize anythjng, and these optimizations grow larger as the scale of the program grows larger. Microbenchmarks might show a single example but even that single example should get us thinking that why is it so slow for this one example? Does this overhead force people to write switch case statements that can lead to code bloat which can again backfire in terms of performance?<u></u><u></u></p></div><div><p class="MsoNormal">Regards, Muneem.<u></u><u></u></p></div></div><p class="MsoNormal"> <u></u><u></u></p><div><div><p class="MsoNormal">On Sat, 4 Apr 2026, 12:48<span style="font-family:&quot;Arial&quot;,sans-serif"> </span>am Muneem, &lt;<a href="mailto:itfllow123@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">itfllow123@gmail.com</a>&gt; wrote:<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt"><div><div><div><p class="MsoNormal">Hi!<u></u><u></u></p></div><div><p class="MsoNormal">Thanks again for your feedback, Macieira. <span style="font-family:&quot;Segoe UI Emoji&quot;,sans-serif">👍</span><u></u><u></u></p></div><p class="MsoNormal">&gt;micro benchmark is misleading<u></u><u></u></p></div><div><p class="MsoNormal">1. The reason that I gave you microbenchmarks is that some asked for it, and even I was too relectunt to use them despite the quote of Bjarne Stroustrups <u></u><u></u></p></div><div><p class="MsoNormal">&quot;Don&#39;t assume, measure&quot; because in this case, the goal is to either make the compiler smaller or runtime faster, both of which are targeted by my new proposal.<u></u><u></u></p></div><div><p class="MsoNormal">2. You are right that the compiler might have folded the loop into half,  but the point is that it still shows that the observable behaviour is the same, infact, if the loop body was to index into a heterogeneous set(using the proposed construct) and do some operation then the compiler would optimize the indexing if the source of the index is one. This proves that intent. An help the compiler do wonders:<u></u><u></u></p></div><div><p class="MsoNormal">1.Fold loops even when I used volatile to avoid it.<u></u><u></u></p></div><div><p class="MsoNormal">2.Avoid the entire indexing operations (if in a loop with the most minimal compile time overhead)<u></u><u></u></p></div><div><p class="MsoNormal">3. Store the result immediately after it takes input into some memory location (if that solution is the fasted).<u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal">3.Optimize a single expression for the sake of the whole program.<u></u><u></u></p></div><div><p class="MsoNormal">Currently, the optimizer might in fact be able to optimize checks in a loop, but it&#39;s not as easy or as gurrentied because there are no semantical promises that we can make with the existing constructs to make it happen.<u></u><u></u></p></div><div><p class="MsoNormal">4.My main point isn&#39;t weather my benchmark is correct or wrong, but rather that expressing intent is better. The bench mark was merely to show that std::visit is slower (according to g++ and Microsoft visual studio 2026 compiled programs, using std::chorno and visual studio 2026 CPU usage measurement tools to prove my point), but even if some compiler or all compilers optimize their performance; we still have compile time overhead for taking std::visit and making it faster, and the optimization might backfire since it would be to optimize single statements independent of what&#39;s in the rest of the program. Why? Because unlike my proposed construct, std::visit does not have enough context and intent to tell the compiler what&#39;s going on so that it can generate code that has the exact &quot;book keeping&quot; data and access code that fits the entire program.<u></u><u></u></p></div><div><div><p class="MsoNormal"> <u></u><u></u></p></div></div><div><p class="MsoNormal">3. In case, someone&#39;s think a few nano seconds in a single example isn&#39;t a big deal, then rethink it because if my construct is passed then yes, it would not be a big deal because the compiler can optimize many indexing operations into a single heterogenous set and maybe cache the result afterwards somewhere. The issue is that this can&#39;t be done with the current techniques because of the lack of intent. Compilers are much smarter than we could ever be because they are work of many people&#39;s entire career, not just one very smart guy from Intel, so blaming/restricting compilers whose job is to be as general for the sake of the whole program.<u></u><u></u></p></div><div><p class="MsoNormal">4.&gt;I suppose it decided to unroll the loop a &gt;bit<u></u><u></u></p></div><div><p class="MsoNormal">&gt;and made two calls to sink() per loop:<u></u><u></u></p></div><div><p class="MsoNormal">&gt;template &lt;typename T&gt; void sink(const T &gt;&amp;) { asm volatile(&quot;&quot; ::: &quot;memory&quot;); }<u></u><u></u></p></div><div><p class="MsoNormal">Even if it optimized switch case statement using volatile(&quot;&quot; ::: &quot;memory&quot;);  but not std::visit<u></u><u></u></p></div><div><p class="MsoNormal">That&#39;s my point isn&#39;t that switch case is magically faster, but rather the compiler has more room to cheat and skip things. Infact the standard allows it a lot of free room as long as the observable behaviour is the same, even more so by giving it free room with sets of observable behaviours (unspecified behaviours)<u></u><u></u></p></div><div><p class="MsoNormal">5. Microbe marking wasent to show that std::visit is inherintly slower,  but rather the compiler can and should do mistakes in optimizing it, in order to avoid massive compile time overhead.<u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><div><p class="MsoNormal"> <u></u><u></u></p></div><p class="MsoNormal"> <u></u><u></u></p><div><div><p class="MsoNormal">On Fri, 3 Apr 2026, 8:33<span style="font-family:&quot;Arial&quot;,sans-serif"> </span>pm Thiago Macieira via Std-Proposals, &lt;<a href="mailto:std-proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">std-proposals@lists.isocpp.org</a>&gt; wrote:<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt"><p class="MsoNormal">On Thursday, 2 April 2026 19:15:42 Pacific Daylight Time Thiago Macieira via <br>Std-Proposals wrote:<br>&gt; Even in this case, I have profiled the code above (after fixing it and<br>&gt; removing the std::cout itself) and found that overall, the switched case<br>&gt; ran 2x faster, at 0.113 ns per iteration, while the variant case required<br>&gt; 0.227 ns per iteration. Looking at the CPU performance counters, the<br>&gt; std::variant code has 2 branches per iteration and takes 1 cycle per<br>&gt; iteration, running at 5 IPC (thus, 5 instructions per iteration).<br>&gt; Meanwhile, the switched case has 0.5 branch per iteration and takes 0.5<br>&gt; cycle per iteration, running at 2 IPC. The half cycle numbers make sense<br>&gt; because I believe the two instructions are getting macrofused together and<br>&gt; execute as a single uop, which causes confusing numbers.<br><br>This half a cycle and ninth of a nanosecond problem has been on my mind for a <br>while. The execution time of anything needs to be a multiple of the cycle <br>time, so a CPU running at 4.5 GHz line mine was shouldn&#39;t have a difference of <br>one ninth of a nanosecond. One explanation would be that somehow the CPU was <br>executing two iterations of the loop at the same time, pipelining.<br><br>But disassembling the binary shows a simpler explanation. The switch loop was:<br><br>  40149f:       mov    $0x3b9aca00,%eax<br>  4014a4:       nop<br>  4014a5:       data16 cs nopw 0x0(%rax,%rax,1)<br>  4014b0:       sub    $0x2,%eax<br>  4014b3:       jne    4014b0<br><br>[Note how there is no test for what was being indexed in the loop!]<br><br>Here&#39;s what I had missed: sub $2. I&#39;m not entirely certain what GCC was <br>thinking here, but it&#39;s subtracting 2 instead of 1, so this looped half a <br>billion times (0x3b9aca00 / 2). I suppose it decided to unroll the loop a bit <br>and made two calls to sink() per loop:<br><br>template &lt;typename T&gt; void sink(const T &amp;) { asm volatile(&quot;&quot; ::: &quot;memory&quot;); }<br><br>But that expanded to nothing in the output. I could add &quot;nop&quot; so we&#39;d see what <br>happened and the CPU would be obligated to retire those instructions, <br>increasing the instruction executed counter (I can&#39;t quickly find how many the <br>TGL processor / WLC core can retire per cycle, but I recall it&#39;s 6, so adding <br>2 more instructions shouldn&#39;t affect the execution time). But I don&#39;t think I <br>need to further benchmark this to prove my point:<br><br>The microbenchmark is misleading.<br><br>-- <br>Thiago Macieira - thiago (AT) <a href="http://macieira.info" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">macieira.info</a> - thiago (AT) <a href="http://kde.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">kde.org</a><br>  Principal Engineer - Intel Data Center - Platform &amp; Sys. Eng.<br>-- <br>Std-Proposals mailing list<br><a href="mailto:Std-Proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">Std-Proposals@lists.isocpp.org</a><br><a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><u></u><u></u></p></blockquote></div></div></blockquote></div></div></div><p class="MsoNormal">-- <br>Std-Proposals mailing list<br><a href="mailto:Std-Proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">Std-Proposals@lists.isocpp.org</a><br><a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><u></u><u></u></p></blockquote></div></div></div><p class="MsoNormal">-- <br>Std-Proposals mailing list<br><a href="mailto:Std-Proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">Std-Proposals@lists.isocpp.org</a><br><a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><u></u><u></u></p></blockquote></div></blockquote></div></div></div><p class="MsoNormal">-- <br>Std-Proposals mailing list<br><a href="mailto:Std-Proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">Std-Proposals@lists.isocpp.org</a><br><a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><u></u><u></u></p></blockquote></div></div></div><p class="MsoNormal">-- <br>Std-Proposals mailing list<br><a href="mailto:Std-Proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">Std-Proposals@lists.isocpp.org</a><br><a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><u></u><u></u></p></blockquote></div></div></div><p class="MsoNormal">-- <br>Std-Proposals mailing list<br><a href="mailto:Std-Proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">Std-Proposals@lists.isocpp.org</a><br><a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><u></u><u></u></p></blockquote></div></blockquote></div></div></div>-- <br>
Std-Proposals mailing list<br>
<a href="mailto:Std-Proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">Std-Proposals@lists.isocpp.org</a><br>
<a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><br>
</blockquote></div>
-- <br>
Std-Proposals mailing list<br>
<a href="mailto:Std-Proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">Std-Proposals@lists.isocpp.org</a><br>
<a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><br>
</blockquote></div>
-- <br>
Std-Proposals mailing list<br>
<a href="mailto:Std-Proposals@lists.isocpp.org" rel="noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">Std-Proposals@lists.isocpp.org</a><br>
<a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><br>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>

