title: Vector initialisation using ranges vs lambda inline initialisation
body: <p>I would like to initialise a vector by transforming the other one. I made a test with two ways of inline initialisation a transformed <code>std::vector</code>.</p>
  <p>One using lambda inline initialisation (with <code>std::transform</code>):</p>
  <pre class="lang-cpp prettyprint-override"><code>   std::vector&lt;int&gt; foo(100,42);
     const auto fooTimesTwo = [&amp;]{
              std::vector&lt;int&gt; tmp(foo.size());
              std::transform(foo.begin(), foo.end(), tmp.begin(), convert);
              return tmp;
      }();
  </code></pre>
  <p>And the other one - using <code>std::ranges::views::transform</code>:</p>
  <pre class="lang-cpp prettyprint-override"><code>   std::vector&lt;int&gt; foo(100,42);
     auto transform_range = (foo | std::ranges::views::transform(convert));
     std::vector&lt;int&gt; fooTimesTwo {
             transform_range.begin(),
             transform_range.end()
     };
  </code></pre>
  <p>I expected that both way of vector initialisation should have similar performance, but from some reason the benchmark of solution with traditional <code>std::transform</code> is much faster that the second one (9.7 times faster -&gt; <a href="https://quick-bench.com/q/3PSDRO9UbMNunUpdWGNShF49WlQ" rel="noreferrer">https://quick-bench.com/q/3PSDRO9UbMNunUpdWGNShF49WlQ</a> ).</p>
  <p>My questions are:</p>
  <ul>
  <li>Do I use <code>std::ranges::views::transform</code> incorrectly?</li>
  <li>Why does it work so much slower?</li>
  </ul>
  <p>Side note - it can be done using <code>boost::make_transform_iterator</code>, but I couldn't check it on quick-bench as they don't support boost. So I'm not sure about efficiency of such solution.</p>