Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If it is possible for your use-case, you could do specialization on a namespace basis and then aggregate as follows, using C++11 since you mentioned it but can work without.</p> <p>Assume you have a number of namespaces <code>ns_1</code> to <code>ns_k</code> like this:</p> <pre><code>namespace ns_i { template&lt;class T&gt; struct my_int: std::integral_constant&lt;int, -1&gt; {}; /*...*/ enum e_1 { /*...*/ }; template&lt;&gt; struct my_int&lt;e_1&gt;: std::integral_constant&lt;int, 101&gt; {}; /*...*/ enum e_n { /*...*/ }; template&lt;&gt; struct my_int&lt;e_n&gt;: std::integral_constant&lt;int, 142&gt; {}; /*...*/ } </code></pre> <p>I assume you already have the means to do a unique numbering. Then you aggregate the <code>my_int</code> from all namespaces like this:</p> <pre><code>namespace your_lib { template&lt; class T, template&lt;class&gt; class sources... /* any number of template classes, each taking one type argument */ &gt; struct Union: std::integral_constant&lt;int, -1&gt; {}; // default -1 for (empty template list) template&lt; class T, template&lt;class&gt; class source, // match first template template&lt;class&gt; class sources... // match all but first template &gt; struct Union&lt;T, source, sources...&gt;: std::conditional&lt; source::value == -1, union&lt;T, sources...&gt;, // recursively call union on all but first tempalte source // or if there's a value in first, use it &gt; {}; template&lt;class T&gt; struct my_int : Union&lt;T, ns_1::my_int, /*...,*/ ns_k::my_int&gt; {}; /* here you could use boost preprocessor to iterate over the namespaces since you mentionned it */ } </code></pre>
 

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