[intrusive] unordered_set::iterator_to
Hi, I'm getting compile errors trying to use iterator_to() on an unordered_set when given a const reference (and returning a const_iterator). It works fine for me with ordered set. I am able to reproduce this error by adding the following two lines: MyClass const &cr = values[0]; base_set.iterator_to(cr); to the bottom of the Example code (just before the return 0 from main) for unordered_set at: http://www.boost.org/doc/libs/1_45_0/doc/html/intrusive/unordered_set_unorde... The error is: /opt/boost/include/boost-1_38/boost/intrusive/hashtable.hpp: In member function ‘boost::intrusive::detail::hashtable_iterator<boost::intrusive::hashtable_impl<Config>, true> boost::intrusive::hashtable_impl<Config>::iterator_to(typename std::iterator_traits<typename boost::intrusive::detail::eval_if_c<boost::intrusive::hashtable_impl<Config>::external_value_traits, boost::intrusive::detail::eval_value_traits<typename Config::value_traits>, boost::intrusive::detail::identity<typename Config::value_traits>
::type::const_pointer>::reference) const [with Config = boost::intrusive::detail::usetopt<boost::intrusive::detail::base_hook_traits<MyClass, boost::intrusive::slist_node_traits<void*>, safe_link, boost::intrusive::default_tag, 4>, boost::hash<MyClass>, std::equal_to<MyClass>, long unsigned int, boost::intrusive::detail::bucket_traits_impl<boost::intrusive::detail::get_slist_impl<boost::intrusive::slist_node_traits<void*> ::type>, 3ul>]’:
/opt/boost/include/boost-1_38/boost/intrusive/unordered_set.hpp:733: instantiated from ‘typename boost::intrusive::hashtable_impl<Config>::const_iterator boost::intrusive::unordered_set_impl<Config>::iterator_to(typename boost::intrusive::hashtable_impl<Config>::const_reference) const [with Config = boost::intrusive::detail::usetopt<boost::intrusive::detail::base_hook_traits<MyClass, boost::intrusive::slist_node_traits<void*>, safe_link, boost::intrusive::default_tag, 4>, boost::hash<MyClass>, std::equal_to<MyClass>, long unsigned int, boost::intrusive::detail::bucket_traits_impl<boost::intrusive::detail::get_slist_impl<boost::intrusive::slist_node_traits<void*>
::type>, 3ul>]’
::type>, 3ul> >,
example.cpp:82: instantiated from here /opt/boost/include/boost-1_38/boost/intrusive/hashtable.hpp:1682: error: no matching function for call to ‘boost::intrusive::detail::hashtable_iterator<boost::intrusive::hashtable_impl<boost::intrusive::detail::usetopt<boost::intrusive::detail::base_hook_traits<MyClass, boost::intrusive::slist_node_traits<void*>, safe_link, boost::intrusive::default_tag, 4>, boost::hash<MyClass>, std::equal_to<MyClass>, long unsigned int, boost::intrusive::detail::bucket_traits_impl<boost::intrusive::detail::get_slist_impl<boost::intrusive::slist_node_traits<void*> true>::hashtable_iterator(boost::intrusive::slist_iterator<boost::intrusive::slist_impl<boost::intrusive::slistopt<boost::intrusive::trivial_value_traits<boost::intrusive::slist_node_traits<void*>, normal_link>, long unsigned int, false, false, false> >, true>, const boost::intrusive::hashtable_impl<boost::intrusive::detail::usetopt<boost::intrusive::detail::base_hook_traits<MyClass, boost::intrusive::slist_node_traits<void*>, safe_link, boost::intrusive::default_tag, 4>, boost::hash<MyClass>, std::equal_to<MyClass>, long unsigned int, boost::intrusive::detail::bucket_traits_impl<boost::intrusive::detail::get_slist_impl<boost::intrusive::slist_node_traits<void*>
::type>, 3ul> >* const)’
I am using 1_38_0. I have not yet tried 1_45_0, but I have gone through the entire list of fixed bugs on the release notes between 1_38 and 1_45. I'll try 1_45_0 in the next few days, just in case. I am able to work around my issue by casting away const on my reference before calling iterator_to and assigning the result back into a const_iterator, so for me it is nothing more than an annoyance, but I thought I'd bring it to your attention so it can be fixed in a future release. Thanks, Paul Rose
Hi, I just confirmed that I get the same compile error with 1_45_0 using gcc 4.2.1 (Macintosh XCode 3.2.2). Original error was with gcc 4.3.x on SuSE linux 11 Thanks, Paul Rose On Thu, Feb 10, 2011 at 12:58 PM, Paul Rose <paul.d.rose@gmail.com> wrote:
Hi,
I'm getting compile errors trying to use iterator_to() on an unordered_set when given a const reference (and returning a const_iterator).
It works fine for me with ordered set.
I am able to reproduce this error by adding the following two lines:
MyClass const &cr = values[0]; base_set.iterator_to(cr);
to the bottom of the Example code (just before the return 0 from main) for unordered_set
Sorry to keep replying to myself. To fix this I chaged: return const_iterator(bucket_type::s_iterator_to(priv_value_to_node(const_cast<reference>(value))), this); to: return const_iterator(bucket_type::s_iterator_to(const_cast<node &>(priv_value_to_node(value))), this); in file boost/intrusive/hashtable.hpp: (near line 1682 in version 1_38_0) The original code appears to be trying to call the non-const version of priv_value_to_node() by casting away the constness of the value parameter, but it doesn't work because the 'this' pointer is still const. So, the const version of priv_value_to_node() is called instead, returning a const reference. That const reference is passed to the const version of bucket_type::s_iterator_to(), which returns a const bucket (slist) iterator. Finally, a const_iterator is constructed from the const bucket iterator, but there is no constructor to support this. The lack of supporting iterator constructor seems to be by-design, because the iterator's internal slist_it_ is always non const. Either casting away the constness of the this this pointer when calling priv_value_to_node(), or casting away the constness of the returned node reference will fix the problem. I added a const_cast to the return from priv_value_to_node() and got rid of the const_cast on the input value reference (no longer necessary). Thanks, Paul Rose
Thanks Ion, After my last post, but before getting your reply, I figured out that I could post to the bug tracker. To save you from creating a dup entry, please refer to https://svn.boost.org/trac/boost/ticket/5191 BTW: I'm really enjoying using intrusive -- thanks for your efforts. Thanks again, Paul Rose 2011/2/14 Ion Gaztañaga <igaztanaga@gmail.com>
El 14/02/2011 20:48, Paul Rose escribió:
Sorry to keep replying to myself.
To fix this I changed:
Thanks for the report and the fix. I'll add it to trunk ASAP.
Best,
Ion
participants (2)
-
Ion Gaztañaga
-
Paul Rose