I'm trying to transfer parsed out the file names from regex match to the list of filesystem::path
objects.
I believe that matches are valid because for_each
for the same iterators and print to console work perfectly. However, I'm getting a segmentation fault running this code. What am I doing wrong? Is there a mistake in my lambda?
namespace fs = boost::filesystem;
std::forward_list<fs::path> results;
std::transform(std::sregex_iterator(file_data.begin(), file_data.end(), re),
std::sregex_iterator(), results.begin(),
[&](const std::smatch& m)->fs::path{
return root / fs::path(m[1].str());
});
GDB shows me this line as a place of error:
path& operator=(const path& p)
{
m_pathname = p.m_pathname;
return *this;
}
UPDATE: found the solution - use back_inserter(results)
instead of results.begin()
. However, why is that?