Assigning parsers to auto variables

人盡茶涼 提交于 2019-11-26 15:28:45
sehe

Spirit Parsers are not designed to be used with auto in Spirit V2.

This is because the underlying Proto expression templates hold references to the temporaries.

You can use

  • qi::copy() (existing in the trunk after boost_1_55_0, not in any released version at this time)
  • boost::proto::deep_copy
  • or BOOST_SPIRIT_AUTO (first coined here)

I've written about these things more often on SO: https://stackoverflow.com/search?q=user%3A85371+deep_copy, specifically, this:

Boost Spirit X3 will not have this limitation.

Boost.Spirit uses expression templates and does not work with auto. A workaround is to use boost::proto::deep_copy:

auto bracketed_z = proto::deep_copy('[' >> +qi::char_('z') >> ']');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!