How can I create a constexpr function that returns a type (to be used in a template parameter)
<p>I'm looking for some way to create a class, with a template parameter type, based on a template parameter number.</p>

<p>What I'm trying to do is something like this:</p>

<pre><code>template&lt;size_t n&gt;
constexpr auto type_from_size() {
    if(n &lt; 256) {
        return uint8_t;
    } else {
        return uint16_t;
    }
}

template&lt;size_t n&gt;
class X {
    type_from_size&lt;n&gt;() t;
}

X&lt;500&gt; x;
x.t = 500;
</code></pre>

<p>So, in the code above, the <code>constexpr</code> function <code>type_from_size()</code> would receive the number 500 and would return the type <code>uint16_t</code>, and this would be the type of the member <code>X.t</code>.</p>

<p>I know this is obviously terrible code, but is this possible using templates?</p>