parsing from std::string into a boost::string_view using boost::spirit::x3

后端 未结 1 550
花落未央
花落未央 2021-01-07 04:06

In my my previous question it was suggested that the performance of my boost::spirit::x3 parser could be improved by parsing into a boost::string_view

相关标签:
1条回答
  • 2021-01-07 04:17

    I'd simply write what you want:

    v = boost::string_view(&*b, std::distance(b,e));
    

    You might want to check that storage is contiguous¹ as a concept check for your input range. In that respect, it might be clearer to also require the iterator to be random-access, and write:

    v = boost::string_view(&*b, e-b);
    

    ¹ this is a requirement for string_view anyways

    0 讨论(0)
提交回复
热议问题