Build bimap with iterators ... + lower_bound(..) ?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Build bimap with iterators ... + lower_bound(..) ?

Rytuto
Hello everyone,

I have just started to use boost via boost::bimap.
I have a problem when using iterators to build a new bimap.
Here is a sample of my code :

class MyObject {...Definitions of MyObject...};
struct Position{};


// Wherever you meet Pos, it will mean Position
// Define my bimap type :
typedef boost::bimap<
        set_of<tagged<double,Position> >,
        multiset_of<tagged< MyObject*, MyObject> > // because at one position, I can have many objects .... is that right ?
    > PosMap;
typedef PosMap::value_type MyObjectPos;

PosMap posX ;
// This posX maps the position of my objects

for(MyObject::iterator it = MyObject.begin() ; it!= = MyObject.end() ; it++)
{
// it is an iterator on MyObjects

       Vector3D position = it->GetPosition() ;
//      Fill my map :
        posX.insert(MyObjectPos(position.x(), (*it)));
}

// Now I would like just to select a window on my posX bimap:
double x = something ;
double R = something else ;
//    PosMap::left_iterator tmp_itLowX  = posX.left.lower_bound(x-R);
//    PosMap::left_iterator tmp_itUpX  = posX.left.lower_bound(x+R);

// Here is my problem :
PosMap m(posX.left.lower_bound(x-R), posX.left.lower_bound(x+R));

What is wrong with this piece of code ... ?

//___________________________________________________________

Here is the output from the compiler :

./boost/bimap/container_adaptor/ordered_associative_container_adaptor.hpp: In member function ‘typename boost::bimaps::container_adaptor::ordered_associative_container_adaptor_base<Base, Iterator, ConstIterator, ReverseIterator, ConstReverseIterator, KeyType, IteratorToBaseConverter, IteratorFromBaseConverter, ReverseIteratorFromBaseConverter, ValueToBaseConverter, ValueFromBaseConverter, KeyToBaseConverter, FunctorsFromDerivedClasses>::type::iterator boost::bimaps::container_adaptor::ordered_associative_container_adaptor<Base, Iterator, ConstIterator, ReverseIterator, ConstReverseIterator, KeyType, IteratorToBaseConverter, IteratorFromBaseConverter, ReverseIteratorFromBaseConverter, ValueToBaseConverter, ValueFromBaseConverter, KeyToBaseConverter, FunctorsFromDerivedClasses>::lower_bound(const CompatibleKey&) [with CompatibleKey = double, Base = boost::multi_index::detail::ordered_index<boost::multi_index::member<boost::bimaps::relation::detail::relation_storage<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, true>, double, &boost::bimaps::relation::detail::relation_storage<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, true>::left>, std::less<double>, boost::multi_index::detail::nth_layer<2, boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true>, boost::bimaps::detail::bimap_core<boost::bimaps::set_of<boost::bimaps::tags::tagged<double, Position>, std::less<double> >, boost::bimaps::multiset_of<boost::bimaps::tags::tagged<MyObject*, MyObject>, std::less<MyObject*> >, mpl_::na, mpl_::na, mpl_::na>::core_indices, std::allocator<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true> > >, boost::mpl::v_item<Position, boost::mpl::vector0<mpl_::na>, 0>, boost::multi_index::detail::ordered_unique_tag>, Iterator = boost::bimaps::detail::set_view_iterator<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true>, std::allocator<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true> > > > > >, ConstIterator = boost::bimaps::detail::const_set_view_iterator<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true>, std::allocator<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true> > > > > >, ReverseIterator = boost::bimaps::detail::set_view_iterator<boost::reverse_iterator<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true>, std::allocator<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true> > > > > > >, ConstReverseIterator = boost::bimaps::detail::const_set_view_iterator<boost::reverse_iterator<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true>, std::allocator<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true> > > > > > >, KeyType = boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, false>, IteratorToBaseConverter = boost::bimaps::container_adaptor::support::iterator_facade_to_base<boost::bimaps::detail::set_view_iterator<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true>, std::allocator<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true> > > > > >, boost::bimaps::detail::const_set_view_iterator<boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true>, std::allocator<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true> > > > > > >, IteratorFromBaseConverter = mpl_::na, ReverseIteratorFromBaseConverter = mpl_::na, ValueToBaseConverter = boost::bimaps::relation::detail::get_mutable_relation_functor<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true> >, ValueFromBaseConverter = boost::bimaps::relation::support::get_above_view_functor<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true> >, KeyToBaseConverter = boost::bimaps::detail::set_view_key_to_base<double, boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true>, boost::multi_index::member<boost::bimaps::relation::detail::relation_storage<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, true>, double, &boost::bimaps::relation::detail::relation_storage<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, true>::left> >, FunctorsFromDerivedClasses = boost::mpl::vector<mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>]’:
include/MyObjectManager.icc:184:   instantiated from ‘std::vector<MyObject*, std::allocator<MyObject*> > MyObjectManager<T>::FindClosestITsWithinGivenRange(const ThreeVector&, double) [with T = Object]’
kit.cc:240:   instantiated from here
./boost/bimap/container_adaptor/ordered_associative_container_adaptor.hpp:257: erreur: no match for call to ‘(boost::bimaps::detail::set_view_key_to_base<double, boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true>, boost::multi_index::member<boost::bimaps::relation::detail::relation_storage<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, true>, double, &boost::bimaps::relation::detail::relation_storage<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, true>::left> >) (const double&)’
./boost/bimap/detail/set_view_base.hpp:38: note: candidats sont: const Key boost::bimaps::detail::set_view_key_to_base<Key, Value, KeyToBase>::operator()(const Value&) const [with Key = double, Value = boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, mpl_::na, true>, KeyToBase = boost::multi_index::member<boost::bimaps::relation::detail::relation_storage<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, true>, double, &boost::bimaps::relation::detail::relation_storage<boost::bimaps::tags::tagged<const double, Position>, boost::bimaps::tags::tagged<MyObject* const, MyObject>, true>::left>]

//___________________________________________________________

Thank you very much for your help and guidance,

Mathieu





_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Build bimap with iterators ... + lower_bound(..) ?

Matias Capeletto
On Thu, Feb 3, 2011 at 2:56 PM, Rytuto <[hidden email]> wrote:
> Hello everyone,

Hi, sorry I did not see your email sooner.

> I have just started to use boost via boost::bimap.
> I have a problem when using iterators to build a new bimap.

> typedef boost::bimap<
>         set_of<tagged<double,Position> >,
>         multiset_of<tagged< MyObject*, MyObject> > // because at one
> position, I can have many objects .... is that right ?
>     > PosMap;

This is exactly the other way around. Your object are unique while the
x positions can be the same, so you need a relation between a multiset
of doubles (that can hold duplicated values) and a set of your
objects.

> // Here is my problem :
> PosMap m(posX.left.lower_bound(x-R), posX.left.lower_bound(x+R));
>
> What is wrong with this piece of code ... ?

You can not use view iterators directly in the bimap set view. If you
really want to do this, you could write:

  PosMap m ;
  m.left.insert(posX.left.lower_bound(x-R), posX.left.lower_bound(x+R));

Anyways, I will recomend that if it is possible, you work directly
with the range of iterators to avoid all this copying. Read this
section of the docs, there is a range function that is really nice for
your use case:

  http://tinyurl.com/bimap-range

> Here is the output from the compiler :
>
> (snip error message)

This is strange, this error does not seems to correspond with the code
you posted above. And there are typos in your code that do not allow
to directly try your snippet. If you want others to help you faster, I
recommend that you try to isolate as much as possible your problem.

Cheers,
Matias
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users