title: Pass by value or reference, to a C++ constructor that needs to store a copy?
body: <p>Should a C++ (implicit or explicit) value constructor accept its parameter(s) by value or reference-to-const, when it needs to store a copy of the argument(s) in its object either way?</p>
  
  <p>Here is the shortest example I can think of:</p>
  
  <pre><code>struct foo {
      bar _b;
      foo(bar [const&amp;] b) // pass by value or reference-to-const?
          : _b(b) { }
  };
  </code></pre>
  
  <p>The idea here is that I want to minimize the calls to bar's copy constructor when a foo object is created, in any of the various ways in which a foo object might get created.</p>
  
  <p>Please note that I do know a little bit about copy elision and (Named) Return Value Optimization, and I have read <a href="http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/" rel="nofollow noreferrer">"Want Speed? Pass by Value"</a>, however I don't think the article directly addresses this use case.</p>
  
  <p><strong>Edit:</strong> I should be more specific.</p>
  
  <p>Assume that I can't know the <code>sizeof(bar)</code>, or whether or not <code>bar</code> is a fundamental, built-in type (<code>bar</code> may be a template parameter, and <code>foo</code> may be a class template instead of a class).  Also, don't assume that <code>foo</code>'s constructor can be inlined (or <code>bar</code>'s, for that matter).  Do assume that I at least might be using a compiler that implements RVO.</p>
  
  <p>What I would like is for there to be a possibility (given compiler optimizations) that a call like this will invoke no calls to <code>bar</code>'s copy constructor whatsoever (even when executing <code>_b(b)</code> in <code>foo</code>'s initialization list):</p>
  
  <pre><code>foo f = function_that_creates_and_returns_a_bar_object_using_rvo();
  </code></pre>
  
  <p>Is there any possibility (given the C++98 standard) that this can be done, and if so, is it more or less likely to work if <code>foo</code> accepts its parameter by reference-to-const instead of by value?</p>