I'm using the boost spirit x3 semantic parser as lambda functions.
I would to like assign the value of string to an "external" variable, but my code doesn't work:
template <typename Iterator>
bool comment(Iterator first, Iterator last)
{
string varName = ""; //<- this is my "extranal" variable
auto do_varName = [&](auto& ctx)
{
cout << "VAR name: " << _attr(ctx) << endl; //This work well
//This don't work; varName is a external variable
varName = std::string( _where(ctx).begin(),
_where(ctx).end()) ;
};
The varName
assumed the value of all character that are AFTER the expected content. The output of cout
is correct. Why?