<?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[std::find und boost::bind !?]]></title><description><![CDATA[<p>Also ich habe eine Klasse Entity:</p>
<pre><code class="language-cpp">class Entity {
        public:
            typedef boost::shared_ptr&lt;Entity&gt; type;
            typedef std::list&lt;type&gt; list_t;
            typedef std::list&lt;type&gt;::iterator iterator;

        private:
            std::string id;
            list_t nodes;
        public:
            Entity(std::string id);
            void add_entity(type &amp;e);
            list_t::iterator begin();

            list_t::iterator end();

            const std::string getId();

            // comparison structure
            struct Compare: std::binary_function&lt;Entity &amp;, std::string, bool&gt; {
                    result_type operator()(first_argument_type a, second_argument_type b) {
                        return (a.getId() == b);
                    }
            };
    };
</code></pre>
<p>wiie man sehen kann, gehts hier um eine Art Baumstruktur.<br />
Jetzt möchte ich also ein Kindelement anhand der Id finden.. Dazu hab ich eine abgeleitete Klasse und eine Funktion zum suchen:</p>
<pre><code class="language-cpp">Entity::type Memory::find(std::string id) {
        Entity::type result;

//        result = std::find(begin(), end(), std::bind2nd(std::mem_fun_ref(&amp;Entity::Compare()), id));
        result = std::find(begin(), end(), boost::bind(&amp;Entity::Compare(), _2, id));
        return result;
    }
</code></pre>
<p>uuund der compiler meckert:</p>
<blockquote>
<p><strong>mein gcc sag dazu</strong></p>
<p>**** Build of configuration Debug for project 01MemorySegments ****</p>
<p>make all<br />
Building file: ../Entities.cpp<br />
Invoking: GCC C++ Compiler<br />
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF&quot;Entities.d&quot; -MT&quot;Entities.d&quot; -o&quot;Entities.o&quot; &quot;../Entities.cpp&quot;<br />
../Entities.cpp: In member function ‘boost::shared_ptr<a href="docjunior::Entity" rel="nofollow">docjunior::Entity</a> docjunior::Memory::find(std::string)’:<br />
../Entities.cpp:66: warning: taking address of temporary<br />
/usr/include/boost/bind.hpp: At global scope:<br />
/usr/include/boost/bind.hpp: In instantiation of ‘boost::_bi::result_traits&lt;boost::_bi::unspecified, docjunior::Entity::Compare*&gt;’:<br />
/usr/include/boost/bind/bind_template.hpp:15: instantiated from ‘boost::_bi::bind_t&lt;boost::_bi::unspecified, docjunior::Entity::Compare*, boost::_bi::list2&lt;boost::arg&lt;2&gt; (<em>)(), boost::_bi::value&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;’<br />
../Entities.cpp:68: instantiated from here<br />
/usr/include/boost/bind.hpp:66: error: ‘docjunior::Entity::Compare</em>’ is not a class, struct, or union type<br />
../Entities.cpp: In member function ‘boost::shared_ptr<a href="docjunior::Entity" rel="nofollow">docjunior::Entity</a> docjunior::Memory::find(std::string)’:<br />
../Entities.cpp:68: error: no match for ‘operator=’ in ‘result = std::find [with _IIter = std::_List_iterator&lt;boost::shared_ptr<a href="docjunior::Entity" rel="nofollow">docjunior::Entity</a> &gt;, _Tp = boost::_bi::bind_t&lt;boost::_bi::unspecified, docjunior::Entity::Compare*, boost::_bi::list2&lt;boost::arg&lt;2&gt; (<em>)(), boost::_bi::value&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;](((docjunior::Memory</em>)this)-&gt;docjunior::Memory::&lt;anonymous&gt;.docjunior::Entity::begin(), ((docjunior::Memory*)this)-&gt;docjunior::Memory::&lt;anonymous&gt;.docjunior::Entity::end(), ((const boost::_bi::bind_t&lt;boost::_bi::unspecified, docjunior::Entity::Compare*, boost::_bi::list2&lt;boost::arg&lt;2&gt; (<em>)(), boost::_bi::value&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;&amp;)((const boost::_bi::bind_t&lt;boost::_bi::unspecified, docjunior::Entity::Compare</em>, boost::_bi::list2&lt;boost::arg&lt;2&gt; (<em>)(), boost::_bi::value&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;</em>)(&amp; boost::bind(F, A1, A2) [with F = docjunior::Entity::Compare*, A1 = boost::arg&lt;2&gt; (<em>)(), A2 = std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;](&lt;unnamed&gt;::_2, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;(((const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;&amp;)((const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;</em>)(&amp; id)))))))))’<br />
/usr/include/boost/shared_ptr.hpp:177: note: candidates are: boost::shared_ptr&lt;T&gt;&amp; boost::shared_ptr&lt;T&gt;::operator=(const boost::shared_ptr&lt;T&gt;&amp;) [with T = docjunior::Entity]<br />
/usr/include/c++/4.3/bits/stl_algo.h: In function ‘_InputIterator std::__find(_InputIterator, _InputIterator, const _Tp&amp;, std::input_iterator_tag) [with _InputIterator = std::_List_iterator&lt;boost::shared_ptr<a href="docjunior::Entity" rel="nofollow">docjunior::Entity</a> &gt;, _Tp = boost::_bi::bind_t&lt;boost::_bi::unspecified, docjunior::Entity::Compare*, boost::_bi::list2&lt;boost::arg&lt;2&gt; (<em>)(), boost::_bi::value&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;]’:<br />
/usr/include/c++/4.3/bits/stl_algo.h:3814: instantiated from ‘_IIter std::find(_IIter, _IIter, const _Tp&amp;) [with _IIter = std::_List_iterator&lt;boost::shared_ptr<a href="docjunior::Entity" rel="nofollow">docjunior::Entity</a> &gt;, _Tp = boost::_bi::bind_t&lt;boost::_bi::unspecified, docjunior::Entity::Compare</em>, boost::_bi::list2&lt;boost::arg&lt;2&gt; (<em>)(), boost::_bi::value&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;]’<br />
../Entities.cpp:68: instantiated from here<br />
/usr/include/c++/4.3/bits/stl_algo.h:151: error: no match for ‘operator==’ in ‘__first.std::_List_iterator&lt;_Tp&gt;::operator</em> [with _Tp = boost::shared_ptr<a href="docjunior::Entity" rel="nofollow">docjunior::Entity</a>]() == __val’<br />
make: *** [Entities.o] Fehler 1</p>
</blockquote>
<p>Mein Verständnis in der Richtung ist arg begrenzt, aaber gerade jetzt brauch ich sowas halt..<br />
Wie kann ich also die compare-funktion für mein find aufrufen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/255460/std-find-und-boost-bind</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 23:42:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/255460.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 01 Dec 2009 09:22:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::find und boost::bind !? on Tue, 01 Dec 2009 09:31:07 GMT]]></title><description><![CDATA[<p>Also ich habe eine Klasse Entity:</p>
<pre><code class="language-cpp">class Entity {
        public:
            typedef boost::shared_ptr&lt;Entity&gt; type;
            typedef std::list&lt;type&gt; list_t;
            typedef std::list&lt;type&gt;::iterator iterator;

        private:
            std::string id;
            list_t nodes;
        public:
            Entity(std::string id);
            void add_entity(type &amp;e);
            list_t::iterator begin();

            list_t::iterator end();

            const std::string getId();

            // comparison structure
            struct Compare: std::binary_function&lt;Entity &amp;, std::string, bool&gt; {
                    result_type operator()(first_argument_type a, second_argument_type b) {
                        return (a.getId() == b);
                    }
            };
    };
</code></pre>
<p>wiie man sehen kann, gehts hier um eine Art Baumstruktur.<br />
Jetzt möchte ich also ein Kindelement anhand der Id finden.. Dazu hab ich eine abgeleitete Klasse und eine Funktion zum suchen:</p>
<pre><code class="language-cpp">Entity::type Memory::find(std::string id) {
        Entity::type result;

//        result = std::find(begin(), end(), std::bind2nd(std::mem_fun_ref(&amp;Entity::Compare()), id));
        result = std::find(begin(), end(), boost::bind(&amp;Entity::Compare(), _2, id));
        return result;
    }
</code></pre>
<p>uuund der compiler meckert:</p>
<blockquote>
<p><strong>mein gcc sag dazu</strong></p>
<p>**** Build of configuration Debug for project 01MemorySegments ****</p>
<p>make all<br />
Building file: ../Entities.cpp<br />
Invoking: GCC C++ Compiler<br />
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF&quot;Entities.d&quot; -MT&quot;Entities.d&quot; -o&quot;Entities.o&quot; &quot;../Entities.cpp&quot;<br />
../Entities.cpp: In member function ‘boost::shared_ptr<a href="docjunior::Entity" rel="nofollow">docjunior::Entity</a> docjunior::Memory::find(std::string)’:<br />
../Entities.cpp:66: warning: taking address of temporary<br />
/usr/include/boost/bind.hpp: At global scope:<br />
/usr/include/boost/bind.hpp: In instantiation of ‘boost::_bi::result_traits&lt;boost::_bi::unspecified, docjunior::Entity::Compare*&gt;’:<br />
/usr/include/boost/bind/bind_template.hpp:15: instantiated from ‘boost::_bi::bind_t&lt;boost::_bi::unspecified, docjunior::Entity::Compare*, boost::_bi::list2&lt;boost::arg&lt;2&gt; (<em>)(), boost::_bi::value&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;’<br />
../Entities.cpp:68: instantiated from here<br />
/usr/include/boost/bind.hpp:66: error: ‘docjunior::Entity::Compare</em>’ is not a class, struct, or union type<br />
../Entities.cpp: In member function ‘boost::shared_ptr<a href="docjunior::Entity" rel="nofollow">docjunior::Entity</a> docjunior::Memory::find(std::string)’:<br />
../Entities.cpp:68: error: no match for ‘operator=’ in ‘result = std::find [with _IIter = std::_List_iterator&lt;boost::shared_ptr<a href="docjunior::Entity" rel="nofollow">docjunior::Entity</a> &gt;, _Tp = boost::_bi::bind_t&lt;boost::_bi::unspecified, docjunior::Entity::Compare*, boost::_bi::list2&lt;boost::arg&lt;2&gt; (<em>)(), boost::_bi::value&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;](((docjunior::Memory</em>)this)-&gt;docjunior::Memory::&lt;anonymous&gt;.docjunior::Entity::begin(), ((docjunior::Memory*)this)-&gt;docjunior::Memory::&lt;anonymous&gt;.docjunior::Entity::end(), ((const boost::_bi::bind_t&lt;boost::_bi::unspecified, docjunior::Entity::Compare*, boost::_bi::list2&lt;boost::arg&lt;2&gt; (<em>)(), boost::_bi::value&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;&amp;)((const boost::_bi::bind_t&lt;boost::_bi::unspecified, docjunior::Entity::Compare</em>, boost::_bi::list2&lt;boost::arg&lt;2&gt; (<em>)(), boost::_bi::value&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;</em>)(&amp; boost::bind(F, A1, A2) [with F = docjunior::Entity::Compare*, A1 = boost::arg&lt;2&gt; (<em>)(), A2 = std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;](&lt;unnamed&gt;::_2, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;(((const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;&amp;)((const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;</em>)(&amp; id)))))))))’<br />
/usr/include/boost/shared_ptr.hpp:177: note: candidates are: boost::shared_ptr&lt;T&gt;&amp; boost::shared_ptr&lt;T&gt;::operator=(const boost::shared_ptr&lt;T&gt;&amp;) [with T = docjunior::Entity]<br />
/usr/include/c++/4.3/bits/stl_algo.h: In function ‘_InputIterator std::__find(_InputIterator, _InputIterator, const _Tp&amp;, std::input_iterator_tag) [with _InputIterator = std::_List_iterator&lt;boost::shared_ptr<a href="docjunior::Entity" rel="nofollow">docjunior::Entity</a> &gt;, _Tp = boost::_bi::bind_t&lt;boost::_bi::unspecified, docjunior::Entity::Compare*, boost::_bi::list2&lt;boost::arg&lt;2&gt; (<em>)(), boost::_bi::value&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;]’:<br />
/usr/include/c++/4.3/bits/stl_algo.h:3814: instantiated from ‘_IIter std::find(_IIter, _IIter, const _Tp&amp;) [with _IIter = std::_List_iterator&lt;boost::shared_ptr<a href="docjunior::Entity" rel="nofollow">docjunior::Entity</a> &gt;, _Tp = boost::_bi::bind_t&lt;boost::_bi::unspecified, docjunior::Entity::Compare</em>, boost::_bi::list2&lt;boost::arg&lt;2&gt; (<em>)(), boost::_bi::value&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;]’<br />
../Entities.cpp:68: instantiated from here<br />
/usr/include/c++/4.3/bits/stl_algo.h:151: error: no match for ‘operator==’ in ‘__first.std::_List_iterator&lt;_Tp&gt;::operator</em> [with _Tp = boost::shared_ptr<a href="docjunior::Entity" rel="nofollow">docjunior::Entity</a>]() == __val’<br />
make: *** [Entities.o] Fehler 1</p>
</blockquote>
<p>Mein Verständnis in der Richtung ist arg begrenzt, aaber gerade jetzt brauch ich sowas halt..<br />
Wie kann ich also die compare-funktion für mein find aufrufen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1815782</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1815782</guid><dc:creator><![CDATA[DocJunioR]]></dc:creator><pubDate>Tue, 01 Dec 2009 09:31:07 GMT</pubDate></item><item><title><![CDATA[Reply to std::find und boost::bind !? on Tue, 01 Dec 2009 09:36:16 GMT]]></title><description><![CDATA[<p>DocJunioR schrieb:</p>
<blockquote>
<pre><code class="language-cpp">boost::bind(&amp;Entity::Compare(), _2, id)
</code></pre>
</blockquote>
<p>Ohne die Fehlermeldung studiert zu haben: Entity::Compare() ist ein rvalue, der Adressoperator arbeitet nur mit lvalues.<br />
Hm.. der Compiler gibt dazu sogar eine Warnung aus.<br />
Selbst wenn das Adresse ermitteln möglich wäre, hättest du dann nur einen einfachen Zeiger...</p>
<p>Soll vermutlich so aussehen:</p>
<pre><code class="language-cpp">boost::bind(Entity::Compare(), _2, id)
</code></pre>
<p>oder du machst aus Enitity::Compare eine nichtstatische Memberfunktion. Dann sollte es auch mit der kommentierten Version klappen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1815790</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1815790</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Tue, 01 Dec 2009 09:36:16 GMT</pubDate></item><item><title><![CDATA[Reply to std::find und boost::bind !? on Tue, 01 Dec 2009 10:09:39 GMT]]></title><description><![CDATA[<p>da bleibt dann trotzdem noch folgendes:</p>
<p>Description Resource Path Location Type<br />
no match for ‘operator==’ in ‘__first.std::_List_iterator&lt;_Tp&gt;::operator* [with _Tp = boost::shared_ptr<a href="docjunior::Entity" rel="nofollow">docjunior::Entity</a>]() == __val’ 01MemorySegments line 151, external location: /usr/include/c++/4.3/bits/stl_algo.h C/C++ Problem</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1815807</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1815807</guid><dc:creator><![CDATA[DocJunioR]]></dc:creator><pubDate>Tue, 01 Dec 2009 10:09:39 GMT</pubDate></item><item><title><![CDATA[Reply to std::find und boost::bind !? on Tue, 01 Dec 2009 10:44:45 GMT]]></title><description><![CDATA[<p>DocJunioR schrieb:</p>
<blockquote>
<p>da bleibt dann trotzdem noch folgendes:</p>
<p>Description Resource Path Location Type<br />
no match for ‘operator==’ in ‘__first.std::_List_iterator&lt;_Tp&gt;::operator* [with _Tp = boost::shared_ptr<a href="docjunior::Entity" rel="nofollow">docjunior::Entity</a>]() == __val’ 01MemorySegments line 151, external location: /usr/include/c++/4.3/bits/stl_algo.h C/C++ Problem</p>
</blockquote>
<p>Ich könnte zwar raten, aber letztlich reicht der Code nicht aus. Schon weil unklar bleibt, was begin und end für Iteratoren sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1815823</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1815823</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Tue, 01 Dec 2009 10:44:45 GMT</pubDate></item><item><title><![CDATA[Reply to std::find und boost::bind !? on Tue, 01 Dec 2009 12:16:14 GMT]]></title><description><![CDATA[<p>begin() und end() sind delegatoren und zeigen auf begin() und end() der liste</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1815865</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1815865</guid><dc:creator><![CDATA[DocJunioR]]></dc:creator><pubDate>Tue, 01 Dec 2009 12:16:14 GMT</pubDate></item><item><title><![CDATA[Reply to std::find und boost::bind !? on Tue, 01 Dec 2009 12:24:34 GMT]]></title><description><![CDATA[<p>was du willst ist std::find_if nicht std::find</p>
<p>Regards,</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1815872</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1815872</guid><dc:creator><![CDATA[evilissimo]]></dc:creator><pubDate>Tue, 01 Dec 2009 12:24:34 GMT</pubDate></item><item><title><![CDATA[Reply to std::find und boost::bind !? on Tue, 01 Dec 2009 13:00:39 GMT]]></title><description><![CDATA[<p>das ist zwar richtig, hilft aber auch nicht.<br />
hab jetzt mal einfach nen workaround über ne map realisiert und les mir das thema nochmal genauer durch, wenn ich die zeit hab..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1815885</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1815885</guid><dc:creator><![CDATA[DocJunioR]]></dc:creator><pubDate>Tue, 01 Dec 2009 13:00:39 GMT</pubDate></item><item><title><![CDATA[Reply to std::find und boost::bind !? on Tue, 01 Dec 2009 15:27:32 GMT]]></title><description><![CDATA[<p>war mist</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1815967</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1815967</guid><dc:creator><![CDATA[ipsec]]></dc:creator><pubDate>Tue, 01 Dec 2009 15:27:32 GMT</pubDate></item></channel></rss>