<?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[auf applizierbare Funktionsüberladung prüfen]]></title><description><![CDATA[<p>Ich habe eine Funktion, die sehr stark überladen ist und SFINAE exploitet, sodass sich die Balken biegen.<br />
Die Funktion heit: js_stringify</p>
<p>Bei containern wollte ich nun eine SFINAE condition hinzufügen, die generell prüft ob der value_type in js_stringify gestopft werden kann, selbes bei pointern (js_stringify(*ptr)) usw.</p>
<p>Ich habe nun angefangen alle bisherigen conditions zusammenzutragen.<br />
(is_arithmetic, is_pointer (excl func_ptr), is_js_object (boost fusion vector), tuples, is_container, ... viele mehr)<br />
Aber dann dachte ich mir, wenn ich einfach prüfen könnte, ob es für T eine geeignete &quot;js_stringify&quot;-Variante gibt, die T akzeptiert, hätte ich hier keine Code duplication mehr.)</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/324359/auf-applizierbare-funktionsüberladung-prüfen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Apr 2026 05:21:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/324359.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 14 Mar 2014 00:13:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to auf applizierbare Funktionsüberladung prüfen on Fri, 14 Mar 2014 00:13:31 GMT]]></title><description><![CDATA[<p>Ich habe eine Funktion, die sehr stark überladen ist und SFINAE exploitet, sodass sich die Balken biegen.<br />
Die Funktion heit: js_stringify</p>
<p>Bei containern wollte ich nun eine SFINAE condition hinzufügen, die generell prüft ob der value_type in js_stringify gestopft werden kann, selbes bei pointern (js_stringify(*ptr)) usw.</p>
<p>Ich habe nun angefangen alle bisherigen conditions zusammenzutragen.<br />
(is_arithmetic, is_pointer (excl func_ptr), is_js_object (boost fusion vector), tuples, is_container, ... viele mehr)<br />
Aber dann dachte ich mir, wenn ich einfach prüfen könnte, ob es für T eine geeignete &quot;js_stringify&quot;-Variante gibt, die T akzeptiert, hätte ich hier keine Code duplication mehr.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2388782</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2388782</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Fri, 14 Mar 2014 00:13:31 GMT</pubDate></item><item><title><![CDATA[Reply to auf applizierbare Funktionsüberladung prüfen on Fri, 14 Mar 2014 00:42:44 GMT]]></title><description><![CDATA[<p>Weiß nicht, vielleicht suchste sowas?</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;utility&gt;
using namespace std;

void js_stringify(int){
}
void js_stringify(char){
}

template&lt;typename T&gt;
class Test
{
    template&lt;typename U&gt;
    static char check(...);
    template&lt;typename U&gt;
    static char (&amp;check(decltype(js_stringify(declval&lt;U&gt;()))*))[2];
    public:
    static const bool value=sizeof(check&lt;T&gt;(0))==2;
};

int main(){
	cout&lt;&lt; Test&lt;int&gt;::value &lt;&lt;'\n';js_stringify(1);
	cout&lt;&lt; Test&lt;char&gt;::value &lt;&lt;'\n';js_stringify('a');
	cout&lt;&lt; Test&lt;bool&gt;::value &lt;&lt;'\n';js_stringify(true);
	cout&lt;&lt; Test&lt;void*&gt;::value &lt;&lt;'\n';//js_stringify(nullptr);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2388785</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2388785</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Fri, 14 Mar 2014 00:42:44 GMT</pubDate></item><item><title><![CDATA[Reply to auf applizierbare Funktionsüberladung prüfen on Fri, 14 Mar 2014 00:46:56 GMT]]></title><description><![CDATA[<p>Das sieht schonmal Spitze aus.<br />
Ich teste das gleich mal im Hauptprojekt aus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2388787</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2388787</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Fri, 14 Mar 2014 00:46:56 GMT</pubDate></item><item><title><![CDATA[Reply to auf applizierbare Funktionsüberladung prüfen on Fri, 14 Mar 2014 01:50:23 GMT]]></title><description><![CDATA[<p>EDIT: Ich bin grad selbst auf SFINAE reingefallen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Läuft perfekt.</p>
<p>Jetzt geht auch sowas cooles, wie:</p>
<pre><code>namespace JSON
{
    template &lt;typename T&gt;
    std::string js_try_stringify(std::string const&amp; name, T const&amp; obj, StringificationOptions const&amp; options = DEFAULT_OPTIONS,
                                 typename std::enable_if &lt;Internal::can_js_stringify&lt;T&gt;::value, void&gt;::type* = nullptr)
    {
        return js_stringify(name, obj, options);
    }

    template &lt;typename T&gt;
    std::string js_try_stringify(std::string const&amp;, T const&amp;, StringificationOptions const&amp; = DEFAULT_OPTIONS,
                                 typename std::enable_if &lt;!Internal::can_js_stringify&lt;T&gt;::value, int&gt;::type* = nullptr)
    {
        static_assert (Internal::can_js_stringify&lt;T&gt;::value, &quot;the object you try to convert is not convertible to JSON&quot;);
        return {};
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2388794</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2388794</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Fri, 14 Mar 2014 01:50:23 GMT</pubDate></item><item><title><![CDATA[Reply to auf applizierbare Funktionsüberladung prüfen on Fri, 14 Mar 2014 09:49:39 GMT]]></title><description><![CDATA[<p>Das ist ein bisschen doppelt. Warum sollte man zweimal mit enable_if nachfragen, wenn die eine Version immer eine assertion auslöst.</p>
<pre><code>namespace JSON
{
    template &lt;typename T&gt;
    std::string js_try_stringify(std::string const&amp; name, T const&amp; obj, StringificationOptions const&amp; options = DEFAULT_OPTIONS)
    {
        static_assert (Internal::can_js_stringify&lt;T&gt;::value, &quot;the object you try to convert is not convertible to JSON&quot;);
        return js_stringify(name, obj, options);
    }
}
</code></pre>
<p>Das tut es doch auch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2388829</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2388829</guid><dc:creator><![CDATA[Marthog]]></dc:creator><pubDate>Fri, 14 Mar 2014 09:49:39 GMT</pubDate></item><item><title><![CDATA[Reply to auf applizierbare Funktionsüberladung prüfen on Fri, 14 Mar 2014 15:32:12 GMT]]></title><description><![CDATA[<p>Das ist zwar richtig, aber dann gibt er zusätzlich noch den Fehler, dass es keine passende js_stringify Funktion gibt und die Meldung ist sehr lang.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2388937</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2388937</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Fri, 14 Mar 2014 15:32:12 GMT</pubDate></item></channel></rss>