|
Boost Users : |
Subject: Re: [Boost-users] [boost-users][lambda] crash in std::for_each
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2009-02-03 07:29:54
On Tue, Feb 3, 2009 at 9:45 AM, Igor R <boost.lists_at_[hidden]> wrote:
> The following code crashes in for_each when trying to output the 1st pair.
> What's wrong with it?
>
> Thanks!
>
> namespace bl = boost::lambda;
> std::map<std::string, std::string> temp;
> temp["a"] = "1";
> temp["b"] = "2";
> const std::map<std::string, std::string> attrs(temp);
> typedef std::pair<std::string, std::string> string_pair;
> std::stringstream stream;
> std::for_each(attrs.begin(), attrs.end(),
> stream << bl::bind(&string_pair::first, bl::_1)
> << bl::bind(&string_pair::second, bl::_1));
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
What's the problem? This works for me - full source follows.
#include "boost/lambda/lambda.hpp"
#include "boost/lambda/bind.hpp"
#include <algorithm>
#include <map>
#include <iostream>
#include <sstream>
int main( )
{
namespace bl = boost::lambda;
std::map<std::string, std::string> temp;
temp["a"] = "1";
temp["b"] = "2";
const std::map<std::string, std::string> attrs(temp);
typedef std::pair<std::string, std::string> string_pair;
std::stringstream stream;
std::for_each(attrs.begin(), attrs.end(),
stream << bl::bind(&string_pair::first, bl::_1) <<
bl::bind(&string_pair::second, bl::_1));
}
Using Visual Studio 2005 & Boost 1.36
Rob.
--
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