- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个简单的结构,适用于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’
这是 ubuntu 12.04
话虽如此,我设法在 ubuntu 14.04(gcc 4.8.2,boost 1.54)上重现了我的问题
最佳答案
这让我想起了这个臭名昭著的限制:
但是,我无法让它点击,通常的解决方法似乎并不适用。您可以在 [spirit-general]
邮件列表中报告它。
与此同时,这里有一个 phoenix 解决方法:
node_line = " * " >> node [qi::_val=qi::_1];
关于c++ - Boost::spirit 属性类型不崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26507932/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!