<?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[boost::fusion::vector mittels Funktor füllen]]></title><description><![CDATA[<p>Hallo,<br />
ich suche nach einer Möglichkeit, aus einem boost::fusion::vector einen Funktor zu erstellen, in etwa so:</p>
<pre><code class="language-cpp">template&lt;typename Signature&gt;
struct FusedCallable
{
   typedef Signature SignatureType;
   //der Funktor...
   typedef boost::function&lt;SignatureType&gt; FunctorType;

   //mpl::vector Typ aus Signatur Typ erzeugen
   typedef typename boost::function_types::parameter_types&lt;SignatureType&gt;::type VectorizedSignatureType;
   //fusion::vector Typ aus mpl::vector Typ erzeugen
   typedef typename boost::fusion::result_of::as_vector&lt;VectorizedSignatureType&gt;::type FusedParameterType;

   //ein fusion::vector Objekt, welches Werte entsprechend den Signaturetypen aufnehmen kann
   FusedParameterType paramContainer;

   FunctorType fill;

   //boost::function Objekt, welches das fusion::vector Objekt fuellen soll
   //dabei suche ich das magicFusionVectorToFunctor
   //welches ein Funktionsobjekt entsprechend der Signatur liefern soll
   //(Rueckgabewert im Moment nicht beruecksichtigt)
   FusedCallable() : fill(magicFusionVectorToFunctor(paramContainer)) {}
};

//...

//Anwendung
FusedCallable&lt;void (int, float)&gt; fusedCallable; //-&gt; fusion::vector&lt;int, float&gt;

fusedCallable.fill(42, 3.14159f);
std::cout &lt;&lt; boost::fusion::at_c&lt;0&gt;(fusedCallable.paramContainer) &lt;&lt; '\n'; //42
std::cout &lt;&lt; boost::fusion::at_c&lt;1&gt;(fusedCallable.paramContainer) &lt;&lt; '\n'; //~pi
</code></pre>
<p>Irgendwie fehlt mir hier das <code>magicFusionVectorToFunctor</code> . Gibt es da was, oder hat vielleicht einer eine Idee, wie man das realisieren könnte?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/280270/boost-fusion-vector-mittels-funktor-füllen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 24 Aug 2026 04:04:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/280270.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 12 Jan 2011 15:57:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to boost::fusion::vector mittels Funktor füllen on Wed, 12 Jan 2011 16:38:35 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich suche nach einer Möglichkeit, aus einem boost::fusion::vector einen Funktor zu erstellen, in etwa so:</p>
<pre><code class="language-cpp">template&lt;typename Signature&gt;
struct FusedCallable
{
   typedef Signature SignatureType;
   //der Funktor...
   typedef boost::function&lt;SignatureType&gt; FunctorType;

   //mpl::vector Typ aus Signatur Typ erzeugen
   typedef typename boost::function_types::parameter_types&lt;SignatureType&gt;::type VectorizedSignatureType;
   //fusion::vector Typ aus mpl::vector Typ erzeugen
   typedef typename boost::fusion::result_of::as_vector&lt;VectorizedSignatureType&gt;::type FusedParameterType;

   //ein fusion::vector Objekt, welches Werte entsprechend den Signaturetypen aufnehmen kann
   FusedParameterType paramContainer;

   FunctorType fill;

   //boost::function Objekt, welches das fusion::vector Objekt fuellen soll
   //dabei suche ich das magicFusionVectorToFunctor
   //welches ein Funktionsobjekt entsprechend der Signatur liefern soll
   //(Rueckgabewert im Moment nicht beruecksichtigt)
   FusedCallable() : fill(magicFusionVectorToFunctor(paramContainer)) {}
};

//...

//Anwendung
FusedCallable&lt;void (int, float)&gt; fusedCallable; //-&gt; fusion::vector&lt;int, float&gt;

fusedCallable.fill(42, 3.14159f);
std::cout &lt;&lt; boost::fusion::at_c&lt;0&gt;(fusedCallable.paramContainer) &lt;&lt; '\n'; //42
std::cout &lt;&lt; boost::fusion::at_c&lt;1&gt;(fusedCallable.paramContainer) &lt;&lt; '\n'; //~pi
</code></pre>
<p>Irgendwie fehlt mir hier das <code>magicFusionVectorToFunctor</code> . Gibt es da was, oder hat vielleicht einer eine Idee, wie man das realisieren könnte?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2005791</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2005791</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Wed, 12 Jan 2011 16:38:35 GMT</pubDate></item><item><title><![CDATA[Reply to boost::fusion::vector mittels Funktor füllen on Fri, 14 Jan 2011 09:26:05 GMT]]></title><description><![CDATA[<p>Mir ist nicht so richtig klar was Du machen willst, kannst Du das vielleicht noch näher erläutern? Soll <code>FusedCallable</code> ein Functor sein oder werden? Oder probierst willst Du <code>paramContainer</code> zu füllen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2006444</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2006444</guid><dc:creator><![CDATA[headmyshoulder]]></dc:creator><pubDate>Fri, 14 Jan 2011 09:26:05 GMT</pubDate></item><item><title><![CDATA[Reply to boost::fusion::vector mittels Funktor füllen on Fri, 14 Jan 2011 10:25:27 GMT]]></title><description><![CDATA[<p>headmyshoulder schrieb:</p>
<blockquote>
<p>Mir ist nicht so richtig klar was Du machen willst, kannst Du das vielleicht noch näher erläutern? Soll <code>FusedCallable</code> ein Functor sein oder werden? Oder probierst willst Du <code>paramContainer</code> zu füllen</p>
</blockquote>
<p>Der Funktor ist <code>FusedCallable::fill()</code> . Und wenn der aufgerufen wird, dann soll das Fusion-Tuple mit den übergabenen Aktualparametern gefüllt werden.<br />
Beispiel:</p>
<pre><code class="language-cpp">//der Funktor:
boost::function&lt;void (int, double)&gt; fkt;
//das dazugehoerende Fusion-Tuple:
boost::fusion::vector&lt;int, double&gt; tuple;
fkt = magicBind(tuple);

fkt(42, 3.1); --&gt;tuple enthaelt jetzt (42, 3.1)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2006471</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2006471</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Fri, 14 Jan 2011 10:25:27 GMT</pubDate></item><item><title><![CDATA[Reply to boost::fusion::vector mittels Funktor füllen on Fri, 14 Jan 2011 10:57:47 GMT]]></title><description><![CDATA[<p>Tachyon schrieb:</p>
<blockquote>
<p>headmyshoulder schrieb:</p>
<blockquote>
<p>Mir ist nicht so richtig klar was Du machen willst, kannst Du das vielleicht noch näher erläutern? Soll <code>FusedCallable</code> ein Functor sein oder werden? Oder probierst willst Du <code>paramContainer</code> zu füllen</p>
</blockquote>
<p>Der Funktor ist <code>FusedCallable::fill()</code> . Und wenn der aufgerufen wird, dann soll das Fusion-Tuple mit den übergabenen Aktualparametern gefüllt werden.<br />
Beispiel:</p>
<pre><code class="language-cpp">//der Funktor:
boost::function&lt;void (int, double)&gt; fkt;
//das dazugehoerende Fusion-Tuple:
boost::fusion::vector&lt;int, double&gt; tuple;
fkt = magicBind(tuple);

fkt(42, 3.1); --&gt;tuple enthaelt jetzt (42, 3.1)
</code></pre>
</blockquote>
<p>Ok, vestehe. Ich bin mir nicht sicher ob es dafür ein fertige Lösung gibt, vielleicht musst Du da in der Fusion Doku nochmal genau nachsehen. Vielleich gibt es auch etwas in Boost.Phoenix. Ansonten kann man das aber auch schnell selber machen, z.B. so ( Wenn Du mehr Parameter brauchst musst Du nochmehr <code>operatoren()</code> schreiben) :</p>
<pre><code class="language-cpp">template&lt; class Vec &gt;
struct assign
{
	Vec &amp;m_vec;
	assign( Vec &amp;vec ) : m_vec( vec ) { }

	template&lt; class P1 &gt;
	boost::fusion::vector&lt; P1 &gt; operator()( const P1 &amp;p1 ) const
	{
		m_vec = boost::fusion::make_vector( p1 );
	}

	template&lt; class P1 , class P2 &gt;
	boost::fusion::vector&lt; P1 , P2 &gt; operator()( const P1 &amp;p1 , const P2 &amp;p2 ) const
	{
		m_vec = boost::fusion::make_vector( p1 , p2 );
	}
};

template&lt;typename Signature&gt;
struct FusedCallable
{
   typedef Signature SignatureType;

   typedef boost::function&lt;SignatureType&gt; FunctorType;

   typedef typename boost::function_types::parameter_types&lt;SignatureType&gt;::type VectorizedSignatureType;
   typedef typename boost::fusion::result_of::as_vector&lt;VectorizedSignatureType&gt;::type FusedParameterType;

   FusedParameterType paramContainer;
   FunctorType fill;

   FusedCallable() : fill( assign&lt; FusedParameterType &gt;( this-&gt;paramContainer ) ) { };
};

FusedCallable&lt;void (int, float)&gt; fusedCallable;
fusedCallable.fill(42, 3.14159f);
std::cout &lt;&lt; boost::fusion::at_c&lt;0&gt;(fusedCallable.paramContainer) &lt;&lt; '\n'; //42
std::cout &lt;&lt; boost::fusion::at_c&lt;1&gt;(fusedCallable.paramContainer) &lt;&lt; '\n'; //~pi
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2006482</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2006482</guid><dc:creator><![CDATA[headmyshoulder]]></dc:creator><pubDate>Fri, 14 Jan 2011 10:57:47 GMT</pubDate></item><item><title><![CDATA[Reply to boost::fusion::vector mittels Funktor füllen on Fri, 14 Jan 2011 11:40:34 GMT]]></title><description><![CDATA[<p>Danke erstmal für die Mühe.<br />
So etwas in der Art hätte ich auch als nächstes implementiert. Ich hatte nur gehofft, dass es evtl. eine Lösung gibt, welche mir das Forwarden der Parameter erspart. Es wird echt langsam Zeit, dass C++0x in trockende Tücher kommt, und dass es Compiler dafür gibt.<br />
Kurz was zum Sinn und Zweck dahinter:<br />
Ich möchte mir für ein Framework eine API erstellen, welche mit Möglichst wenig Auwand RPCs ermöglicht. Im Framework werden intern boost-Signals benutzt. Ich könnte nun ein passendes Signal mit den oben genannten Funktor koppeln, und dann durch einen Aufruf den Inhalt vom Fusion-Vektor z.B. in ein boost.serialization-Archiv serialisieren (das geht mit <code>boost::fusion::for_each</code> relativ einfach). Mit etwas Zusatzinfos garniert, kann man damit dann in einem potentiellen Empfänger wieder deserialiesiren und damit denn weitere Funktoren befeuern. So weit in der Theorie.</p>
<p>PS: Vielleicht wäre es aber einfacher, wenn die Funktoren gleich mit Fusion-Vektoren als Formalparameter ausgelegt werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2006494</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2006494</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Fri, 14 Jan 2011 11:40:34 GMT</pubDate></item></channel></rss>