title: Is it a good practice to not to separate function declarations and definitions for templated classes?
body: <p>Generally in non templated classes, we separate the function declarations and definitions into separate files (.h and .cpp)</p>
  
  <p>[1] But the above practice does not seem to work very good with templated classes. Is it advised to write implementations in a separate file and then include it at the bottom of .h file ?</p>
  
  <p>[2] Which of the below scheme is generally advised for templated classes? <br/>
  [a] declarations and definition all at once or <br/>
  [b]seperated declarations &amp; definitions in the same file</p>
  
  <p>Given the complicated syntax that we have to take care of if we go by choice [b]</p>
  
  <p>Eg.
  [a]</p>
  
  <pre><code>template &lt;typename T&gt;
  class unique_ptr final {
    private:
      T* ptr_;
    public:
      unique_ptr (T* ptr = nullptr) noexcept {
        : ptr_{ ptr } {
      }
  
      friend bool operator == (const unique_ptr&amp; lhs, const unique_ptr&amp; rhs) {
        return lhs.get() == rhs.get();
      }
  };
  </code></pre>
  
  <p>[b]</p>
  
  <pre><code>template &lt;typename T&gt;
  class unique_ptr final {
    private:
      T* ptr_;
    public:
      unique_ptr (T* ptr = nullptr) noexcept;      
      friend bool operator == (const unique_ptr&amp; lhs, const unique_ptr&amp; rhs);
  
  /*** implementations inside the class after all declarations (I am not sure if this makes the code code any easier to understand)  ***/
    };
  
  /**** Implementations outside the class ***/
  /***  Convoluted things needed to make friend functions work ***/
  /** like mentioned in : https://stackoverflow.com/questions/3989678/c-template-friend-operator-overloading  ***/
  </code></pre>