using std::list<boost::weak_ptr<T> >

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello! I am new to using boost smart pointers, so this might be a FAQ; but I was not able to find the answer :-( The documatation on boost::week_ptr says:
Every weak_ptr meets the CopyConstructible and Assignable requirements of the C++ Standard Library, and so can be used in standard library containers. Comparison operators are supplied so that weak_ptr works with the standard library's associative containers.
So, I thought, I might use a std::list of boost::weak_ptr. But my compiler complains about std::list::remove():
In member function `void std::list<_Tp, _Alloc>::remove(const _Tp&) [with _Tp = boost::weak_ptr<Channel>, _Alloc = std::allocator<boost::weak_ptr<Channel> >]': error: no match for 'operator==' in '(&__first)-
std::_List_iterator<_Tp>::operator* [with _Tp = boost::weak_ptr<Channel>]() == __value'
It seems, that the compiler does not find an operator== for the boost::weak_ptr. The documentation does not mention such an operator, too. So, can I have a std::list of boost::weak_ptr? Thanks in advance, Mario - -- Mario Klebsch mkl@innodyne.de Innovative Dynamics GmbH http://www.innodyne.de Wiesenweg 9 Tel: +49 5304 91 19 410 38533 Vordorf / Rethen Fax: +49 5304 91 19 412 Geschäftsführer: Dipl. Phys. Gerhard Heidkamp Sitz: 38533 Vordorf - Rethen, Wiesenweg 9 Handelsregister beim Amtsgericht Hildesheim HRB 100553, USt-Id Nr. DE 215 876 442 SICHERHEITSHINWEIS: =================== Diese Email ist elektronisch signiert. InnoDyne versendet grundsätzlich seit dem 11.9.2006 verbindliche Dokumente nur als signierte PDF - Dateien oder elektronisch nachprüfbar signierte Emails. Juristisch und technisch verbindliche Dokumente dürfen das Haus InnoDyne nicht als andere Datei- formate verlassen. Sollten Sie ein signiertes, technisch oder kauf- männisch/juristisch verbindliches Dokument in einem anderen Dateiformat als PDF oder signierte Email von InnoDyne erhalten, so ist dies sehr wahrscheinlich ein Versehen des Versenders, eine Software - Fehlfunktion oder schlimmer noch, eine Fälschung. Wir bitten in einem solchen Fall um sofortige Information und Übermittlung solcher Dokumente an gl@innodyne.de -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) iEYEARECAAYFAkndz6MACgkQDwNq2neCwq6CeACgkTu1xYLv6qrlTmVlW97eMALq fvQAnR7Xmfb2LPtYctyVjtXLTirK/2ze =EH4C -----END PGP SIGNATURE-----

Mario Klebsch: ...
So, I thought, I might use a std::list of boost::weak_ptr. But my compiler complains about std::list::remove():
...
It seems, that the compiler does not find an operator== for the boost::weak_ptr.
weak_ptr has no operator==. You need to use remove_if instead of remove, passing it one of: bool eq( weak_ptr<Channel> const & p, weak_ptr<Channel> const & q ) { return p.lock() == q.lock(); } bool eq2( weak_ptr<Channel> const & p, weak_ptr<Channel> const & q ) { return !(p < q) && !(q < p); } Which one is better depends on your specific use case. The first one considers two weak_ptr instances to be equal when they point to the same object. The second one considers two weak_ptr instances to be equal when they are copies.
participants (2)
-
Mario Klebsch
-
Peter Dimov