Boost logo

Boost Users :

From: JOAQUIN M. LOPEZ MUÑOZ (joaquin_at_[hidden])
Date: 2008-07-07 14:02:27


________________________________________
De: boost-users-bounces_at_[hidden] [boost-users-bounces_at_[hidden]] En nombre de Igor R [boost.lists_at_[hidden]]
Enviado el: lunes, 07 de julio de 2008 16:53
Para: boost-users_at_[hidden]
Asunto: Re: [Boost-users] [boost-users][Multi-Index] crash in equal_range()

> Well, I think I've realised what happed there:
>
> RecordsBySetting bySetting = records_.get<Record::setting>();
>
> The index is copied there, and the copy is in invalid state for some
> reason. However, if take the reference, everything goes well:
>
> RecordsBySetting &bySetting = records_.get<Record::setting>();

Hi Igor,

Correct, the problem was exactly as you said: indices are not meant to be
copied and can only be referred to to via references (or pointers). You
might legitimately ask: why haven't you made their copy ctors
private/protected so as to avoid this kind of errors? Well, the copy ctors
are indeed protecetd except for those *defective* compilers for which the
Boost.Config macro BOOST_NO_MEMBER_TEMPLATE_FRIENDS
is set, among which are MSVC 8.0 and older (which I guess include the
one you're using).

This issue gets reported every so often, see for instance an older post
about it:

http://lists.boost.org/boost-users/2005/02/10055.php

To try to prevent new users from keep falling into the same trap I added
some warning text at the last paragraph of

http://www.boost.org/libs/multi_index/doc/tutorial/basics.html#multiple_sort

Unfortunately, the caveat seems not to be conspicuous enough, judging from
the number of times this problem has been reported. I'm sorry it also hit
you, hope your further experience with B.MI is more pleasant.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net