Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're severely overthinking this. You've only got four vectors. You can determine the largest vector using 3 comparisons. Just do that:</p> <p><s></p> <pre><code>std::vector&lt;blah&gt;&amp; max = vector1; if (max.size() &lt; vector2.size()) max = vector2; if (max.size() &lt; vector3.size()) max = vector3; if (max.size() &lt; vector4.size()) max = vector4; </code></pre> <p></s></p> <h2>EDIT:</h2> <p>Now with pointers!</p> <p><s>EDIT (280Z28):</p> <p>Now with references! :)</s></p> <h2>EDIT:</h2> <p>The version with references won't work. Pavel Minaev explains it nicely in the comments:</p> <blockquote> <p>That's correct, the code use references. The first line, which declares max, doesn't cause a copy. However, all following lines do cause a copy, because when you write <code>max = vectorN</code>, if max is a reference, it doesn't cause the reference to refer to a different vector (a reference cannot be changed to refer to a different object once initialized). Instead, it is the same as <code>max.operator=(vectorN)</code>, which simply causes <code>vector1</code> to be cleared and replaced by elements contained in <code>vectorN</code>, copying them.</p> </blockquote> <p>The pointer version is likely your best bet: it's quick, low-cost, and simple.</p> <pre><code>std::vector&lt;blah&gt; * max = &amp;vector1; if (max-&gt;size() &lt; vector2.size()) max = &amp;vector2; if (max-&gt;size() &lt; vector3.size()) max = &amp;vector3; if (max-&gt;size() &lt; vector4.size()) max = &amp;vector4; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload