Note that there are some explanatory texts on larger screens.

plurals
  1. POClass template and condition checking
    primarykey
    data
    text
    <p>This is probably a really obvious question but I want to be sure about it before going on with my development.</p> <p>I have a templated class something like:</p> <pre><code>template&lt;TypeA var1, TypeB var2&gt; class myClass { //Attributes ... //Methods ... void checkHit(vector&lt;Real&gt;* path, vector&lt;bool&gt;* active) { for(int i = 0; i &lt; N; i++) { //Some process bool hit = ((var1 == Up) || (var1 == Down)); } //... bool flag = ((var2 == Left) || (var2 == Right)); } } </code></pre> <p>If I create and object like</p> <pre><code>myClass obj&lt;Up, Right&gt;(...); </code></pre> <p>When executing the method</p> <pre><code>obj.checkHit( ... ); </code></pre> <p>Will the program just check for <code>bool hit = ((var1 == Up)</code> and <code>(var2 == Right)</code> ?? In other words, will the compiler throw away the code that doesn't has to do with the template-parameters passed? What I mean is if the resulting code after compiling will be something like</p> <pre><code>template&lt;TypeA var1, TypeB var2&gt; class myClass { //Attributes ... //Methods ... void checkHit(vector&lt;Real&gt;* path, vector&lt;bool&gt;* active) { for(int i = 0; i &lt; N; i++) { //Some process bool hit = ((var1 == Up)); //Like if I have never put "|| (var1 == Down));" } //... bool flag = ((var2 == Right)); } } </code></pre> <p>Hope the example is clear enough, I just simplified (a lot) the real code but it should be roughly equivalent. If it isn't clear just tell and I will gladly improve it.</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.
 

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