title: template function with pqxx results
body: <p>This is on os x yosemite with clang from xcode 7.2 in clion.</p>
  
  <p>I'm iterating through a query from a postgresql db and adding the result to a json object.</p>
  
  <pre><code>for (pqxx::result::const_iterator c = R.begin(); c != R.end(); ++c) {
      participants["participants"] += { \
          {"id", c[0].as&lt;std::string&gt;()},
          {"location", c[1].as&lt;std::string&gt;()},
          {"racename", c[2].as&lt;std::string&gt;()},
          {"racestart_at", c[3].as&lt;std::string&gt;()},
          {"ended_at", static_cast&lt;bool&gt;(c[9].size()) ? c[9].as&lt;std::string&gt;() : ""},
          {"racetime", static_cast&lt;bool&gt;(c[10].size()) ? c[10].as&lt;std::string&gt;() : ""}
      };
  }
  </code></pre>
  
  <p>Some of the columns have null values so I test for that casting to bool in a ternary operator and either return the result or an empty string. To make it a bit cleaner I tried to add a template function with the example from <a href="http://www.cprogramming.com/tutorial/templated_functions.html" rel="nofollow noreferrer">http://www.cprogramming.com/tutorial/templated_functions.html</a> and had this:</p>
  
  <pre><code>template &lt;class T&gt;
  std::string column_content(T a) {
      return static_cast&lt;bool&gt;(a.size()) ? a.as&lt;std::string&gt;() : "";
  }
  </code></pre>
  
  <p>When I try to compile the program I get the error:</p>
  
  <pre><code>Database.cpp:9:44: error: use 'template' keyword to treat 'as' as a dependent template name
  return static_cast&lt;bool&gt;(a.size()) ? a.as&lt;std::string&gt;() : "";
                                         ^
                                         template 
  </code></pre>
  
  <p>I looked at <a href="https://stackoverflow.com/questions/9764295/cast-chars-to-int-in-template-function">Cast Chars To Int in Template Function</a> and <a href="http://www.cplusplus.com/doc/oldtutorial/templates/" rel="nofollow noreferrer">http://www.cplusplus.com/doc/oldtutorial/templates/</a> and other suggestions from google but it looks like I'm using the wrong syntax but I can't spot it.</p>
  
  <p>If I could use a template function adding to json could then look like</p>
  
  <pre><code>{"start_at", column_content(c[8])}
  </code></pre>
  
  <p>regards
  Claus</p>