title: Why can't a struct be passed as value as template non-type parameter?
body: <p>Non-type template parameters are obviously ones that <em>aren't types</em>, for example:</p>
  
  <pre><code>template&lt;int x&gt;
  void foo() { cout &lt;&lt; x; }
  </code></pre>
  
  <p>There are other options than <code>int</code> in that case, and I'd like to refer to <a href="https://stackoverflow.com/a/5687553/752976">this great answer</a>.</p>
  
  <p>Now, there's one thing that bugs me: structs. Consider:</p>
  
  <pre><code>struct Triple { int x, y, z; };
  
  Triple t { 1, 2, 3 };
  
  template&lt;Triple const&amp; t&gt;
  class Foo { };
  </code></pre>
  
  <p>Now, using normal nontype reference semantics, we can write:</p>
  
  <pre><code>Foo&lt;t&gt; f;
  </code></pre>
  
  <p>What's worth noting here is that <code>t</code> <em>can't</em> be <code>constexpr</code> or even <code>const</code>, because that implies internal linkage, which basically means that the line won't compile. We can bypass that by declaring <code>t</code> as <code>const extern</code>. That itself might be a bit weird, but the one that really made me wonder was why this isn't possible:</p>
  
  <pre><code>Foo&lt;Triple { 1, 2, 3 }&gt; f;
  </code></pre>
  
  <p>We get a really decent error from compiler:</p>
  
  <blockquote>
    <p>error: <code>Triple{1, 2, 3}</code> is not a valid template argument for type <code>const Triple&amp;</code> because it is not an lvalue.</p>
  </blockquote>
  
  <p>We can't specify <code>Triple</code> in template by value, because that's disallowed. However, I fail to understand the <em>real</em> problem with that small line of code. What's the reasoning behind not allowing using structs as value parameters. If I can use three <code>int</code>s, why not a struct of three ints? If it has only trivial special members, it shouldn't be really different in handling than just three variables.</p>