title: Can I have a single template with a variable object?
body: <p>I currently have the following code:</p>
  
  <pre><code>template&lt; class Obj, class ObjResult &gt;
  CLStatus convertObjToResult2( const Obj &amp; xFrom, ObjResult &amp; xTo )
  {
      CLStatus eStatus = CLSTATUS_SUCCESS;
      switch ( xTo.eType )
      {
          case CEPTFull:
              xTo.xData.xFull = xFrom;
              break;
          case CEPTBrief:
              eStatus = Convert( xFrom, xTo.xData.xBrief );
              break;
          default:
              eStatus = CLSTATUS_INVALIDPROJECTIONTYPE;
      }
      return eStatus;
  }
  
  template&lt; class Obj, class ObjResult &gt;
  CLStatus convertObjToResult1( const Obj &amp; xFrom, ObjResult &amp; xTo )
  {
      CLStatus eStatus = CLSTATUS_SUCCESS;
      switch ( xTo.eType )
      {
          case CEPTFull:
              xTo.xData.xFull = xFrom;
              break;
          default:
              eStatus = CLSTATUS_INVALIDPROJECTIONTYPE;
      }
      return eStatus;
  }
  </code></pre>
  
  <p>All ObjResults have an <code>xFull</code>, but only some have an <code>xBrief</code>, where xData is a <code>union</code>. This resulted in me writing the two different templates above, but it would be great if I could somehow have just one template.</p>
  
  <p>I can't simply use <code>convertObjToResult2</code>, since it will fail to compile with object types that do not have an <code>xBrief</code>. I looked at <a href="https://stackoverflow.com/questions/5768511/using-sfinae-to-check-for-global-operator">this answer</a> to see if it would help, but I don't understand at all what it's doing.</p>