title: std::tuple with generic types like boost::any
body: <p>Dear fellow programmers,</p>
  
  <p>the code below gives me some headaches. It tries to add a 'generic' object (=object that can be constructed from anything) to a tuple and then copy that tuple. </p>
  
  <pre><code>    #include &lt;tuple&gt;
      #include &lt;iostream&gt;
      #include &lt;typeinfo&gt;
  
  
      struct anything
      {
         anything()
         {}
  
         anything(const anything&amp;)
         {
            std::cout &lt;&lt; "Called copy c'tor" &lt;&lt; std::endl;
         }
  
         template&lt;class T&gt;
         anything(T arg)
         {
            std::cout &lt;&lt; "Called c'tor with with argument of type " &lt;&lt; typeid(arg).name() &lt;&lt; std::endl;
            // new T(arg); // causes stack overflow
         }
      };
  
  
      int main()
      {
         std::tuple&lt;anything&gt; t;
         //
         std::cout &lt;&lt; "Copy constructing t2, expecting copy c'tor to be called." &lt;&lt; std::endl;
         std::tuple&lt;anything&gt; t2(t);
  
         return 0;
      }
  </code></pre>
  
  <p>With VS 2015 Update 2 it doesn't even compile, the line</p>
  
  <pre><code>std::tuple&lt;anything&gt; t2(t);
  </code></pre>
  
  <p>triggers a compiler error deep in tuple.h.
  With gcc 5.3.1 it compiles, but the output is not what I'd expect:</p>
  
  <p>Copy constructing t2, expecting copy c'tor to be called.<br>
  Called copy c'tor<br>
  Called c'tor with with argument of type St5tupleIJ8anythingEE</p>
  
  <p>What I don't understand is the last line, i.e. why the templated constructor gets called with std::tuple as argument?</p>
  
  <p>This is actually a real world problem. In my application I use a boost::signal of signature </p>
  
  <pre><code> typedef boost::type_erasure::any
           &lt;boost::mpl::vector&lt;
           boost::type_erasure::typeid_&lt;&gt;,
           boost::type_erasure::copy_constructible&lt;&gt;,
           boost::type_erasure::less_than_comparable&lt;&gt;,
           boost::type_erasure::equality_comparable&lt;&gt;,
           boost::type_erasure::relaxed
           &gt;&gt; KeyType;
  
  boost::signals2::signal&lt;void(const KeyType&amp;)&gt;
  </code></pre>
  
  <p>Boost signals internally wraps the argument in a tuple before calling the slot function with it, which eventually results in a stack overflow, because the tuple c'tor calls the any c'tor with tuple as argument and the any c'tor then calls the tuple c'tor with 'any of tuple' and so on and on and on...</p>