<p>Hi!<br>
I have been considering different approaches to this problem.<br>
We want a data type to represent a generic neighbor search class, no matter which tree type is considered. However, we want to distinguish between KDTree/BallTree and the rest of tree types, because we want to set the leaf size in the former and the NeighborSearch Class doesn't provide a general option for that. This is the reason of the difference in the code, between KDTrees/BallTrees and the rest of the tree types.<br>
So, as you suggested, I considered three possible approaches:</p>

<ul>
<li><p>Add TreeType as a template parameter and use SFINAE to decide if the tree should be built with specific leafSize or not. It involved a lot of lines of code...</p></li>
<li><p>Create a generic NeighborSearchGen class, and make NeighborSearch class inherit from it. Then, I implemented a NeighborSearchLeaf class that encapsulates an instance of NeighborSearch class, and adds the functionality to deal with different leaf sizes. It is implemented in: <a href="https://github.com/MarcosPividori/mlpack/tree/improve-nsmodel">https://github.com/MarcosPividori/mlpack/tree/improve-nsmodel</a></p></li>
<li>
<p>Finally I considered boost variant:</p>

<pre><code>  boost::variant&lt;NSType&lt;SortPolicy, tree::KDTree&gt;*,
                 NSType&lt;SortPolicy, tree::StandardCoverTree&gt;*,
                 NSType&lt;SortPolicy, tree::RTree&gt;*,
                 NSType&lt;SortPolicy, tree::RStarTree&gt;*,
                 NSType&lt;SortPolicy, tree::BallTree&gt;*,
                 NSType&lt;SortPolicy, tree::XTree&gt;*&gt; nSearch;
</code></pre>

<p>I use template specialization in the visitors to decide if the leafSize should be considered or not.<br>
This is by far the simplest option, which include the least changes in actual code. Also, it only uses inheritance when defining the visitors, so I think it won't be confusing. It is implemented in: <a href="https://github.com/MarcosPividori/mlpack/tree/variants-for-ns-model">https://github.com/MarcosPividori/mlpack/tree/variants-for-ns-model</a></p>
</li>
</ul>

<p>What do you think? I made a pull request in : <a href="https://github.com/mlpack/mlpack/pull/693" class="issue-link js-issue-link" data-url="https://github.com/mlpack/mlpack/issues/693" data-id="159961483" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#693</a> </p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/mlpack/mlpack/issues/674#issuecomment-225604519">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe/AJ4bFO-k1agDmKmpnCtsF_TSbyRoDUyyks5qLW5ugaJpZM4It4UX">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFHTB8uwWXEO5JlSVMrh88cSs-qX-ks5qLW5ugaJpZM4It4UX.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/mlpack/mlpack/issues/674#issuecomment-225604519"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>