Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>template&lt;typename T&gt; struct is_io_type : std::false_type {}; template&lt;&gt; struct is_io_type&lt;int&gt; : std::true_type {}; template&lt;&gt; struct is_io_type&lt;double&gt; : std::true_type {}; template&lt;&gt; struct is_io_type&lt;std::string&gt; : std::true_type {}; </code></pre> <p>Then, instead of your macro, simply type:</p> <pre><code>static_assert( is_io_type&lt;T&gt;::value, "Type not defined for this template." ) </code></pre> <p>which is about as verbose and not nearly as obscure or hard to figure out what the heck is going on.</p> <p>Now, suppose we really need the <code>is_base_of</code> functionality.</p> <pre><code>template&lt;typename T,typename=void&gt; struct is_io_type : std::false_type {}; template&lt;&gt; struct is_io_type&lt;int,void&gt; : std::true_type {}; template&lt;typename T&gt; struct is_io_type&lt;T,typename std::enable_if&lt;std::is_base_of&lt;int, T&gt;::type&gt; : std::true_type {}; template&lt;&gt; struct is_io_type&lt;double,void&gt; : std::true_type {}; template&lt;typename T&gt; struct is_io_type&lt;T,typename std::enable_if&lt;std::is_base_of&lt;double, T&gt;::type&gt; : std::true_type {}; template&lt;&gt; struct is_io_type&lt;std::string,void&gt; : std::true_type {}; template&lt;typename T&gt; struct is_io_type&lt;T,typename std::enable_if&lt;std::is_base_of&lt;std::string, T&gt;::type&gt; : std::true_type {}; </code></pre> <p>which gets pretty verbose.</p> <p>But rather than creating a variardic macro expansion at the point where we use the macro, we can instead use a macro to build the above type trait specializations.</p> <p>So you first create your type trait, then extend it:</p> <pre><code>CREATE_TYPE_CATEGORY( is_io_type ); ADD_BASE_TYPE_CATEGORY( is_io_type, int ); ADD_BASE_TYPE_CATEGORY( is_io_type, double ); ADD_BASE_TYPE_CATEGORY( is_io_type, std::string ); </code></pre> <p>which would write the code above a bit less verbosely. It also supports distributed trait modification: if someone creates a new type that should be <code>is_io_type</code>, they can use the above macro after introducing the type and it (and its descendents) become an io type.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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