<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[ADL und C++11 Alias templates]]></title><description><![CDATA[<p>Hallo,</p>
<p>wie kann ich in folgendem Beispiel erreichen, das der operator- durch ADL gefunden wird?</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
class Foo {};

namespace test {
        template &lt;class T&gt;
        using Test = Foo&lt;T&gt;;

        template &lt;typename T&gt;
        void operator-(Test&lt;T&gt;, Test&lt;T&gt;) {}
}

int main() {
        test::Test&lt;int&gt;() - test::Test&lt;int&gt;();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/306659/adl-und-c-11-alias-templates</link><generator>RSS for Node</generator><lastBuildDate>Fri, 07 Aug 2026 16:40:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/306659.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 03 Aug 2012 17:50:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ADL und C++11 Alias templates on Fri, 03 Aug 2012 17:50:20 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>wie kann ich in folgendem Beispiel erreichen, das der operator- durch ADL gefunden wird?</p>
<pre><code class="language-cpp">template &lt;typename T&gt;
class Foo {};

namespace test {
        template &lt;class T&gt;
        using Test = Foo&lt;T&gt;;

        template &lt;typename T&gt;
        void operator-(Test&lt;T&gt;, Test&lt;T&gt;) {}
}

int main() {
        test::Test&lt;int&gt;() - test::Test&lt;int&gt;();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2238460</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2238460</guid><dc:creator><![CDATA[pyhax]]></dc:creator><pubDate>Fri, 03 Aug 2012 17:50:20 GMT</pubDate></item><item><title><![CDATA[Reply to ADL und C++11 Alias templates on Fri, 03 Aug 2012 18:05:46 GMT]]></title><description><![CDATA[<p>Bin nicht ganz sicher:</p>
<pre><code class="language-cpp">template &lt;typename T&gt; 
class Foo {}; 

namespace test { 
        template &lt;class T&gt; 
        using Test = Foo&lt;T&gt;; 

        template &lt;typename T&gt; 
        void operator-(Test&lt;T&gt;, Test&lt;T&gt;) {} 
} 

int main() { 
        using namespace test;
        test::Test&lt;int&gt;() - test::Test&lt;int&gt;(); 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2238468</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2238468</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Fri, 03 Aug 2012 18:05:46 GMT</pubDate></item><item><title><![CDATA[Reply to ADL und C++11 Alias templates on Fri, 03 Aug 2012 18:56:38 GMT]]></title><description><![CDATA[<p>Das würde gehen, allerdings muss ich dann immer using namespace test; schreiben. Kennt jemand eine andere Möglichkeit?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2238488</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2238488</guid><dc:creator><![CDATA[pyhax]]></dc:creator><pubDate>Fri, 03 Aug 2012 18:56:38 GMT</pubDate></item><item><title><![CDATA[Reply to ADL und C++11 Alias templates on Fri, 03 Aug 2012 18:59:56 GMT]]></title><description><![CDATA[<p>Machs halt am Anfang des Sourcefiles hin. Und sonst machst du daraus eine freie Funktion. Probleme mit einem Nameclash wirst du nicht haben, weil du ja eine entsprechend eindeutige Überladung anbietest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2238489</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2238489</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Fri, 03 Aug 2012 18:59:56 GMT</pubDate></item><item><title><![CDATA[Reply to ADL und C++11 Alias templates on Fri, 03 Aug 2012 19:08:39 GMT]]></title><description><![CDATA[<p>Das Problem ist, dass Test nicht ein anderer Typ ist, sondern er ist der selbe Typ wie Foo.</p>
<p>Deses using ist nur ein Typedef - mehr nicht.</p>
<p>Deshalb die Gretchen Frage: was willst du denn erreichen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2238494</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2238494</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Fri, 03 Aug 2012 19:08:39 GMT</pubDate></item><item><title><![CDATA[Reply to ADL und C++11 Alias templates on Fri, 03 Aug 2012 21:44:51 GMT]]></title><description><![CDATA[<p>pyhax schrieb:</p>
<blockquote>
<p>wie kann ich in folgendem Beispiel erreichen, das der operator- durch ADL gefunden wird?</p>
</blockquote>
<p>Durch ADL gar nicht.</p>
<blockquote>
<p>If T is a class type (including unions), its associated classes are: the class itself; the class of which it is a<br />
member, if any; and its direct and indirect base classes. <strong>Its associated namespaces are the namespaces<br />
of which its associated classes are members.</strong> Furthermore, if T is a class template specialization,<br />
its associated namespaces and classes also include: the namespaces and classes associated with the<br />
types of the template arguments provided for template type parameters (excluding template template<br />
parameters); the namespaces of which any template template arguments are members; and the classes<br />
of which any member templates used as template template arguments are members. [ Note: Non-type<br />
template arguments do not contribute to the set of associated namespaces. — end note ]</p>
</blockquote>
<p>Die Klasse lebt im globalen Namensraum, unabhängig davon, dass der gewählte Bezeichner, der auf sie verweist, zufällig in test lebt. test ist damit nicht assoziert mit test::Test&lt;T&gt;, es sei denn, T ist selbst mit test assoziert. Alternativ könnte man auch Foo von einer Klasse in test erben lassen.</p>
<pre><code class="language-cpp">namespace test { struct dummy {}; }

template &lt;typename T, typename = test::dummy&gt;
class Foo {};

namespace test {
        template &lt;class T&gt;
        using Test = Foo&lt;T&gt;;

        template &lt;typename T&gt;
        void operator-(Test&lt;T&gt;, Test&lt;T&gt;) {}
}

int main() {
        test::Test&lt;int&gt;() - test::Test&lt;int&gt;();
}
</code></pre>
<pre><code class="language-cpp">namespace test { struct dummy {}; }

template &lt;typename T&gt;
class Foo : private dummy {};

namespace test {
        template &lt;class T&gt;
        using Test = Foo&lt;T&gt;;

        template &lt;typename T&gt;
        void operator-(Test&lt;T&gt;, Test&lt;T&gt;) {}
}

int main() {
        test::Test&lt;int&gt;() - test::Test&lt;int&gt;();
}
</code></pre>
<p>In jedem Fall ist es das Klassentemplate, um das es geht, wie und wo das Aliastemplate deklariert wird, spielt keine Rolle.</p>
<p>Als Merkregel: eine Klasse (oder ein Template) lebt in dem Namensraum, in dem sie definiert wird. Damit kriegt man auch den Fall namenloser Klassen in den Griff.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2238510</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2238510</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 03 Aug 2012 21:44:51 GMT</pubDate></item></channel></rss>