Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems from the comments that what you want is to take a vector, modify it destructively (in the sense that the original state cannot be reset) and then use the result internally. And you want this to work efficiently for both lvalues and rvalues.</p> <p>The next question is whether in the case of the lvalue, the code that holds the original container needs it after the function call has completed, and if it needs the original state of the vector or not. Depending on the answers to that you have different solutions:</p> <p><em>The caller holding an lvalue does not use it anymore after the call</em> </p> <p><em>(or alternatively, the caller holding the lvalue needs the original state)</em></p> <p>This is the simplest case. Then your function should take the container by value. If the caller has an lvalue, it can <code>std::move</code> to avoid the copy (it does not care about the object anymore) or <em>copy</em> which might be more expensive but leaves the original container untouched.</p> <p>If the function is called with an <em>rvalue</em> then the copy will be either elided or transformed into a cheap implicit move.</p> <p><em>The caller holding the lvalue does not need the original state, but it needs the container</em></p> <p>This case is the hard one, and you will need to provide two overloads for the same function (or lambda), one taking an <em>lvalue</em> to be used by this caller and a different taking an <em>rvalue-reference</em> for the case where the caller hands a temporary. In both cases the binding will be cheap. While this requires more code, you can implement one overload in terms of the other:</p> <pre><code>rtype f(std::vector&lt;Data&gt; &amp; ); // for lvalues rtype f(std::vector&lt;Data&gt; &amp;&amp; v) // for rvalues { return f(v); } // v is an lvalue here </code></pre> <p>The fact that you are doing lambdas might make this slightly more complicated, but hopefully not too much.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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