Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>The essence is from the comment of WhozCraig</strong>:</p> <p>When you drop the T* in both templates the program will compile (with warnings -Wreorder) and give the expected output.</p> <pre><code>operator&lt;&lt;(std::ostream&amp; stream, X&lt;H*,T...&gt; const &amp; x) operator&lt;&lt;(std::ostream&amp; stream, X&lt;vector&lt;V*&gt;*, T...&gt; const &amp; x) </code></pre> <p>After going through [14] Templates without any enlightenment, I think there is a compiler bug.</p> <p>A modified test:</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;boost/type_traits/is_fundamental.hpp&gt; #include &lt;boost/utility/enable_if.hpp&gt; using namespace std; #define USE_VARIADIC_TEMPLATE 1 #define USE_AMBIGUOUS 1 template &lt;typename ... T&gt; struct X; template &lt;&gt; struct X &lt;&gt; { }; template &lt;typename H, typename ... T&gt; struct X&lt;H*,T*...&gt; : public X&lt;T*...&gt; { H* value; X(H* value, T*... args) : X&lt;T*...&gt;(args...), value(value) {} }; #if USE_VARIADIC_TEMPLATE template &lt;typename H, typename ... T&gt; #if USE_AMBIGUOUS std::ostream&amp; operator&lt;&lt;(std::ostream&amp; stream, X&lt;H*,T*...&gt; const &amp; x) #else std::ostream&amp; operator&lt;&lt;(std::ostream&amp; stream, X&lt;H*,T...&gt; const &amp; x) #endif #else template &lt;typename H, typename T&gt; std::ostream&amp; operator&lt;&lt;(std::ostream&amp; stream, X&lt;H*, T*&gt; const &amp; x) #endif { return stream &lt;&lt; "specialized scalar pointer"; } #if USE_VARIADIC_TEMPLATE template &lt;typename V, typename ... T&gt; #if USE_AMBIGUOUS std::ostream&amp; operator&lt;&lt;(std::ostream&amp; stream, X&lt;vector&lt;V*&gt;*,T*...&gt; const &amp; x) #else std::ostream&amp; operator&lt;&lt;(std::ostream&amp; stream, X&lt;vector&lt;V*&gt;*,T...&gt; const &amp; x) #endif #else template &lt;typename V, typename T&gt; std::ostream&amp; operator&lt;&lt;(std::ostream&amp; stream, X&lt;vector&lt;V*&gt;*, T*&gt; const &amp; x) #endif { return stream &lt;&lt; "specialized vector pointer"; } int main() { double a,b; vector&lt;double *&gt; v; X&lt;double*,double*&gt; x (&amp;a,&amp;b); X&lt;vector&lt;double*&gt;*, double*&gt; y (&amp;v, &amp;b); cout &lt;&lt; x &lt;&lt; endl; cout &lt;&lt; y &lt;&lt; endl; // this line is ambiguous according to gcc 4.6 and later } </code></pre> <p>Even the case:</p> <pre><code>template &lt;typename H, typename T&gt; std::ostream&amp; operator&lt;&lt;(std::ostream&amp; stream, X&lt;H*, T*&gt; const &amp; x) template &lt;typename V, typename T&gt; std::ostream&amp; operator&lt;&lt;(std::ostream&amp; stream, X&lt;vector&lt;V*&gt;*, T*&gt; const &amp; x) </code></pre> <p>compiles nicely.</p> <p><strong>Edit</strong>: If the variadic template hold just one T passed as T* it should be the simple case shown above.</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