<?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[Überladene Funktion auswählen]]></title><description><![CDATA[<p>Hallo,</p>
<p>des Problems Lösung ist bestimmt trivial, ich habe nur gerade ein Brett vor dem Kopf:</p>
<pre><code>template&lt;typename T&gt;
struct Foo { };
template&lt;typename T&gt;
struct Bar { };

void f(int);
template&lt;typename T&gt;
void f(Foo&lt;T&gt;);
template&lt;typename T&gt;
void f(Bar&lt;T&gt;);

struct FooBar
{
	template&lt;typename T&gt;
	FooBar(T);
};

int main()
{
	FooBar(/* hier einen Funktionszeiger auf f&lt;int&gt;(Foo&lt;int&gt;) erstellen und übergeben */);
}
</code></pre>
<p>Wie sieht die Syntax aus?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/327441/überladene-funktion-auswählen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Jul 2026 10:45:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/327441.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 12 Aug 2014 11:37:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 11:37:40 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>des Problems Lösung ist bestimmt trivial, ich habe nur gerade ein Brett vor dem Kopf:</p>
<pre><code>template&lt;typename T&gt;
struct Foo { };
template&lt;typename T&gt;
struct Bar { };

void f(int);
template&lt;typename T&gt;
void f(Foo&lt;T&gt;);
template&lt;typename T&gt;
void f(Bar&lt;T&gt;);

struct FooBar
{
	template&lt;typename T&gt;
	FooBar(T);
};

int main()
{
	FooBar(/* hier einen Funktionszeiger auf f&lt;int&gt;(Foo&lt;int&gt;) erstellen und übergeben */);
}
</code></pre>
<p>Wie sieht die Syntax aus?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413095</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413095</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Tue, 12 Aug 2014 11:37:40 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 12:02:57 GMT]]></title><description><![CDATA[<pre><code>FooBar( static_cast&lt;void(*)(Foo&lt;int&gt;)&gt;(f&lt;int&gt;) );
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2413097</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413097</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Tue, 12 Aug 2014 12:02:57 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 12:11:34 GMT]]></title><description><![CDATA[<p>Oder mit meinem kleinen <code>deduce</code> Tool:</p>
<pre><code>template &lt;typename... T&gt;
struct deduce
{
	template &lt;typename R, typename... Superfluent&gt;
	static auto from( R(*f)(T..., Superfluent...) ) -&gt; decltype(f)
	{
		return f;
	}
};

// [...]

	FooBar( deduce&lt;Foo&lt;int&gt;&gt;::from(f&lt;int&gt;) );
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2413099</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413099</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Tue, 12 Aug 2014 12:11:34 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 12:57:23 GMT]]></title><description><![CDATA[<p>Deine Lösung mit <code>static_cast</code> hat funktioniert.</p>
<p>Ich habe eigentlich etwas Eigenes was fast so wie dein <code>deduce</code> ist, was hier (im konkreten Anwendungsfall, nicht beim Minimalbeispiel) nicht funktioniert hat, deswegen war ich auch so ratlos. Der Fehler war, dass ich die Argumente als LValue angegeben habe, obwohl die Funktion Const-Referenzen annimmt. Peinlich. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Danke für deine Hilfe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413108</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413108</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Tue, 12 Aug 2014 12:57:23 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 14:44:46 GMT]]></title><description><![CDATA[<p>Das nennst du peinlich? Ich habe heute Morgen eine halbe Stunde gesucht was hier falsch ist:</p>
<pre><code>unsigned y_square = 1;
	unsigned x_square = 1;

	for (unsigned y = 1; y != root; ++y)
	{

		for (unsigned x = 1; x != root; ++x)
		{
			// ...
			// ...
			// ...
			x_square += 2*x+1;
		}

		y_square += 2*y+1;
	}
</code></pre>
<p>volkard hätte es natürlich sofort gesehen, der sieht sowas einfach direkt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413122</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413122</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Tue, 12 Aug 2014 14:44:46 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 15:38:02 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>volkard hätte es natürlich sofort gesehen, der sieht sowas einfach direkt.</p>
</blockquote>
<p>hab's auch nicht direkt gesehen.<br />
mir wäre es aber nicht passiert.<br />
beim schleife-verdoppeln wäre square als an-die-schleife-gekettet mit der schleife bewegt worden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413129</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413129</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 12 Aug 2014 15:38:02 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 16:15:51 GMT]]></title><description><![CDATA[<p>Das fehlende <code>x_square = 1</code> oder was?<br />
Sowas kann man schonmal übersehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413132</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413132</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 12 Aug 2014 16:15:51 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 16:34:37 GMT]]></title><description><![CDATA[<p>Ist das premature Optimization? x*x ist viel schneller als +=(x&lt;&lt;1)+1. Und dass man den Scope seiner Variablen minimal halten soll ist ja schon seit Jahrzehnten bekannt. Zudem ist das vermutlich unnötiger Brute-Force den man algorithmisch optimieren kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413134</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413134</guid><dc:creator><![CDATA[tinyscope]]></dc:creator><pubDate>Tue, 12 Aug 2014 16:34:37 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 18:37:22 GMT]]></title><description><![CDATA[<p>tinyscope schrieb:</p>
<blockquote>
<p>Ist das premature Optimization? x*x ist viel schneller als +=(x&lt;&lt;1)+1.</p>
</blockquote>
<p>Hast du es ausprobiert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413161</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413161</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 12 Aug 2014 18:37:22 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 18:38:25 GMT]]></title><description><![CDATA[<p>@Arcoth<br />
Geht's darum, dass <code>x_square</code> vor der Schleife definiert wird anstatt in der äusseren? Ein Kopierfehler - wie ich ihn begangen habe - ist doch immer peinlicher als ein Logikfehler.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413163</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413163</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Tue, 12 Aug 2014 18:38:25 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 18:40:11 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>tinyscope schrieb:</p>
<blockquote>
<p>Ist das premature Optimization? x*x ist viel schneller als +=(x&lt;&lt;1)+1.</p>
</blockquote>
<p>Hast du es ausprobiert?</p>
</blockquote>
<p>Ja. 2.15s vs 1.38s bei -O3 und</p>
<pre><code class="language-cpp">void f(int i);

void g(int x) {
  for (int i=1; i&lt;x; ++i)
    f(i*i);
}

void h(int x) {
  for (int i=0, square=1; i!=x; ++i, square+=2*i+1)
    f(square);
}
</code></pre>
<p>(x=1000*1000*1000)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413164</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413164</guid><dc:creator><![CDATA[tinyscope]]></dc:creator><pubDate>Tue, 12 Aug 2014 18:40:11 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 18:41:46 GMT]]></title><description><![CDATA[<p>2.15s vs 1.38s bezog sich auf h (Arcoth) vs h (i*i).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413165</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413165</guid><dc:creator><![CDATA[tinyscope]]></dc:creator><pubDate>Tue, 12 Aug 2014 18:41:46 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 18:42:58 GMT]]></title><description><![CDATA[<p>* h vs g.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413167</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413167</guid><dc:creator><![CDATA[tinyscope]]></dc:creator><pubDate>Tue, 12 Aug 2014 18:42:58 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 20:35:10 GMT]]></title><description><![CDATA[<p>Das muss aber ein seltsamer Compiler sein, der dir die Schleife nicht komplett wegoptimiert. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Hab's aber grad selbst ausprobiert, und muss zu meinem Erstaunen feststellen dass du Recht hast. (Also nicht dass die Schleife nicht wegoptimiert wird, sondern dass x*x wirklich schneller ist als die += Variante.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413184</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413184</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 12 Aug 2014 20:35:10 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 20:55:59 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>tinyscope schrieb:</p>
<blockquote>
<p>Ist das premature Optimization? x*x ist viel schneller als +=(x&lt;&lt;1)+1.</p>
</blockquote>
<p>Hast du es ausprobiert?</p>
</blockquote>
<p>vor 2-3 Jahren hatte ich es ausprobiert, i7 mit AFAIR 6 Takten pro integer-multiplikation. Es war fast gleich.</p>
<p>ungefähr so gleich wie bei tinyscopes messung nur andersrum und noch weniger signifikant. bei &quot;(x=1000*1000*1000)&quot; und &quot;2.15s vs 1.38s&quot; reden wir von vielleicht 3 takten, die werden von allem, was mit den</p>
<pre><code>// ...
            // ...
            // ...
</code></pre>
<p>steckt, komplett marginalisiert. ich hatte eher sowas wie einen takt zugunsten Arcoths.</p>
<p>ich erwarte, daß in zukunft noch ein paarhundertmillionen transistoren in die multiplikation gesteckt werden. außerdem nimmt, vermute ich, die multiplikation ein wenig registerdruck weg, was nur zieht, wenn in f() sauwenig passiert, vielleicht sind tinyscopes messungen deswegen signifikanter als in der praxis.</p>
<p>würde selbst für private forschung, wo ich schon extrem auf jeden takt achte (manche nennen es krank, aber es ist halt ein hobby, da muss ich nicht nach stechuhr mindestens 2250 zeilen pro woche einloggen), wo ich schnellere (weil passendere) replacements für vector, array, queue, stack benutze, hier einfach bei * bleiben. Den Takt gebe ich mir.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413185</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413185</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 12 Aug 2014 20:55:59 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 21:12:04 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>Hab's aber grad selbst ausprobiert, und muss zu meinem Erstaunen feststellen dass du Recht hast. (Also nicht dass die Schleife nicht wegoptimiert wird, sondern dass x*x wirklich schneller ist als die += Variante.)</p>
</blockquote>
<p>Vielleicht wieder lahmer, wenn man das Problem mit Multithreading lösen läßt und auf 8 Hyperkernen nur 4 ALUs hat.<br />
Es ist unsicher zur Zeit, fürchte ich. Trend geht nach *.</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /> Geschäftsidee <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /><br />
Ich verkaufe meine Game nicht, sondern verschenke die normale Version oder zu kelienm Preis!<br />
Aaber ich biete an, daß man eine auf den Zielrechner optimierte exe erwerben kann. Dazu einfach meinen Messer runterladen, der testet alle und jede Funktion aus. Auch ob zum Quadratzahlenaufzählen diese oder jene Version schneller ist. Auch ob der vergötterte Twister den MWC packt. Auch ob double oder float besser flutschen, auch ob…<br />
Und mit so 20 oder 50 Parametern wird dem Kunden die speziell angepaßte exe automatisch oder per Hand compiliert, und die kann er für 25€ oder halt größerem Preis kaufen. Mehr frames, mehr frags.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413187</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413187</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 12 Aug 2014 21:12:04 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Tue, 12 Aug 2014 23:03:22 GMT]]></title><description><![CDATA[<p>Wieso sollten 8 Hyperkerne nur 4 ALUs haben, wenn ein Core schon 5 hat? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<pre><code class="language-cpp">#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#define NOMINMAX

#include &quot;targetver.h&quot;

#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;cstdint&gt;
#include &lt;algorithm&gt;
#include &lt;vector&gt;

#include &lt;windows.h&gt;

using namespace std;

__declspec(noinline) unsigned square_multiply(unsigned start, unsigned limit)
{
	unsigned accu = 0;
#pragma loop(hint_parallel(0))
	for (unsigned i = start; i &lt;= limit; i++)
		accu += i*i;

	return accu;
}

__declspec(noinline) unsigned square_multiply_p8(unsigned start, unsigned limit)
{
	static const int batch_size = 10000;

	int batch_count = (limit - start + batch_size - 1) / batch_size;
	int slimit = limit;

	LONG accu = 0;
#pragma loop(no_vector)
#pragma loop(hint_parallel(8))
#pragma loop(ivdep)
	for (int i = start; i &lt;= slimit; i += batch_size)
	{
		unsigned val = square_multiply(i, min(i + batch_size - 1, slimit));
		::InterlockedAdd(&amp;accu, val);
	}

	return accu;
}

__declspec(noinline) unsigned square_multiply_novec(unsigned start, unsigned limit)
{
	unsigned accu = 0;
#pragma loop(no_parallel)
#pragma loop(no_vector)
	for (unsigned i = start; i &lt;= limit; i++)
	{
		accu += i*i;
	}

	return accu;
}

__declspec(noinline) unsigned square_add(unsigned start, unsigned limit)
{
	unsigned accu = 0;
	unsigned square = start * start;
	for (unsigned i = start; i &lt;= limit; i++)
	{
		accu += square;
		square += 2 * i + 1;
	}

	return accu;
}

__declspec(noinline) unsigned square_add_p8(unsigned start, unsigned limit)
{
	static const int batch_size = 10000;

	int batch_count = (limit - start + batch_size - 1) / batch_size;
	int slimit = limit;

	LONG accu = 0;
#pragma loop(no_vector)
#pragma loop(hint_parallel(8))
#pragma loop(ivdep)
	for (int i = start; i &lt;= slimit; i += batch_size)
	{
		unsigned val = square_add(i, min(i + batch_size - 1, slimit));
		::InterlockedAdd(&amp;accu, val);
	}

	return accu;
}

int volatile result = 0;
LARGE_INTEGER frequeny;

__declspec(noinline) uint64_t measure_one(char const* name, unsigned(*fun)(unsigned, unsigned), unsigned start, unsigned limit)
{
	SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
	Sleep(1);

	LARGE_INTEGER t0;
	QueryPerformanceCounter(&amp;t0);

	result = fun(start, limit);

	LARGE_INTEGER t1;
	QueryPerformanceCounter(&amp;t1);

	SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);

	return t1.QuadPart - t0.QuadPart;
}

void measure(char const* name, unsigned(*fun)(unsigned, unsigned), unsigned start, unsigned limit)
{
	uint64_t best_time = numeric_limits&lt;uint64_t&gt;::max();
	int best_result = 0;

	for (int rep = 0; rep &lt; 10; rep++)
	{
		uint64_t t = measure_one(name, fun, start, limit);
		if (t &lt; best_time)
		{
			rep = 0;
			best_time = t;
			best_result = result;
		}
	}

	cout &lt;&lt; name &lt;&lt; &quot;: &quot; &lt;&lt; (best_time * 1000.0) / frequeny.QuadPart &lt;&lt; &quot; (&quot; &lt;&lt; best_result &lt;&lt; &quot;)\n&quot;;
}

#define MEASURE(fun) measure(#fun, fun, start, limit)

int main(int argc, char const** argv)
{
	QueryPerformanceFrequency(&amp;frequeny);

	int start = 1234;
	int limit = 1234567;

	if (argc &gt; 1)
		start = stoi(argv[1]);
	if (argc &gt; 2)
		limit = stoi(argv[2]);

	cout &lt;&lt; &quot;start = &quot; &lt;&lt; start &lt;&lt; &quot;, limit = &quot; &lt;&lt; limit &lt;&lt; &quot;\n&quot;;

	MEASURE(square_multiply_p8);
	MEASURE(square_multiply);
	MEASURE(square_multiply_novec);
	MEASURE(square_add_p8);
	MEASURE(square_add);

	return 0;
}
</code></pre>
<p>VS 2013, x64, /arch:AVX2 /Qpar<br />
Xeon E3-1245 v3 (quad core Haswell)</p>
<pre><code>start = 4455, limit = 1234567890
square_multiply_p8: 31.6727 (-1713703374)
square_multiply: 119.588 (-1713703374)
square_multiply_novec: 346.583 (-1713703374)
square_add_p8: 86.8956 (-1713703374)
square_add: 535.312 (-1713703374)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2413195</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413195</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 12 Aug 2014 23:03:22 GMT</pubDate></item><item><title><![CDATA[Reply to Überladene Funktion auswählen on Wed, 13 Aug 2014 08:18:36 GMT]]></title><description><![CDATA[<p>Tatsächlich, die Multiplikation scheint schneller zu sein - hätte ich nicht erwartet. Danke für den Tipp den ich sowieso nicht mehr brauche, der algorithmischen Optimierung wegen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2413207</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2413207</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Wed, 13 Aug 2014 08:18:36 GMT</pubDate></item></channel></rss>