title: Variant implementation (variadic template) C++
body: <p>I'm trying to implement a variant class but I'm having a problem with a recursive function:</p>
  
  <pre><code>template&lt;typename Visitor, typename... Types&gt;
  class VariantVisitor;
  
  template&lt;typename... Types&gt;
  class Variant
  {
      template &lt;typename V, typename... types&gt;
      friend class VariantVisitor;
  public:
      struct holder
      {
          virtual ~holder() {}
      };
  
      template &lt;typename T&gt;
      struct impl : public holder
      {
          impl(const T&amp; t) : val(t) {}
          T get() const { return val; }
          T val;
      };
  
      Variant() : mHolder(nullptr) {}
  
      template &lt;typename T&gt;
      Variant(const T&amp; t) 
      {
          mHolder = new impl&lt;T&gt;(t);
      }
  
      Variant(const Variant&lt;Types...&gt;&amp; v) : mHolder(nullptr)
      {
          copy&lt;Types...&gt;(v);
      }
  
      ~Variant()
      {
          delete mHolder;
      }
  
      template &lt;typename T&gt;
      Variant&lt;Types...&gt;&amp; operator = (const T&amp; t)
      {
          if (!mHolder) {
              mHolder = new impl&lt;T&gt;(t);
              return *this;
          }
  
          _ASSERT(typeid(*mHolder) == typeid(impl&lt;T&gt;));
          static_cast&lt;impl&lt;T&gt;*&gt;(mHolder)-&gt;val = t;
          return *this;
      }
  
      Variant&lt;Types...&gt; &amp;operator = (const Variant&amp; v)
      {
          copy&lt;Types...&gt;(v);
          return *this;
      }
  
      template &lt;typename T&gt;
      T Get() const
      {
          _ASSERT(mHolder &amp;&amp; typeid(*mHolder) == typeid(impl&lt;T&gt;));
          return static_cast&lt;impl&lt;T&gt;*&gt;(mHolder)-&gt;get();
      }
  
      template&lt;typename T&gt;
      bool Is() const
      {
          return (mHolder &amp;&amp; typeid(*mHolder) == typeid(impl&lt;T&gt;));
      }
  private:
      template &lt;typename T&gt;
      void copy(const Variant&lt;Types...&gt;&amp; v)
      {
          if (mHolder) delete mHolder;
          impl&lt;T&gt;* ptr = static_cast&lt;impl&lt;T&gt;*&gt;(v.mHolder);
          mHolder = new impl&lt;T&gt;(*ptr);
      }
  
      template &lt;typename T, typename...types&gt;
      void copy(const Variant&lt;Types...&gt;&amp; v)
      {
          if (!Is&lt;T&gt;())
              return copy&lt;types...&gt;(v);
  
          copy&lt;T&gt;(v);
      }
  
      holder* mHolder;
  };
  </code></pre>
  
  <p>Visual C++ 2013 says there is an ambiguous call to this line:</p>
  
  <pre><code>copy&lt;T&gt;(v);
  </code></pre>
  
  <p>I'm new to variadic templates but I think it should distinguish the two copy functions for the number of types, shouldn't it? So why they can be both overloads? And, of course, how can I fix this?</p>