title: c++ understanding the syntax of templates, typename
body: <p>I am new to <code>c++</code> but I have enough <code>Java</code> knowledge from the past to understand the concept of generics; I have been a python dev for many years now.</p>
  
  <p>I am learning <code>c++</code> by examples and I came across this code for a generics implementation of <code>merge sort</code>.</p>
  
  <pre><code>template&lt;typename I&gt;
  void doMerge(I begin, I midPoint, I end)
  {
      typename std::vector&lt;typename std::iterator_traits&lt;I&gt;::value_type&gt; TmpVec;
  
      TmpVec tmp(std::make_move_iterator(begin), std::make_move_iterator(end));
  
      TmpVec::iterator   beginAlt   = std::begin(tmp);
      TmpVec::iterator   endAlt     = std::end(tmp);
      TmpVec::iterator   midAlt     = std::next(beginAlt, std::distance(begin, midPoint));
  
  
      TmpVec::iterator   l   = beginAlt
      TmpVec::iterator   r   = midAlt;
      I                  i   = begin;
  
      while(l &lt; midAlt &amp;&amp; r &lt; endAlt)
      {
          *i = std::move((*l &lt; *r) ? *l++ : *r++);
          ++i;
      }
      while(l &lt; midAlt)
      {   *i  = std::move(*l++);
          ++i;
      }
      while(r &lt; endAlt)
      {   *i  = std::move(*r++);
          ++i;
      }
  }
  template&lt;typename I&gt;
  void mergeSort(I begin, I end)
  {
      std::size_t length  = std::distance(begin, end);
      if (length &lt;= 1)
      {   return;
      }
  
      std::size_t mid      = length/2;
      I           midPoint = std::next(begin, mid);
  
      mergeSort(begin, midPoint);
      mergeSort(midPoint, end);
  
      doMerge(begin, midPoint, end);
  }
  </code></pre>
  
  <p>I am using <code>g++</code> to compile from a <code>Makefile</code> with the following command</p>
  
  <pre><code>g++ -std=c++98 merge_sort.cpp -o mergesort.out
  
  merge_sort.cpp:34:11: error: expected ';' after expression
      TmpVec tmp(std::make_move_iterator(begin), std::make_move_iterator(end));
  </code></pre>
  
  <p>Can someone explain the compile error and provide some insight into the following parts:</p>
  
  <pre><code>template&lt;typename I&gt;
  void doMerge(I begin, I midPoint, I end)
  </code></pre>
  
  <p>The <code>template</code> keyword allows the function to accept a generic Iterator, correct? But why can I not define one global <code>template</code> in a header file to use in all functions in this code file?</p>