title: C++ templates: How to conditionally compile different code based on data type?
body: <p>Here's a small example that illustrates the essence of my question:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std ;
  typedef char achar_t ;
  
  template &lt; class T &gt; class STRING
  {
     public:
       T *    memory   ;
       int    size     ;
       int    capacity ;
     public:
       STRING() {
          size     =   0 ;
          capacity = 128 ;
          memory   = ( T *) malloc( capacity * sizeof(T) ) ;
       }
       const STRING&amp; operator=( T * buf) {
           if ( typeid(T) == typeid(char) )
              strcpy( memory, buf ) ;
           else
              wcscpy( memory, buf ) ;
          return *this ;
       }
  }  ;
  
  void main()
  {
    STRING&lt;achar_t&gt; a ;
    STRING&lt;wchar_t&gt; w ;
    a =  "a_test" ;
    w = L"w_test" ;
   cout &lt;&lt; " a = " &lt;&lt; a.memory &lt;&lt; endl ;
   cout &lt;&lt; " w = " &lt;&lt; w.memory &lt;&lt; endl ;
  }
  </code></pre>
  
  <p>Can some one please help me compile the above? That is somehow compile either with strcpy() or wcscpy() based on the type of the object i am using.</p>
  
  <p>thank you</p>