<?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[SFINAE um zu testen ob operator &amp;quot;==&amp;quot; von klassen template wirklich nutzbar ist]]></title><description><![CDATA[<p>Hi zusammen,</p>
<p>ist es mit SFINAE möglich zu testen ob der call zum == operator eines Klassen templates möglich ist?<br />
Als Beispiel soll der <code>std::vector&lt;T&gt;</code> herhalten.</p>
<p>Wenn ein type T für <code>std::vector&lt;T&gt;</code> verwendet wird, so muss dieser Typ T nicht den &quot;==&quot; operator definieren, nur wenn beim vector wirklich den code für &quot;==&quot; instantiert.</p>
<p>Hier ist mein Ansatz, er funktioniert leider nicht für klassen templates.</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;type_traits&gt;
#include &lt;vector&gt;

using namespace std;

template&lt;typename T, typename = decltype(std::declval&lt;T&gt;() == std::declval&lt;T&gt;() )&gt; 
std::true_type  supports_euqla_test(const T&amp;);
std::false_type supports_euqla_test(...);

template&lt;typename T&gt;
struct can_use_equal_operator : std::integral_constant&lt;bool, std::is_same&lt;std::true_type, 
                                                             decltype(supports_euqla_test(std::declval&lt;T&gt;()))&gt;::value&gt; {};

struct foo
{
};

int main() {
	std::vector&lt;foo&gt; obj;
	std::cout &lt;&lt; std::boolalpha &lt;&lt; 
				can_use_equal_operator&lt;decltype(obj)&gt;::value &lt;&lt; std::endl; // should return 'false', but actually returns 'true'
	//std::cout &lt;&lt; (obj == obj) &lt;&lt; std::endl; // compile error
	return 0;
}
</code></pre>
<p><a href="http://ideone.com/lqDfmn" rel="nofollow">http://ideone.com/lqDfmn</a></p>
<p>Habt Ihr ne Idee, wie man es vielleicht doch testen könnte?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/334822/sfinae-um-zu-testen-ob-operator-quot-quot-von-klassen-template-wirklich-nutzbar-ist</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Apr 2026 06:34:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/334822.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 13 Oct 2015 18:05:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SFINAE um zu testen ob operator &amp;quot;==&amp;quot; von klassen template wirklich nutzbar ist on Tue, 13 Oct 2015 18:05:51 GMT]]></title><description><![CDATA[<p>Hi zusammen,</p>
<p>ist es mit SFINAE möglich zu testen ob der call zum == operator eines Klassen templates möglich ist?<br />
Als Beispiel soll der <code>std::vector&lt;T&gt;</code> herhalten.</p>
<p>Wenn ein type T für <code>std::vector&lt;T&gt;</code> verwendet wird, so muss dieser Typ T nicht den &quot;==&quot; operator definieren, nur wenn beim vector wirklich den code für &quot;==&quot; instantiert.</p>
<p>Hier ist mein Ansatz, er funktioniert leider nicht für klassen templates.</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;type_traits&gt;
#include &lt;vector&gt;

using namespace std;

template&lt;typename T, typename = decltype(std::declval&lt;T&gt;() == std::declval&lt;T&gt;() )&gt; 
std::true_type  supports_euqla_test(const T&amp;);
std::false_type supports_euqla_test(...);

template&lt;typename T&gt;
struct can_use_equal_operator : std::integral_constant&lt;bool, std::is_same&lt;std::true_type, 
                                                             decltype(supports_euqla_test(std::declval&lt;T&gt;()))&gt;::value&gt; {};

struct foo
{
};

int main() {
	std::vector&lt;foo&gt; obj;
	std::cout &lt;&lt; std::boolalpha &lt;&lt; 
				can_use_equal_operator&lt;decltype(obj)&gt;::value &lt;&lt; std::endl; // should return 'false', but actually returns 'true'
	//std::cout &lt;&lt; (obj == obj) &lt;&lt; std::endl; // compile error
	return 0;
}
</code></pre>
<p><a href="http://ideone.com/lqDfmn" rel="nofollow">http://ideone.com/lqDfmn</a></p>
<p>Habt Ihr ne Idee, wie man es vielleicht doch testen könnte?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470888</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470888</guid><dc:creator><![CDATA[Nash26]]></dc:creator><pubDate>Tue, 13 Oct 2015 18:05:51 GMT</pubDate></item><item><title><![CDATA[Reply to SFINAE um zu testen ob operator &amp;quot;==&amp;quot; von klassen template wirklich nutzbar ist on Tue, 13 Oct 2015 21:34:02 GMT]]></title><description><![CDATA[<pre><code>template &lt;typename, typename=bool&gt; struct EqualityComparable : std::false_type{};
template &lt;typename T&gt; struct EqualityComparable&lt;T, decltype(bool(std::declval&lt;T const&amp;&gt;() == std::declval&lt;T const&amp;&gt;()))&gt; : std::true_type{};
</code></pre>
<p>(ungetestet)<br />
Oder, mittels concepts:</p>
<pre><code>template &lt;typename T&gt;
concept bool EqualityComparable = requires (T const a, T const b) {{a == b} -&gt; bool;}
</code></pre>
<p>(ebenfalls ungetestet)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470915</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470915</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Tue, 13 Oct 2015 21:34:02 GMT</pubDate></item><item><title><![CDATA[Reply to SFINAE um zu testen ob operator &amp;quot;==&amp;quot; von klassen template wirklich nutzbar ist on Tue, 13 Oct 2015 21:37:24 GMT]]></title><description><![CDATA[<blockquote>
<p>// should return 'false', but actually returns 'true'</p>
</blockquote>
<p>Der <code>operator==</code> von <code>vector</code> wendet nicht selbst SFINAE an, kann also lediglich einen hard error liefern. Du musst schon für den <code>value_type</code> testen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470917</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Tue, 13 Oct 2015 21:37:24 GMT</pubDate></item><item><title><![CDATA[Reply to SFINAE um zu testen ob operator &amp;quot;==&amp;quot; von klassen template wirklich nutzbar ist on Tue, 13 Oct 2015 21:40:36 GMT]]></title><description><![CDATA[<p>das mit <code>std::vector&lt;T&gt;</code> ist nur ein Beispiel, mir geht es um eine generelle Lösung für alle template typen.<br />
Kann ich mit SFINAE feststellen ob der Aufruf zu einem operator (bsp. &quot;==&quot;) möglich ist oder nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2470919</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2470919</guid><dc:creator><![CDATA[Nash26]]></dc:creator><pubDate>Tue, 13 Oct 2015 21:40:36 GMT</pubDate></item><item><title><![CDATA[Reply to SFINAE um zu testen ob operator &amp;quot;==&amp;quot; von klassen template wirklich nutzbar ist on Thu, 15 Oct 2015 04:52:04 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Wie Arcoth schon gesagt hat, ist dein Problem, dass du den Typ Vector prüfst ob er den ==-Operator besitzt. In deinem Fall müsstest du aber vector&lt;T&gt;::value_type prüfen.</p>
<p>Grus Marco</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2471065</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2471065</guid><dc:creator><![CDATA[Marc-O]]></dc:creator><pubDate>Thu, 15 Oct 2015 04:52:04 GMT</pubDate></item><item><title><![CDATA[Reply to SFINAE um zu testen ob operator &amp;quot;==&amp;quot; von klassen template wirklich nutzbar ist on Thu, 15 Oct 2015 06:25:43 GMT]]></title><description><![CDATA[<p>Nun ja, eigentlich wird geprüft ob der call zu</p>
<pre><code>std::declval&lt;T&gt;() == std::declval&lt;T&gt;()
</code></pre>
<p>möglich ist.</p>
<p>Das sind also die grenzen von SFINAE, es gibt keine Möglichkeit zu überprüfen ob ein call zu einem Klassen template möglich ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2471069</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2471069</guid><dc:creator><![CDATA[Nash26]]></dc:creator><pubDate>Thu, 15 Oct 2015 06:25:43 GMT</pubDate></item><item><title><![CDATA[Reply to SFINAE um zu testen ob operator &amp;quot;==&amp;quot; von klassen template wirklich nutzbar ist on Thu, 15 Oct 2015 07:57:34 GMT]]></title><description><![CDATA[<p>Nash26 schrieb:</p>
<blockquote>
<p>Das sind also die grenzen von SFINAE, es gibt keine Möglichkeit zu überprüfen ob ein call zu einem Klassen template möglich ist.</p>
</blockquote>
<p>Unsinn. Lies doch mal meine zweite Antwort.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2471079</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2471079</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Thu, 15 Oct 2015 07:57:34 GMT</pubDate></item><item><title><![CDATA[Reply to SFINAE um zu testen ob operator &amp;quot;==&amp;quot; von klassen template wirklich nutzbar ist on Thu, 15 Oct 2015 18:28:30 GMT]]></title><description><![CDATA[<p>Selbstverständlich habe ich Deine Antwort gelesen.<br />
Nur leider hast du das Problem in seiner Gänze noch nicht verstanden.<br />
Ich will eine generelle Lösung, <code>std::vector&lt;T&gt;</code> war nur Beispielhaft genommen.</p>
<p>Was ist wenn ich überprüfen will ob eine X-Beliebiges Klassen template den &quot;==&quot; operator unterstützt und das natürlich kein typedef <code>value_type</code> definiert hat. Ich will keine zig Spezialisierungen schreiben, ich will schlicht und einfach überprüfen ob der Vergleich eines Beliebigen types möglich ist oder nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2471183</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2471183</guid><dc:creator><![CDATA[Nash26]]></dc:creator><pubDate>Thu, 15 Oct 2015 18:28:30 GMT</pubDate></item><item><title><![CDATA[Reply to SFINAE um zu testen ob operator &amp;quot;==&amp;quot; von klassen template wirklich nutzbar ist on Thu, 15 Oct 2015 18:56:11 GMT]]></title><description><![CDATA[<p>Der von Arcoth gezeigte Code überprüft, ob es eine Deklaration eins operator== gibt (und dieser Aufruf nicht via SFINAE deaktiviert ist). Sie überprüft nicht, ob es eine Definition gibt, oder ob die Definition kompiliert. So etwas kann SFINAE nicht.</p>
<p>Deshalb funktioniert std::vector&lt;T&gt; auch nicht. std::vector hat immer einen operator==, unabhäng davon ob T einen hat. Deshalb gibt es immer eine gültige Dekleration, weswegen man das so nicht überprüfen kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2471192</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2471192</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Thu, 15 Oct 2015 18:56:11 GMT</pubDate></item><item><title><![CDATA[Reply to SFINAE um zu testen ob operator &amp;quot;==&amp;quot; von klassen template wirklich nutzbar ist on Fri, 16 Oct 2015 04:24:02 GMT]]></title><description><![CDATA[<p>Nash26 schrieb:</p>
<blockquote>
<p>Das sind also die grenzen von SFINAE, es gibt keine Möglichkeit zu überprüfen ob ein call zu einem Klassen template möglich ist.</p>
</blockquote>
<p>Ähm, wenn eine Klasse behauptet, den op== zu haben, ohne ihn zu haben…<br />
Das sind nicht bloß die Grenzen von SFINAE, sondern das sind die Grenzen aller Programmiersprachen überhaupt. Sie können halt nicht perfekt mit Programmierern zusammenarbeiten, die den Compiler/Interpreter anlügen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2471229</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2471229</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 16 Oct 2015 04:24:02 GMT</pubDate></item></channel></rss>