Описание проблемы
У меня есть тривиальная структура, адаптированная для boost::fusion
:
struct Node
{
std::string text;
};
BOOST_FUSION_ADAPT_STRUCT(Node, (std::string, text))
У меня есть грамматика с набором правил:
boost::spirit::qi::rule<Iterator, Node()> node_line;
boost::spirit::qi::rule<Iterator, Node()> node;
И есть одно правило, которое бросается мне в глаза:
node_line %= " * " >> node;
Я ожидаю, что это будет допустимо, поскольку атрибут литерала — unused
, а node_line
и node
имеют одинаковый тип атрибута. Вместо этого компилятор жалуется:
/usr/include/boost/spirit/home/support/container.hpp:262:13: error: no matching function for call to ‘std::basic_string<char>::insert(std::basic_string<char>::iterator, const Node&)’
т.е. компилятор пытается добавить struct Node
к std::string
. Я совершенно смущен тем, почему он пытается это сделать. Есть предположения?
Полный код
#include <boost/config/warning_disable.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/include/qi.hpp>
struct Node
{
std::string text;
};
BOOST_FUSION_ADAPT_STRUCT(Node, (std::string, text))
template <typename Iterator>
struct My_parser : boost::spirit::qi::grammar<Iterator, Node()>
{
My_parser()
: My_parser::base_type(node_line)
{
name %= +boost::spirit::ascii::char_;
node %= name;
node_line %= " * " >> node;
// node_line %= node;
}
boost::spirit::qi::rule<Iterator, std::string()> name;
boost::spirit::qi::rule<Iterator, Node()> node_line;
boost::spirit::qi::rule<Iterator, Node()> node;
};
int main()
{
const std::string input(" * Some text");
Node parsed;
My_parser<std::string::const_iterator> my_parser;
bool r = parse(input.begin(), input.end(), my_parser, parsed);
if(r)
std::cout << "Match: " << parsed.text << std::endl;
else
std::cout << "No match" << std::endl;
return 0;
}
Полное сообщение об ошибке
In file included from /usr/include/boost/spirit/home/support/string_traits.hpp:16:0,
from /usr/include/boost/spirit/home/support/nonterminal/expand_arg.hpp:20,
from /usr/include/boost/spirit/home/support/context.hpp:15,
from /usr/include/boost/spirit/home/qi/domain.hpp:18,
from /usr/include/boost/spirit/home/qi/meta_compiler.hpp:15,
from /usr/include/boost/spirit/home/qi/action/action.hpp:14,
from /usr/include/boost/spirit/home/qi/action.hpp:14,
from /usr/include/boost/spirit/home/qi.hpp:14,
from /usr/include/boost/spirit/include/qi.hpp:16,
from tt.cc:3:
/usr/include/boost/spirit/home/support/container.hpp: In static member function ‘static bool boost::spirit::traits::push_back_container<Container, T, Enable>::call(Container&, const T&) [with Container = std::basic_string<char>, T = Node, Enable = void]’:
/usr/include/boost/spirit/home/support/container.hpp:324:62: instantiated from ‘bool boost::spirit::traits::push_back(Container&, const T&) [with Container = std::basic_string<char>, T = Node]’
/usr/include/boost/spirit/home/qi/detail/assign_to.hpp:168:13: instantiated from ‘static void boost::spirit::traits::assign_to_container_from_value<Attribute, T, Enable>::call(const T_&, Attribute&, mpl_::false_, mpl_::false_) [with T_ = Node, Attribute = std::basic_string<char>, T = Node, Enable = void, mpl_::false_ = mpl_::bool_<false>]’
/usr/include/boost/spirit/home/qi/detail/assign_to.hpp:203:13: instantiated from ‘static void boost::spirit::traits::assign_to_container_from_value<Attribute, T, Enable>::call(const T&, Attribute&) [with Attribute = std::basic_string<char>, T = Node, Enable = void]’
/usr/include/boost/spirit/home/qi/detail/assign_to.hpp:243:13: instantiated from ‘void boost::spirit::traits::detail::assign_to(const T&, Attribute&, mpl_::true_, mpl_::true_) [with T = Node, Attribute = std::basic_string<char>, mpl_::true_ = mpl_::bool_<true>]’
/usr/include/boost/spirit/home/qi/detail/assign_to.hpp:257:9: instantiated from ‘void boost::spirit::traits::assign_to(const T&, Attribute&) [with T = Node, Attribute = std::basic_string<char>]’
/usr/include/boost/spirit/home/qi/detail/attributes.hpp:26:13: [ skipping 12 instantiation contexts ]
/usr/include/boost/function/function_template.hpp:913:60: instantiated from ‘void boost::function4<R, T1, T2, T3, T4>::assign_to(Functor) [with Functor = boost::spirit::qi::detail::parser_binder<boost::spirit::qi::sequence<boost::fusion::cons<boost::spirit::qi::literal_string<const char (&)[5], true>, boost::fusion::cons<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, Node(), boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> >, boost::fusion::nil> > >, mpl_::bool_<true> >, R = bool, T0 = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >&, T1 = const __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >&, T2 = boost::spirit::context<boost::fusion::cons<Node&, boost::fusion::nil>, boost::fusion::vector0<> >&, T3 = const boost::spirit::unused_type&]’
/usr/include/boost/function/function_template.hpp:722:7: instantiated from ‘boost::function4<R, T1, T2, T3, T4>::function4(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::spirit::qi::detail::parser_binder<boost::spirit::qi::sequence<boost::fusion::cons<boost::spirit::qi::literal_string<const char (&)[5], true>, boost::fusion::cons<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, Node(), boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> >, boost::fusion::nil> > >, mpl_::bool_<true> >, R = bool, T0 = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >&, T1 = const __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >&, T2 = boost::spirit::context<boost::fusion::cons<Node&, boost::fusion::nil>, boost::fusion::vector0<> >&, T3 = const boost::spirit::unused_type&, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’
/usr/include/boost/function/function_template.hpp:1064:16: instantiated from ‘boost::function<R(T0, T1, T2, T3)>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::spirit::qi::detail::parser_binder<boost::spirit::qi::sequence<boost::fusion::cons<boost::spirit::qi::literal_string<const char (&)[5], true>, boost::fusion::cons<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, Node(), boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> >, boost::fusion::nil> > >, mpl_::bool_<true> >, R = bool, T0 = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >&, T1 = const __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >&, T2 = boost::spirit::context<boost::fusion::cons<Node&, boost::fusion::nil>, boost::fusion::vector0<> >&, T3 = const boost::spirit::unused_type&, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’
/usr/include/boost/function/function_template.hpp:1105:5: instantiated from ‘typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, boost::function<R(T0, T1, T2, T3)>&>::type boost::function<R(T0, T1, T2, T3)>::operator=(Functor) [with Functor = boost::spirit::qi::detail::parser_binder<boost::spirit::qi::sequence<boost::fusion::cons<boost::spirit::qi::literal_string<const char (&)[5], true>, boost::fusion::cons<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, Node(), boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type> >, boost::fusion::nil> > >, mpl_::bool_<true> >, R = bool, T0 = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >&, T1 = const __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >&, T2 = boost::spirit::context<boost::fusion::cons<Node&, boost::fusion::nil>, boost::fusion::vector0<> >&, T3 = const boost::spirit::unused_type&, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, boost::function<R(T0, T1, T2, T3)>&>::type = boost::function<bool(__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >&, const __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >&, boost::spirit::context<boost::fusion::cons<Node&, boost::fusion::nil>, boost::fusion::vector0<> >&, const boost::spirit::unused_type&)>&]’
/usr/include/boost/spirit/home/qi/nonterminal/rule.hpp:214:13: instantiated from ‘boost::spirit::qi::rule<Iterator, T1, T2, T3, T4>& boost::spirit::qi::operator%=(boost::spirit::qi::rule<Iterator, T1, T2, T3, T4>&, const Expr&) [with Expr = boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const char (&)[5]>, 0l>, boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, Node(), boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type>&>, 2l>, Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, T1 = Node(), T2 = boost::spirit::unused_type, T3 = boost::spirit::unused_type, T4 = boost::spirit::unused_type, boost::spirit::qi::rule<Iterator, T1, T2, T3, T4> = boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >, Node(), boost::spirit::unused_type, boost::spirit::unused_type, boost::spirit::unused_type>]’
tt.cc:21:5: instantiated from ‘My_parser<Iterator>::My_parser() [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >]’
tt.cc:34:42: instantiated from here
/usr/include/boost/spirit/home/support/container.hpp:262:13: error: no matching function for call to ‘std::basic_string<char>::insert(std::basic_string<char>::iterator, const Node&)’
/usr/include/boost/spirit/home/support/container.hpp:262:13: note: candidates are:
/usr/include/c++/4.6/bits/basic_string.h:1174:7: note: void std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::iterator, std::basic_string<_CharT, _Traits, _Alloc>::size_type, _CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>, std::basic_string<_CharT, _Traits, _Alloc>::iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, typename _Alloc::rebind<_CharT>::other::pointer = char*, std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]
/usr/include/c++/4.6/bits/basic_string.h:1174:7: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/4.6/bits/basic_string.h:1190:9: note: template<class _InputIterator> void std::basic_string::insert(std::basic_string<_CharT, _Traits, _Alloc>::iterator, _InputIterator, _InputIterator) [with _InputIterator = _InputIterator, _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>, std::basic_string<_CharT, _Traits, _Alloc>::iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, typename _Alloc::rebind<_CharT>::other::pointer = char*]
/usr/include/c++/4.6/bits/basic_string.h:1220:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>, std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string<char>, std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]
/usr/include/c++/4.6/bits/basic_string.h:1220:7: note: no known conversion for argument 1 from ‘std::basic_string<char>::iterator {aka __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >}’ to ‘long unsigned int’
/usr/include/c++/4.6/bits/basic_string.h:1242:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, const std::basic_string<_CharT, _Traits, _Alloc>&, std::basic_string<_CharT, _Traits, _Alloc>::size_type, std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>, std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string<char>, std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]
/usr/include/c++/4.6/bits/basic_string.h:1242:7: note: candidate expects 4 arguments, 2 provided
/usr/include/c++/4.6/bits/basic_string.tcc:361:6: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, const _CharT*, std::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>, std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]
/usr/include/c++/4.6/bits/basic_string.tcc:361:6: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/4.6/bits/basic_string.h:1283:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>, std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string<char>, std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]
/usr/include/c++/4.6/bits/basic_string.h:1283:7: note: no known conversion for argument 1 from ‘std::basic_string<char>::iterator {aka __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >}’ to ‘long unsigned int’
/usr/include/c++/4.6/bits/basic_string.h:1306:7: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::size_type, std::basic_string<_CharT, _Traits, _Alloc>::size_type, _CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>, std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string<char>, std::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]
/usr/include/c++/4.6/bits/basic_string.h:1306:7: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/4.6/bits/basic_string.h:1323:7: note: std::basic_string<_CharT, _Traits, _Alloc>::iterator std::basic_string<_CharT, _Traits, _Alloc>::insert(std::basic_string<_CharT, _Traits, _Alloc>::iterator, _CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>, std::basic_string<_CharT, _Traits, _Alloc>::iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, typename _Alloc::rebind<_CharT>::other::pointer = char*]
/usr/include/c++/4.6/bits/basic_string.h:1323:7: note: no known conversion for argument 2 from ‘const Node’ to ‘char’
Компилятор/буст-версия
Это убунту 12.04
- gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
- буст 1.46.
Сказав это, мне удалось воспроизвести свой вопрос на Ubuntu 14.04 (gcc 4.8.2, boost 1.54)