Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Iterator runtime assertion with MSVC
From: Nathan Crookston (nathan.crookston_at_[hidden])
Date: 2011-07-22 01:31:23

Hi Narinder,

On Thu, Jul 21, 2011 at 5:21 PM, Narinder Claire
<narinder.claire_at_[hidden]> wrote:
> Hello
> The following piece of code :
<snip code>
> executes fine when compiled with mingw(gcc 4.5.2) and gcc 4.5.2(Ubuntu
> 11.04) but crashes when compiled with VS2010 & VS2008. The issue seems
> to be something about not being allowed to dereference an iterator toa
> string.
> Can anyone shed any light on this ?

The problem is the result_type of the transformer struct -- it ensures
the returned string is copied, despite the return value of the
operator() call. For details on why the it_works example works, see

The it_fails example is due to the string being copied, the iterator
being retrieved, and the copied string being destroyed (all on the
it_fails initialization line). It appears that changing your
transformer declaration as follows will work:
struct transformer
   typedef const std::string& result_type;
   result_type operator()(
      const std::pair<const std::string, int> & thePair)const
       return thePair.first;


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at