<?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[Typ von Elementen in boost::ptr_vector]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>wie komme ich an den Typen dran, der in einem boost::ptr_vector ist?</p>
<pre><code class="language-cpp">#include &lt;memory&gt;
#include &lt;boost/ptr_container/ptr_vector.hpp&gt;

struct Foo{
        typedef int type;
        type value;
};

struct Bar{
        typedef double type;
        type value;
};

template&lt;typename T&gt;
void func(T&amp; t){
        for(typename T::reference obj : t){
                typename T::value_type::type v; 
                v = obj.value;
        }
}

int main(){
        boost::ptr_vector&lt;Foo&gt; v1;
        boost::ptr_vector&lt;Bar&gt; v2;
        func(v1);
        func(v2);
}
</code></pre>
<p>Generell hätte ich vermutet, dass es der typedef value_type ist, aber das funktioniert leider nicht.</p>
<pre><code>test.cpp: In function 'void func(T&amp;) [with T = boost::ptr_vector&lt;Foo&gt;]':
test.cpp:25:9:   instantiated from here
test.cpp:17:32: error: 'boost::ptr_sequence_adapter&lt;Foo, std::vector&lt;void*, std::allocator&lt;void*&gt; &gt;, boost::heap_clone_allocator&gt;::value_type' is not a class, struct, or union type
test.cpp:17:32: error: 'boost::ptr_sequence_adapter&lt;Foo, std::vector&lt;void*, std::allocator&lt;void*&gt; &gt;, boost::heap_clone_allocator&gt;::value_type' is not a class, struct, or union type
test.cpp: In function 'void func(T&amp;) [with T = boost::ptr_vector&lt;Bar&gt;]':
test.cpp:26:9:   instantiated from here
test.cpp:17:32: error: 'boost::ptr_sequence_adapter&lt;Bar, std::vector&lt;void*, std::allocator&lt;void*&gt; &gt;, boost::heap_clone_allocator&gt;::value_type' is not a class, struct, or union type
test.cpp:17:32: error: 'boost::ptr_sequence_adapter&lt;Bar, std::vector&lt;void*, std::allocator&lt;void*&gt; &gt;, boost::heap_clone_allocator&gt;::value_type' is not a class, struct, or union type
</code></pre>
<p>Ich hab leider auch keinen passenden typedef beim Durchsuchen des Quelltexts gefunden.</p>
<p>Steh ich gerade auf dem Schlauch? <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>Wer kann mir den passenden typedef sagen oder wie man an den Typ dran kommt?</p>
<p>Gruß,<br />
XSpille</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/291119/typ-von-elementen-in-boost-ptr_vector</link><generator>RSS for Node</generator><lastBuildDate>Mon, 17 Aug 2026 22:23:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/291119.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 Aug 2011 01:05:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Typ von Elementen in boost::ptr_vector on Thu, 11 Aug 2011 01:05:48 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>wie komme ich an den Typen dran, der in einem boost::ptr_vector ist?</p>
<pre><code class="language-cpp">#include &lt;memory&gt;
#include &lt;boost/ptr_container/ptr_vector.hpp&gt;

struct Foo{
        typedef int type;
        type value;
};

struct Bar{
        typedef double type;
        type value;
};

template&lt;typename T&gt;
void func(T&amp; t){
        for(typename T::reference obj : t){
                typename T::value_type::type v; 
                v = obj.value;
        }
}

