title: Can I template user-defined literals?
body: <p>Suppose I have some class:</p>
  
  <pre><code>template &lt;typename T&gt;
  class Foo {
    const T* x_;
  public:
    Foo(const T* str) : x_{str} {}
  };
  </code></pre>
  
  <p>and I provide some user-defined literals that create a <code>Foo</code> object:</p>
  
  <pre><code>Foo&lt;char&gt; operator"" _foo(const char* str, std::size_t) {
    return Foo&lt;char&gt;{str};
  }
  
  Foo&lt;wchar_t&gt; operator"" _foo(const wchar_t* str, std::size_t) {
    return Foo&lt;wchar_t&gt;{str};
  }
  
  // etc. for char16_t and char32_t.
  </code></pre>
  
  <p>My question is this: why can I not template these and save having to rewrite code?</p>
  
  <pre><code>template &lt;typename T&gt;
  Foo&lt;T&gt; operator"" _foo(const T* str, std::size_t) {
    return Foo&lt;T&gt;{str};
  }
  </code></pre>
  
  <p>gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) and 7.0.0 (compiled myself) report:</p>
  
  <pre><code>error: ‘Foo&lt;T&gt; operator""_foo(const T*, std::size_t)’ has invalid argument list
  Foo&lt;T&gt; operator"" _foo(const T* str, std::size_t) {
                                                  ^
  </code></pre>
  
  <p>The error message seems to be clear enough, but I don't see a reason why I shouldn't be allowed to do this in principle; so, am I doing this incorrectly, or is this genuinely not allowed?</p>