title: class constructor precedence with a variadic template constructor for a value wrapper
body: <p>Today I've discovered that I don't understand the C++ constructor precedence rules.</p>
  
  <p>Please, see the following template <code>struct wrapper</code></p>
  
  <pre><code>template &lt;typename T&gt;
  struct wrapper
   {
     T value;
  
     wrapper (T const &amp; v0) : value{v0}
      { std::cout &lt;&lt; "value copy constructor" &lt;&lt; std::endl; }
  
     wrapper (T &amp;&amp; v0) : value{std::move(v0)}
      { std::cout &lt;&lt; "value move constructor" &lt;&lt; std::endl; }
  
     template &lt;typename ... As&gt;
     wrapper (As &amp;&amp; ... as) : value(std::forward&lt;As&gt;(as)...)
      { std::cout &lt;&lt; "emplace constructor" &lt;&lt; std::endl; }
  
     wrapper (wrapper const &amp; w0) : value{w0.value}
      { std::cout &lt;&lt; "copy constructor" &lt;&lt; std::endl; }
  
     wrapper (wrapper &amp;&amp; w0) : value{std::move(w0.value)}
      { std::cout &lt;&lt; "move constructor" &lt;&lt; std::endl; }
   };
  </code></pre>
  
  <p>It's a simple template value wrapper with copy constructor (<code>wrapper const &amp;</code>), a move constructor (<code>wrapper &amp;&amp; w0</code>), a sort of value copy constructor (<code>T const &amp; v0</code>), a sort of move constructor (<code>T &amp;&amp; v0</code>) and a sort of template construct-in-place-the-value constructor (<code>As &amp;&amp; ... as</code>, following the example of <code>emplace</code> methods for STL containers).</p>
  
  <p>My intention was to use the copy or moving constructor calling with a wrapper, the value copy or move constructor passing a <code>T</code> object and the template emplace constructor calling with a list of values able to construct an object of type <code>T</code>.</p>
  
  <p>But I don't obtain what I expected.</p>
  
  <p>From the following code</p>
  
  <pre><code>std::string s0 {"a"};
  
  wrapper&lt;std::string&gt; w0{s0};            // emplace constructor (?)
  wrapper&lt;std::string&gt; w1{std::move(s0)}; // value move constructor
  wrapper&lt;std::string&gt; w2{1u, 'b'};       // emplace constructor
  //wrapper&lt;std::string&gt; w3{w0};          // compilation error (?)
  wrapper&lt;std::string&gt; w4{std::move(w0)}; // move constructor
  </code></pre>
  
  <p>The <code>w1</code>, <code>w2</code> and <code>w4</code> values are constructed with value move constructor, emplace constructor and move constructor (respectively) as expected.</p>
  
  <p>But <code>w0</code> is constructed with emplace constructor (I was expecting value copy constructor) and <code>w3</code> isn't constructed at all (compilation error) because the emplace constructor is preferred but ins't a <code>std::string</code> constructor that accept a <code>wrapper&lt;std::string&gt;</code> value.</p>
  
  <p>First question: what am I doing wrong?</p>
  
  <p>I suppose that the <code>w0</code> problem it's because <code>s0</code> isn't a <code>const</code> value, so the <code>T const &amp;</code> isn't an exact match.</p>
  
  <p>Indeed, if I write</p>
  
  <pre><code>std::string const s1 {"a"};
  
  wrapper&lt;std::string&gt; w0{s1};  
  </code></pre>
  
  <p>I get the value copy constructor called</p>
  
  <p>Second question: what I have to do to obtain what I want?</p>
  
  <p>So what I have to do to make the value copy constructor (<code>T const &amp;</code>) to get the precedence over the emplace constructor (<code>As &amp;&amp; ...</code>) also with not constant <code>T</code> values and, mostly, what I have to do to get the copy constructor (<code>wrapper const &amp;</code>) take the precedence constructing <code>w3</code>?</p>