title: C++ : how do I use type_traits to determine if a class is trivial?
body: <p>In C++0x, I would like to determine if a class is trivial/has standard layout so I can use memcpy(), memset(), etc...  </p>
  
  <p>How should I implement the code below, using type_traits, so I can confirm that a type is trivial?</p>
  
  <pre><code>template&lt; typename T &gt;
  bool isTrivialType()
  {
    bool isTrivial = ???
    return isTrivial;
  }
  </code></pre>
  
  <p>NOTE: is_pod() is too restrictive: I would like my class to have trivial constructors, etc... ...for convenience.</p>
  
  <p>Added:  I think std::is_standard_layout&lt;> may give me what I'm looking for.
  1. If I add constructors, it still returns true
  2. If I add a virtual method, it returns false
  This is what I need to determine if I can use memcpy(), memset()</p>
  
  <p>Edit:  From Luc Danton's explanation and link below (clarification):</p>
  
  <pre><code>struct N { // neither trivial nor standard-layout
     int i;
     int j;
      virtual ~N();
  };
  
  struct T { // trivial but not standard-layout
      int i;
  private:
      int j;
  };
  
  struct SL { // standard-layout but not trivial
      int i;
      int j;
      ~SL();
  };
  
  struct POD { // both trivial and standard-layout
      int i;
      int j;
  };
  </code></pre>
  
  <p>For memcpy() to be happy:</p>
  
  <pre><code>// N -&gt; false
  // T -&gt; true
  // SL -&gt; ??? (if there are pointer members in destructor, we are in trouble)
  // POD -&gt; true
  </code></pre>
  
  <p>So it does look like is_trivial_class&lt;> is correct: is_standard_layout&lt;> is not necessarily right...</p>