title: C++11: conditional compilation: members
body: <p>I'm trying to make a struct with conditional members, that means, different members exists only with specific specializations. But, I want that this classes are fastest as possible. I've tried it in three differents ways:</p>
  
  <p><strong>Way 1:</strong></p>
  
  <pre><code> template&lt;typename T, bool with_int = false&gt;
   struct foo
   {
       template&lt;typename... Args&gt;
       foo(Args&amp;&amp;... args) : m_t(forward&lt;Args&gt;(args)...)
       {}
  
       T m_t;
   }
  
   template&lt;typename T&gt;
   struct foo&lt;T, true&gt;
   {
       template&lt;typename... Args&gt;
       foo(Args&amp;&amp;... args) : m_t(forward&lt;Args&gt;(args)...), m_id(0)
       {}
  
        T m_t;
        int m_id;
   };
  </code></pre>
  
  <ul>
  <li>Disadventage: repeated code for each specialization.</li>
  </ul>
  
  <p><strong>Way 2:</strong></p>
  
  <pre><code> template&lt;typename T, bool with_int = false&gt;
   struct foo
   {
       template&lt;typename... Args&gt;
       foo(Args&amp;&amp;... args) : m_t(forward&lt;Args&gt;(args)...)
       {}
  
       virtual ~foo() {}
  
       T m_t;
   }
  
   template&lt;typename T&gt;
   struct foo&lt;T, false&gt; : public foo&lt;T&gt;
   {
        using foo&lt;T&gt;::foo;
  
        int m_id = 0;
   };
  </code></pre>
  
  <ul>
  <li>Adventage: few code.</li>
  <li>Disadventage: Use of vtables/inheritance/etc: more time in construction or access to members? But, in other way, I don't pretend to to use "references" to base class. What is it the real adventages or disadventages of this aproach?</li>
  </ul>
  
  <p><strong>Way 3</strong></p>
  
  <pre><code> using nil_type = void*;
   using zero_type = nil_type[0];
  
   template&lt;typename T, bool with_int = false&gt;
   struct foo
   {
      template&lt;typename... Args, typename = typename enable_if&lt;with_int&gt;::type&gt;
      foo(Args&amp;&amp;... args) : m_t(forward&lt;Args&gt;(args)...), m_int(0)
      {}
  
      template&lt;typename... Args, typename = typename enable_if&lt;!with_int&gt;::type&gt;
      foo(Args&amp;&amp;... args) : m_t(forward&lt;Args&gt;(args)...)
      {}        
  
      T m__t;
      typename conditional&lt;with_int, int, zero_type&gt;::type m_int;
   };
  </code></pre>
  
  <ul>
  <li>Ventages: Write code once; when <code>with_int</code> is <code>false</code>, field <code>m_int</code> has size 0 (almost with gcc 4.7.2).</li>
  <li>Adventages: More use of templates (reduce readability) and I'm not sure about how compilers deal with member of size 0. I don't know indeed to what extent a size-0-field is dangerous or has sense. Repeated constructors, but perhaps this is avoidable.</li>
  </ul>
  
  <p>What is the best approach or method?</p>