Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>“Is there any advantage of aliasing type to value meta-functions?”</em></p> <p>Quoting from the linked N3655, before the specifications of <code>is_void_t</code> and siblings (page 4):</p> <blockquote> <h3>4 &nbsp; Supplementary proposed wording</h3> <p>The following wording is provided in response to LWG’s request that aliases for <b><code>::type</code></b> members be consistently provided for all the type traits, not only for those classified as <i>TransformationTraits</i>. Accordingly, this section provides the specifications needed in order to complete the set.</p> </blockquote> <p>That explains why <em>“type to value meta-functions (such as <code>is_void</code> ) are also type aliased”</em> in the proposal: for consistency.</p> <p>Moreover, it would be wrong to use the name “<code>is_void_<b>t</b></code>” to alias <code>is_void&lt;T&gt;::<b>value</b></code>. The “<code>_t</code>” suffix always denotes a <strong>type</strong>. For the value, maybe one could use a “<strong><code>_v</code></strong>” suffix. So we would then have both:</p> <pre><code>template &lt;class T&gt; using is_void_t = typename is_void&lt;T&gt;::type; template &lt;class T&gt; constexpr bool is_void_v = is_void&lt;T&gt;::value; </code></pre> <p>That should compile in C++14, and then you could write things like <code>enable_if_t&lt;(is_void_v&lt;T&gt; || is_integral_v&lt;T&gt;),T&gt;</code>. But I feel that the value alias is “less needed” than the type one: it doesn't save as much typing, and, as you said, you can use the short <code>is_void&lt;T&gt;{}()</code> with the same effect (and for C++11, <code>is_void&lt;T&gt;{}</code> is often enough, thanks to its <code>operator bool()</code>).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload