|
Boost Users : |
Subject: [Boost-users] Use boost::shared_ptr with boost::adaptors
From: tolik levchik (endight_at_[hidden])
Date: 2012-04-28 10:10:54
The following code gives me segfault. But if `foo_ptr` is `foo*` it works
fine.
#include <vector>
#include <boost/range/adaptor/indirected.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/algorithm/for_each.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
struct foo{
foo(int _i):
i(_i){}
virtual void bar() const{
std::cout << "foo::bar::i " << i << std::endl;
}
int i;
};
typedef boost::shared_ptr<foo> foo_ptr;
//typedef foo* foo_ptr;
foo_ptr trasform(int i){
return foo_ptr(new foo(i));
}
int main(){
std::vector<int> vec;
vec.push_back(1);
using namespace boost::adaptors; using boost::bind;
boost::for_each(vec
| transformed(bind(&trasform, _1))
| indirected,
bind(&foo::bar, _1));
}
Is it expected behavior of adaptors ?
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