Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost-users][lambda] crash in std::for_each
From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2009-02-03 14:24:58


On Tue, Feb 3, 2009 at 5:00 PM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
> AMDG
>
> Stuart Dootson wrote:
>>
>> Try changing the string_pair typedef to:
>>
>> std::pair<std::string const, std::string> string_pair;
>>
>> Not 100% sure *why* this makes it run rather than crash (with VC++
>> 2008, Boost 1.37.0), but it makes some sort of sense, as the key in a
>> map is immutable.
>>
>
> The reason is that std::pairs can be converted to each other.
> If the type doesn't match exactly:
> 1) It will be implicitly converted to the correct type.
> 2) Then you get a reference to first.
> 3) Then the temporary created in step 1 is destroyed
> 4) Then you stream first (which has just been destroyed)
>
> In Christ,
> Steven Watanabe
>

Thanks Steven - it's always good to get some educashun! :-)

Stuart D


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