<?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[Templates für Funktionsaufruf: Kann man das irgendwie einfacher machen?]]></title><description><![CDATA[<p>Hi!</p>
<p>Habe einen Wrapper für Python geschrieben. Mit ihm kann ich funktionen in Python aufrufen, und an diese auch Parameter übergeben. Ich mache es derzeit so:</p>
<pre><code class="language-cpp">template &lt;class Param1&gt;
ManagedPyObject CallFunction(const std::string&amp; Name, Param1 p1)
{
	wxPyBlockThreads();

	PyObject* func(GetFunction(Name));
	ManagedPyObject args(BuildParams(p1));

	return ManagedPyObject(PyEval_CallObject(func, args));
}

template &lt;class Param1, class Param2&gt;
ManagedPyObject CallFunction(const std::string&amp; Name, Param1 p1, Param2 p2)
{
	wxPyBlockThreads();

	PyObject* func(GetFunction(Name));
	ManagedPyObject args(BuildParams(p1, p2));

	return ManagedPyObject(PyEval_CallObject(func, args));
}
// ...

template &lt;class Param1&gt;
PyObject* BuildParams(Param1 p1)
{
	PyObject* args=PyTuple_New(1);
	PyTuple_SetItem(args, 0, OneParam(p1));
	return args;
}

template &lt;class Param1, class Param2&gt;
PyObject* BuildParams(Param1 p1, Param2 p2)
{
	PyObject* args=PyTuple_New(1);
	PyTuple_SetItem(args, 0, OneParam(p1));
	PyTuple_SetItem(args, 1, OneParam(p2));
	return args;
}
// ...
</code></pre>
<p>Also ich habe für jede Anzahl von Parametern zwei Funktionen. Kann man die irgendwie automatisieren, also dass ich nicht so viele Funktionen schreiben brauch, sondern eine für alle irgendwie?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/217858/templates-für-funktionsaufruf-kann-man-das-irgendwie-einfacher-machen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 10 Oct 2026 07:03:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/217858.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 12 Jul 2008 13:28:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Templates für Funktionsaufruf: Kann man das irgendwie einfacher machen? on Sat, 12 Jul 2008 13:28:15 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Habe einen Wrapper für Python geschrieben. Mit ihm kann ich funktionen in Python aufrufen, und an diese auch Parameter übergeben. Ich mache es derzeit so:</p>
<pre><code class="language-cpp">template &lt;class Param1&gt;
ManagedPyObject CallFunction(const std::string&amp; Name, Param1 p1)
{
	wxPyBlockThreads();

	PyObject* func(GetFunction(Name));
	ManagedPyObject args(BuildParams(p1));

	return ManagedPyObject(PyEval_CallObject(func, args));
}

template &lt;class Param1, class Param2&gt;
ManagedPyObject CallFunction(const std::string&amp; Name, Param1 p1, Param2 p2)
{
	wxPyBlockThreads();

	PyObject* func(GetFunction(Name));
	ManagedPyObject args(BuildParams(p1, p2));

	return ManagedPyObject(PyEval_CallObject(func, args));
}
// ...

template &lt;class Param1&gt;
PyObject* BuildParams(Param1 p1)
{
	PyObject* args=PyTuple_New(1);
	PyTuple_SetItem(args, 0, OneParam(p1));
	return args;
}

template &lt;class Param1, class Param2&gt;
PyObject* BuildParams(Param1 p1, Param2 p2)
{
	PyObject* args=PyTuple_New(1);
	PyTuple_SetItem(args, 0, OneParam(p1));
	PyTuple_SetItem(args, 1, OneParam(p2));
	return args;
}
// ...
</code></pre>
<p>Also ich habe für jede Anzahl von Parametern zwei Funktionen. Kann man die irgendwie automatisieren, also dass ich nicht so viele Funktionen schreiben brauch, sondern eine für alle irgendwie?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1546195</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1546195</guid><dc:creator><![CDATA[Maxi]]></dc:creator><pubDate>Sat, 12 Jul 2008 13:28:15 GMT</pubDate></item><item><title><![CDATA[Reply to Templates für Funktionsaufruf: Kann man das irgendwie einfacher machen? on Sat, 12 Jul 2008 13:37:18 GMT]]></title><description><![CDATA[<p>Ich denke da gibt es 3 Möglichkeiten, zumindest wenn ich dich richtig verstanden habe:<br />
1. Du wartest auf den neuen Standard, dort wird es variierbare Anzahl Templates geben, welche man ausrollen kann.<br />
2. Du benutzt Boost.Python:<br />
<a href="http://www.boost.org/doc/libs/1_35_0/libs/python/doc/index.html" rel="nofollow">http://www.boost.org/doc/libs/1_35_0/libs/python/doc/index.html</a><br />
Man hat mir gesagt, die Schnittstelle soll sehr gut sein.<br />
3. Du benutzt Boost.Preprocessor:<br />
<a href="http://www.boost.org/doc/libs/1_35_0/libs/preprocessor/doc/index.html" rel="nofollow">http://www.boost.org/doc/libs/1_35_0/libs/preprocessor/doc/index.html</a><br />
Mit diesen Preprocessor Anweisungen kann man &quot;Schleifen&quot; erzeugen, welche ähnlichen Code wiederholen. Gerade für Funktionen die immer gleich aussehen, aber einen weiteren Parameter haben, sollen damit einfach zu lösen sein.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1546200</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1546200</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Sat, 12 Jul 2008 13:37:18 GMT</pubDate></item><item><title><![CDATA[Reply to Templates für Funktionsaufruf: Kann man das irgendwie einfacher machen? on Sat, 12 Jul 2008 14:35:55 GMT]]></title><description><![CDATA[<p>Hey!</p>
<p>Ich glaube boost.preprocessor ist genau das, was ich dafür brauche. boost.python verwende ich schon im hintergrund <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1546232</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1546232</guid><dc:creator><![CDATA[Maxi]]></dc:creator><pubDate>Sat, 12 Jul 2008 14:35:55 GMT</pubDate></item></channel></rss>