|
Boost Users : |
Subject: Re: [Boost-users] [boost-users][lambda] crash in std::for_each
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-02-03 12:00:46
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
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