Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ : variable template parameters (for genetic algorithm)
    text
    copied!<p>I'm writing a parallel evolutionary algorithm library using C++, MPI and CUDA. I need to extract the raw data from my object oriented design and stick it into a flat array (or std::vector using <a href="http://clustertech.com/index.php?Download:STL-MPI_Library" rel="nofollow noreferrer">stl-mpi</a>) for it to be sent across to nodes or the cuda device.</p> <p>The complete design is quite complex with a lot of inheritance to keep the library flexible. But the classes of interest are:</p> <p><strong>Genome class</strong> - contains vector of data. e.g. floats or bools.</p> <p><strong>Population class</strong> - contains vector of Genome objects and is initailised with a genome object.</p> <p>First a genome object is created, then a reference to it is passed to population class constructor which creates its own vector of genomes based on passed one. (Hope that makes sense!)</p> <p>So I thought I would add another member vector, say <code>rawData</code> to the population class. But the type of rawData would need to depend on the type of data stored in the genomes (or the original genome object).<br> Here lies the problem, as far as I am aware there is no way to dynamically set the type passed to template.</p> <p>my pseudo-code would be</p> <pre><code>class genome { std::vector&lt;bool&gt; data; } template &lt;class T&gt; class population { std::vector&lt;genome&gt; population; std::vector&lt;T&gt; rawData; void PackDataIntoRawData(); }; </code></pre> <p>then when i create the population (which is actually a member object of another class), I would call:</p> <pre><code>genome myBitGenome(); population&lt;type of myBitGenome.data&gt; pop(myBitGenome); </code></pre> <p>Is there anyway to do this, or can anyone suggest another way to implement this.</p> <p>Thanks in advance</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