title: Template function to return template type
body: <p>I have the following function but my compiler (VS2003) says that the assignement T = .... is illegal.  Can someone clarify what I've done wrong?  The type of value is a boost::variant.  node is a struct.</p>
  
  <pre><code> template &lt;typename T&gt;
      T find_attribute(const std::string&amp; attribute)
      {
  
          std::vector&lt;boost::shared_ptr&lt;node&gt; &gt;::iterator nodes_iter = _request-&gt;begin();
  
          for (; nodes_iter != _request-&gt;end(); nodes_iter++)
          {
              std::vector&lt;node::attrib&gt;::iterator att_iter = (*nodes_iter)-&gt;attributes.begin();
              for (; att_iter != att_iter; (*nodes_iter)-&gt;attributes.end())
              {
                  if ((*att_iter).key.compare(attribute) == 0) {
                      T = (*att_iter).value;  //T : Illegal use of this type as an expression.
                                      return T; 
                              }
  
              }
  
          }
      }
  </code></pre>