int main(){
        boost::ptr_vector&lt;Foo&gt; v1;
        boost::ptr_vector&lt;Bar&gt; v2;
        func(v1);
        func(v2);
}
</code></pre>
<p>Generell hätte ich vermutet, dass es der typedef value_type ist, aber das funktioniert leider nicht.</p>
<pre><code>test.cpp: In function 'void func(T&amp;) [with T = boost::ptr_vector&lt;Foo&gt;]':
test.cpp:25:9:   instantiated from here
test.cpp:17:32: error: 'boost::ptr_sequence_adapter&lt;Foo, std::vector&lt;void*, std::allocator&lt;void*&gt; &gt;, boost::heap_clone_allocator&gt;::value_type' is not a class, struct, or union type
test.cpp:17:32: error: 'boost::ptr_sequence_adapter&lt;Foo, std::vector&lt;void*, std::allocator&lt;void*&gt; &gt;, boost::heap_clone_allocator&gt;::value_type' is not a class, struct, or union type
test.cpp: In function 'void func(T&amp;) [with T = boost::ptr_vector&lt;Bar&gt;]':
test.cpp:26:9:   instantiated from here
test.cpp:17:32: error: 'boost::ptr_sequence_adapter&lt;Bar, std::vector&lt;void*, std::allocator&lt;void*&gt; &gt;, boost::heap_clone_allocator&gt;::value_type' is not a class, struct, or union type
test.cpp:17:32: error: 'boost::ptr_sequence_adapter&lt;Bar, std::vector&lt;void*, std::allocator&lt;void*&gt; &gt;, boost::heap_clone_allocator&gt;::value_type' is not a class, struct, or union type
</code></pre>
<p>Ich hab leider auch keinen passenden typedef beim Durchsuchen des Quelltexts gefunden.</p>
<p>Steh ich gerade auf dem Schlauch? <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>Wer kann mir den passenden typedef sagen oder wie man an den Typ dran kommt?</p>
<p>Gruß,<br />
XSpille</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2104693</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104693</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Thu, 11 Aug 2011 01:05:48 GMT</pubDate></item><item><title><![CDATA[Reply to Typ von Elementen in boost::ptr_vector on Thu, 11 Aug 2011 01:12:22 GMT]]></title><description><![CDATA[<p>Ich hab jetzt ne (dubiose) Lösung gefunden...</p>
<pre><code class="language-cpp">typename boost::remove_reference&lt;typename T::reference&gt;::type::type v;
</code></pre>
<p>Geht es nicht einfacher?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2104695</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104695</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Thu, 11 Aug 2011 01:12:22 GMT</pubDate></item><item><title><![CDATA[Reply to Typ von Elementen in boost::ptr_vector on Thu, 11 Aug 2011 10:45:53 GMT]]></title><description><![CDATA[<p>Wenn du ohnehin schon C++0x-Features benutzt, warum nicht gleich <code>auto</code> ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2104816</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104816</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Thu, 11 Aug 2011 10:45:53 GMT</pubDate></item><item><title><![CDATA[Reply to Typ von Elementen in boost::ptr_vector on Thu, 11 Aug 2011 10:53:08 GMT]]></title><description><![CDATA[<p>Da es sich ja um den ptr_vector handelt, würde ich davon ausgehen, das value_type ein Pointertyp ist, als z.b. Foo*</p>
<p>Kannst du ja leicht überprüfen mit folgender Krücke:</p>
<pre><code class="language-cpp">ptr_vector&lt;Foo&gt;::value_type foo;
double i = foo;
</code></pre>
<p>Das sollte dann einen Kompilerfehler der folgender Art erzeugen:</p>
<pre><code>Couldn't convert Type ... to double
</code></pre>
<p>Oder ähnlich.</p>
<p>Und dort steht dann der Typ da <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/2104823</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104823</guid><dc:creator><![CDATA[bmario]]></dc:creator><pubDate>Thu, 11 Aug 2011 10:53:08 GMT</pubDate></item><item><title><![CDATA[Reply to Typ von Elementen in boost::ptr_vector on Thu, 11 Aug 2011 10:56:48 GMT]]></title><description><![CDATA[<p>bmario schrieb:</p>
<blockquote>
<p>Da es sich ja um den ptr_vector handelt, würde ich davon ausgehen, das value_type ein Pointertyp ist, als z.b. Foo*</p>
</blockquote>
<p>Genau. Um den Werttyp zu erhalten, könnte man <code>remove_pointer&lt;Container::value_type&gt;::type</code> schreiben. Oder direkt Typinferenz nutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2104826</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104826</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Thu, 11 Aug 2011 10:56:48 GMT</pubDate></item><item><title><![CDATA[Reply to Typ von Elementen in boost::ptr_vector on Thu, 11 Aug 2011 11:17:46 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>Wenn du ohnehin schon C++0x-Features benutzt, warum nicht gleich <code>auto</code> ?</p>
</blockquote>
<p>Danke Nexus!<br />
Weil ich es bisher noch nicht kannte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /><br />
Aber stylistisch find ich es ehrlich gesagt auch nicht so schön <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><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/25467">@bmario</a></p>
<pre><code>test.cpp:27:13: error: cannot convert 'boost::ptr_sequence_adapter&lt;Foo, std::vector&lt;void*, std::allocator&lt;void*&gt; &gt;, boost::heap_clone_allocator&gt;::value_type' to 'double' in initialization
</code></pre>
<p>So einleuchtend find ich die Fehlermeldung leider nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/12954">@Nexus</a>:<br />
Ob remove_reference oder remove_pointer... So einen großen Unterschied sehe ich nicht in der Lesbarkeit <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="😉"
    /><br />
EDIT: Die Verwendung von value_type ist doch etwas schöner...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2104832</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104832</guid><dc:creator><![CDATA[XSpille]]></dc:creator><pubDate>Thu, 11 Aug 2011 11:17:46 GMT</pubDate></item></channel></rss>