title: How to check if a class has a default constructor, either public, protected or private
body: <p>I need to check if a class <code>C</code> has a default constructor, either implicit or custom, and either <code>public</code>, <code>protected</code> or <code>private</code>.</p>
  
  <p>I tried using <code>std::is_default_constructible&lt;C&gt;::value</code>, which returns true if <code>C</code> has a <code>public</code> default constructor (either implicit or custom) but <code>false</code> if <code>C</code> has a <code>protected</code> or <code>private</code> default constructor (seams to be the standard behavior though.)</p>
  
  <p>Is there any way to check if a class has a <code>protected</code> or <code>private</code> default constructor ?</p>
  
  <p>Note (if this may help): the check is performed from a function that is <code>friend</code> of the class <code>C</code> to be checked.</p>
  
  <hr>
  
  <p>I need to perform this check in order to default-construct objects corresponding to the <code>nullptr</code> pointers of the <code>m_objs</code> tuple, member of a <code>Foo</code> object (partial Foo definition below):</p>
  
  <pre><code>template&lt;class... Objects&gt;
  class Foo
  {
  public:
      Foo(Objects*... objects)
      : m_objs(objects...)
      {
          // User construct a Foo objects passing a pack of pointers
          // some of them are nullptr, some are not.
          // The following call should default-construct objects corresponding
          // to the null pointers of m_objs member tuple:
          objs_ctor&lt;Objects...&gt;();
      }
  private:
      template&lt;class Obj, class O1, class ...On&gt;
      void objs_ctor()
      {
          objs_ctor&lt;Obj&gt;(); objs_ctor&lt;O1, On...&gt;();
      }
      template&lt;class Obj&gt;
      typename std::enable_if&lt;std::is_default_constructible&lt;Obj&gt;::value, void&gt;::type
      objs_ctor()
      {
          Obj*&amp; obj = std::get&lt;Obj*&gt;(m_objs);
          if (obj == nullptr)
              obj = new Obj;    // default-construct Obj
      }
      template&lt;class Obj&gt;
      typename std::enable_if&lt;!std::is_default_constructible&lt;Obj&gt;::value, void&gt;::type
      objs_ctor()
      {
          Obj*&amp; obj = std::get&lt;Obj*&gt;(m_objs);
          assert(obj != nullptr);   // terminate if not pre-constructed
      }
  
  private:
      std::tuple&lt;Objects*...&gt;     m_objs;
  };
  </code></pre>
  
  <p>which is intended to be used as:</p>
  
  <pre><code>struct A { };
  class B {
      B() = default;
  
      template &lt;class... Ts&gt;
      friend class Foo;
  };
  
  int main() {
      // currently asserts, even though Foo&lt;A,B&gt; is a friend of B
      // and B is default-constructible to its friends
      Foo&lt;A, B&gt; foo(nullptr, nullptr);
  }
  </code></pre>
  
  <p>Example above asserts because <code>std::is_default_constructible&lt;B&gt;::value</code> is false, even though <code>B</code> has a [private] default ctor and <code>Foo&lt;A,B&gt;</code> is friend of B.</p>