<?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::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren?]]></title><description><![CDATA[<p>Hi,</p>
<p>Ich habe ein Array (ich weiß, vector geht, wird noch verbessert) von boost::tuple&lt;float, float, float, float&gt;. Ich bastel da alle möglichen Einträge rein. OpenGL erwartet jetzt allerdings ein eindimensionales Array von float, also float*.</p>
<p>std::tuple hat wegen head, tail einen Overhead, der natürlich stört. Gibt es irgendein Konstrukt, mit dem ich das tuple so interpretieren kann, dass ich es als float* interpretieren kann? Ich gehe Mal stark davon aus, dass nicht, frage mich aber schon länger, ob ich nicht irgendwas übersehe... Irgendwer ne Idee?</p>
<p>Viele Grüße!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/280873/boost-tuple-lt-float-4-gt-als-float-interpretieren</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 23:25:41 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/280873.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 23 Jan 2011 11:52:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 11:52:49 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>Ich habe ein Array (ich weiß, vector geht, wird noch verbessert) von boost::tuple&lt;float, float, float, float&gt;. Ich bastel da alle möglichen Einträge rein. OpenGL erwartet jetzt allerdings ein eindimensionales Array von float, also float*.</p>
<p>std::tuple hat wegen head, tail einen Overhead, der natürlich stört. Gibt es irgendein Konstrukt, mit dem ich das tuple so interpretieren kann, dass ich es als float* interpretieren kann? Ich gehe Mal stark davon aus, dass nicht, frage mich aber schon länger, ob ich nicht irgendwas übersehe... Irgendwer ne Idee?</p>
<p>Viele Grüße!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2010533</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010533</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Sun, 23 Jan 2011 11:52:49 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 12:38:34 GMT]]></title><description><![CDATA[<p>Ach und falls das nicht geht, findet ihr so einen operator[] unschön? Der Typ soll eigentlich ziemlich ungeschützt sein:</p>
<pre><code class="language-cpp">struct CoordinateType3
	{
		CoordinateType x;
		CoordinateType y;
		CoordinateType z;
		CoordinateType3(CoordinateType x, CoordinateType y, CoordinateType z)
			: x(x), y(y), z(z) {}
		CoordinateType3(){}
		CoordinateType operator[](std::size_t n) const
		{
			return reinterpret_cast&lt;const CoordinateType*&gt;(this)[n];
		}
	};
</code></pre>
<p>assert(n &lt; 0 || n &gt; 2) könnte man reincoden, wenn man wollte, aber spricht sonst was dagegen? Ich find's irgendwie eleganter als n switch, auch wenn der theoretisch sicherer aussieht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2010551</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010551</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Sun, 23 Jan 2011 12:38:34 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 13:12:43 GMT]]></title><description><![CDATA[<p>reinterpret_cast sollte nicht verwendet werden, um cv-qualifier zu ändern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2010580</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010580</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 23 Jan 2011 13:12:43 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 13:19:31 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">CoordinateType operator[](std::size_t n) const
        {
            return reinterpret_cast&lt;const CoordinateType*&gt;(this)[n];
        }
</code></pre>
<p>Ist irgendwie ein kleiner Hack. Warum nicht einfach einen Member <code>CoordinateType m_coords[3];</code> ? Um die einzelnen Werte namentlich anzusprechen (also <code>coord.x() = 123;</code> ) kannst du ja immer noch Methoden bereitstellen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2010581</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010581</guid><dc:creator><![CDATA[Hack]]></dc:creator><pubDate>Sun, 23 Jan 2011 13:19:31 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 14:36:11 GMT]]></title><description><![CDATA[<p>Eisflamme schrieb:</p>
<blockquote>
<p>Ich habe ein Array (ich weiß, vector geht, wird noch verbessert) von boost::tuple&lt;float, float, float, float&gt;. Ich bastel da alle möglichen Einträge rein. OpenGL erwartet jetzt allerdings ein eindimensionales Array von float, also float*.</p>
</blockquote>
<p>Dann verwende boost::array&lt;float,4&gt; statt boost::tuple&lt;float,float,float,float&gt;, oder definiere Dir Deinen eigenen Typen, mit dem man auch ein bissel mehr anstellen kann (operator+, operator*, ...) und der intern ein Array speichert.</p>
<p>Eisflamme schrieb:</p>
<blockquote>
<p>std::tuple hat wegen head, tail einen Overhead, der natürlich stört.</p>
</blockquote>
<p>Von was für einem Overhead sprichst Du?</p>
<p>Eisflamme schrieb:</p>
<blockquote>
<p>Gibt es irgendein Konstrukt, mit dem ich das tuple so interpretieren kann, dass ich es als float* interpretieren kann?</p>
</blockquote>
<p>Nein, nicht portabel. Ein reinterpret_cast verletzt strenggenommen §3.10/15 und außerdem ist nicht festgelegt, in welcher Reihenfolge die Elemente im Tuple gespeichert werden, oder ob &quot;Lücken&quot; zwischen den Elementen sind. Kurz gesagt: Du solltest Dich nicht auf ein bestimmtes Speicherlayout verlassen.</p>
<p>Eisflamme schrieb:</p>
<blockquote>
<p>Ich gehe Mal stark davon aus, dass nicht, frage mich aber schon länger, ob ich nicht irgendwas übersehe... Irgendwer ne Idee?</p>
</blockquote>
<p>Siehe oben.</p>
<p>kk</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2010621</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010621</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 23 Jan 2011 14:36:11 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 14:39:17 GMT]]></title><description><![CDATA[<p>Eisflamme schrieb:</p>
<blockquote>
<p>Ach und falls das nicht geht, findet ihr so einen operator[] unschön?</p>
</blockquote>
<p>Ja.</p>
<p>kk</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2010622</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010622</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 23 Jan 2011 14:39:17 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 20:08:50 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p>reinterpret_cast sollte nicht verwendet werden, um cv-qualifier zu ändern.</p>
</blockquote>
<p>Tut er auch nirgends.<br />
Bzw. kann er gar nicht, nicht mit einem einzelnen reinterpret_cast.</p>
<p>Was ist dein Problem?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2010799</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010799</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 23 Jan 2011 20:08:50 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 20:35:46 GMT]]></title><description><![CDATA[<p>Alles klar, damit weiß ich Bescheid, danke. <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/2010806</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010806</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Sun, 23 Jan 2011 20:35:46 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 20:20:14 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">CoordinateType operator[](std::size_t n) const 
        { 
            return reinterpret_cast&lt;const CoordinateType*&gt;(this)[n]; 
        }
</code></pre>
<p>Der Typ von this ist Class* const. Hier wird zu const Other* gecastet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2010807</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010807</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 23 Jan 2011 20:20:14 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 20:38:48 GMT]]></title><description><![CDATA[<p>Eisflamme schrieb:</p>
<blockquote>
<p>Okay, aber die Reihenfolge muss schon stimmen. Wenn ich eine eigene Struktur basteln möchte, diese einem void* übergeben muss (das erwartet die OGL-Funktion),</p>
</blockquote>
<p>Ich verstehe nicht, was Du mit &quot;diese einem void* übergeben&quot; meinst.</p>
<p>Eisflamme schrieb:</p>
<blockquote>
<p>kann ich mein Problem dann durch ein float[4] in der Struktur lösen statt float x,y,z,w? Würde boost::array mein Problem auch lösen?</p>
</blockquote>
<p>Wenn es darum geht, einen Zeiger p vom Typ float* zu erzeugen, wobei p[0],p[1],p[2],p[3] die vier Komponenten anspricht, ja, dann kannst Du das mit einem Array machen. boost::array benutzt intern auch ein &quot;C-Array&quot; -- ist also dasselbe.</p>
<pre><code class="language-cpp">struct vec4f
{
  float data[4];
  float const&amp; operator[](int i) const {return data[i];}
  float      &amp; operator[](int i)       {return data[i];}
};

int main() {
  vec4f v;
  for (int k=0; k&lt;4; ++k) v[k] = 11*(k+1);
  float* p = v.data;
  for (int k=0; k&lt;4; ++k) cout &lt;&lt; p[k] &lt;&lt; '\n';
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2010823</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010823</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 23 Jan 2011 20:38:48 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 20:44:04 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">CoordinateType operator[](std::size_t n) const 
        { 
            return reinterpret_cast&lt;const CoordinateType*&gt;(this)[n]; 
        }
</code></pre>
<p>Der Typ von this ist Class* const.</p>
</blockquote>
<p>Nein.<br />
Der Typ ist <code>Class const*</code> , da es eine &quot;const Funktion&quot; ist. Und Top-Level const gibt es für &quot;this&quot; keines.</p>
<blockquote>
<p>Hier wird zu const Other* gecastet.</p>
</blockquote>
<p>Ja.<br />
Und selbst wenn der Source-Type <code>Class* const</code> wäre (was er wie gesagt nicht ist) ...<br />
Da das Top-Level const egal ist (es wird ja eine Kopie des Primären Objekts, also hier des Zeigers, erstellt), wäre auch diese Konvertierung erlaubt, da sie implizit erlaubt ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2010830</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010830</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 23 Jan 2011 20:44:04 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 20:55:40 GMT]]></title><description><![CDATA[<p>Du hast zur Hälfte Recht, habe übersehen, dass die Funktion ja const ist.<br />
Der Typ von this ist in der Funktion const Class* const. this ist immer const!<br />
Wo hier eine Kopie erstellt wird, sehe ich gerade nicht.</p>
<p>Edit: Entschuldige, du hast Recht, ist scheinbar nur beim GCC ein T* const <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2010833</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010833</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 23 Jan 2011 20:55:40 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 20:55:05 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>Okay, das beantwortet meine Frage, danke. <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>
<p>Dieses eine void* übergeben bedeutet, ich habe 40 4x4-Matrizen. Diese möchte OpenGL aber als void*[40*4*4] haben. Für das, was ich reinstecke, bietet es sich an, die Matrizen quasi in Zeilen anzugeben, also jeweils als 4er-float-Tupel. Davon nehme ich dann 160 zusammen und habe meine 4 Matrizen abgebildet, gebe die an OpenGL, sage dem, dass er das die einzelnen Komponenten float sind und dann geht der Spaß los. :)=</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2010841</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010841</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Sun, 23 Jan 2011 20:55:05 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 21:03:43 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p>Du hast zur Hälfte Recht, habe übersehen, dass die Funktion ja const ist.<br />
Der Typ von this ist in der Funktion const Class* const. this ist immer const!<br />
Wo hier eine Kopie erstellt wird, sehe ich gerade nicht.</p>
<p>Edit: Entschuldige, du hast Recht, ist scheinbar nur beim GCC ein T* const <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>
</blockquote>
<p>Ja, this ist nicht const, nur halt keine Lvalue, daher &quot;verhält es sich const&quot;.</p>
<p>Und die Kopie wird beim Casten erstellt. Man kann über einen Cast ja nicht ein bestehendes Objekt &quot;mutieren&quot;, man kann nur eine Kopie erstellen. Man kann höchstens eine Kopie einer Referenz oder eines Zeigers erstellen, und über die so erhaltene Referenz bzw. den Zeiger dann auf ein bestehendes Objekt zugreifen. Dabei wird dann das &quot;eigentliche&quot; Objekt nicht kopiert. Die Referenz bzw. der Zeiger <em>wird</em> aber kopiert. Und genau das passiert hier.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2010848</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010848</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 23 Jan 2011 21:03:43 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 21:07:10 GMT]]></title><description><![CDATA[<p>Stimmt du hast Recht, bin schon etwas müde. <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2010850</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010850</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sun, 23 Jan 2011 21:07:10 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 21:20:11 GMT]]></title><description><![CDATA[<p>Eisflamme schrieb:</p>
<blockquote>
<p>Dieses eine void* übergeben bedeutet, ich habe 40 4x4-Matrizen. Diese möchte OpenGL aber als void*[40*4*4] haben.</p>
</blockquote>
<p>Du meinst so etwas wie</p>
<pre><code class="language-cpp">void ogl_func(float const*);
</code></pre>
<p>?</p>
<p>Eisflamme schrieb:</p>
<blockquote>
<p>Für das, was ich reinstecke, bietet es sich an, die Matrizen quasi in Zeilen anzugeben, also jeweils als 4er-float-Tupel.</p>
</blockquote>
<p>Ich sehe nicht, &quot;wie sich das anbietet&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2010869</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010869</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 23 Jan 2011 21:20:11 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 22:46:17 GMT]]></title><description><![CDATA[<p>Die Funktion möchte schon einen void* (bzw. GLvoid*), man gibt über einen anderen Parameter an, ob dahinter floats oder doubles stecken.</p>
<p>Und ich habe Blödsinn erzählt. Ich bin noch etwas von dem Thema verwirrt, die Matrizen übergebe ich an anderer Stelle. Hier übergebe ich so genannte BoneWeights und BoneIndices. Ich arbeite mit Shadern und die GPU arbeitet immer mit float4, also mit vier floats, je Parameter. Wenn man weniger floats nimmt, wird dennoch genau so viel Speicher akquiriert, man gewinnt also nichts. Außerdem ist man in dem, was man an die GPU gibt, beschränkt, man kann nicht beliebig viel übergeben, daher macht es Sinn speicherschonend zu arbeiten. Daher das Vierertupel an floats.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2010907</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010907</guid><dc:creator><![CDATA[Eisflamme ausgeloggt]]></dc:creator><pubDate>Sun, 23 Jan 2011 22:46:17 GMT</pubDate></item><item><title><![CDATA[Reply to boost::tuple&amp;lt;float * 4&amp;gt; als float* interpretieren? on Sun, 23 Jan 2011 23:09:55 GMT]]></title><description><![CDATA[<p>Prinzipiell sollte man sich vorher ueberlegen, wofuer man die entsprechenden Typen einsetzen moechte. In deinem Fall ist boost::tuple einfach ungeeignet. Ein Array mit fester Laenge nimmt normalerweise nicht mehr Speicherplatz weg als das Tupel.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2010915</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2010915</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Sun, 23 Jan 2011 23:09:55 GMT</pubDate></item></channel></rss>