|
Boost Users : |
Subject: [Boost-users] New-style for on an iterator-range of filter_iterator of strings crashes/hangs
From: Ami Tavory (atavory_at_[hidden])
Date: 2013-11-23 14:12:58
Hello,
Using g++ 4.8.1 (g++ (Ubuntu/Linaro 4.8.1-10ubuntu8) 4.8.1) with boost
1.5.3, building the code below with
{{{
g++ -o example/filter.out -std=c++0x -Wall -g -rdynamic
-I/usr/include/boost example/filter.cpp
}}}
{{{
#include
<vector>
#include <string>
#include <iostream>
#include <functional>
#include <boost/iterator/filter_iterator.hpp>
#include <boost/range/iterator_range.hpp>
using namespace std;
using namespace boost;
int main()
{
vector<string> ss{"hello", "world"};
// function<bool (const string &)> fn = [](const string &s){return
false;};
function<bool (const string &)> fn = [](const string &s){return
s.size() > 3;};
cout << fn("Hello") << endl; // (1)
cout << fn("world") << endl; // (2)
typedef
filter_iterator<function<bool (const string &)>,
vector<string>::const_iterator>
filter_it_t;
auto r = make_iterator_range(filter_it_t(fn, ss.begin()),
filter_it_t(fn, ss.end()));
for(const string &a: r)
cout << a << endl;
return 0;
}
}}}
yields an executable that crashes with
{{{
Segmentation fault (core dumped)
}}}
Exchanging the comment in the two lines
{{{
// function<bool (const string &)> fn = [](const string &s){return
false;};
function<bool (const string &)> fn = [](const string &s){return
s.size() > 3;};
}}}
(so that the first lambda is used) yields an executable that hangs.
In either case, the application first prints the results of the lines
marked (1) and (2).
Can't figure out what I'm doing wrong, and would appreciate advice.
Thanks,
Ami
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