Boost logo

Boost Users :

Subject: [Boost-users] Boost.Iterator runtime assertion with MSVC
From: Narinder Claire (narinder.claire_at_[hidden])
Date: 2011-07-21 19:21:24


Hello

The following piece of code :

____________________
#include<string>
#include<map>
#include<iostream>
#include<iterator>

#include<boost/iterator/transform_iterator.hpp>

typedef std::map<std::string, int> map;
typedef map::const_iterator const_iterator;

struct transformer
{
    typedef std::string result_type;
    const result_type & operator()(const std::pair<const result_type,
int> & thePair)const
    {
        return thePair.first;
    }
};

typedef boost::transform_iterator<transformer, const_iterator >
const_key_iterator;

int main()
{
    map m;
    m["one"]=1;
    m["two"]=2;

    const_key_iterator key_iterator(m.begin(),transformer());

    // Following 3 lines work fine
    const std::string &temp = *key_iterator;
    std::string::const_iterator it_works = temp.begin();
    std::cout << *it_works;

    // Following 2 lines cause crash when
    // compiled with VS2010 & VS2008
    std::string::const_iterator it_fails = key_iterator->begin();
    std::cout << *it_fails ;

}

________________________________

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 ?
I ensured that language extensions were NOT disabled.

Rgds
N


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