Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In general compilers are not aggressive at inlining calls through function pointers, even when they are known at compile time. </p> <p>In this case you are relying on the compiler being clever enough to unroll the loop into a block of numberOfWovenFunctions iterations, or generate a switch of the inlined functions for you, both of which are unlikely.</p> <p>If you wanted to make the idiom more generic you could do so with a recursive templates (it would be a pain to write if you do not have c++11 variadic templates), though whether it actually constitutes a simplification is perhaps questionable.</p> <p>i.e. you template on the list of woven function pointer values, and at each level call the woven function, store the result, call sendPacket and the recurse into the next template level with the stored result. Something like (untested):</p> <pre><code>template &lt;InterlacedFunction ... args&gt; struct WovenFunc; //Base case - send remaining packets template &lt;&gt; struct WovenFunc&lt;&gt;{ static int call(int value, int * packet, size_t count){ for(size_t c = 0; c &lt; count; ++c) SendData(packet[c]); return value; } }; //Recursive case - send packets + weave functions template &lt;InterlacedFunction arg, InterlacedFunction ... args&gt; struct WovenFunc&lt;arg, args...&gt;{ static int call(int initial, int * packets, size_t count){ int r = arg(initial); SendData(packets[0]); if(count) return WovenFunc&lt;args...&gt;::call(r, packets + 1, count - 1); } }; </code></pre> <p>And then in the send:</p> <pre><code>typedef WovenFunc&lt;Woven1, Woven2, Woven3&gt; WovenSend WovenSend::call(returnFromLastWoven, packets, packetLength); </code></pre> <p>Obviously you can make is more generic.</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.
 

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