我正在使用QI和Phoenix,我想编写一个返回4个bool的小语法,它将用作语义动作中函数调用的参数.
我有几个需要这些东西的函数,到目前为止我已经使用过这种方法:
( qi::_bool >> qi::_bool >> qi::_bool >> qi::_bool)
[px::bind(&Bool4Function, spirit::_val, spirit::_1, spirit::_2, spirit::_3, spirit::_4)]
Run Code Online (Sandbox Code Playgroud)
虽然它可以自己使用它,但是在整个地方使用它只是简单的丑陋和混乱,即使使用'命名空间部分.
这就是为什么我想把这个表达式提取成一个独立的语法.
所以我尝试了这个(信用证转到ildjarn测试床):
///// grammar implementation /////
#include <boost/fusion/include/vector10.hpp>
#include <boost/spirit/include/qi_bool.hpp>
#include <boost/spirit/include/qi_char_.hpp>
#include <boost/spirit/include/qi_grammar.hpp>
#include <boost/spirit/include/qi_operator.hpp>
#include <boost/spirit/include/qi_rule.hpp>
#include <boost/spirit/include/qi_string.hpp>
struct FourBools : boost::spirit::qi::grammar<
char const*,
boost::fusion::vector4<bool, bool, bool, bool>()
>
{
typedef boost::fusion::vector4<bool, bool, bool, bool> attribute_type;
FourBools() : base_type(start_)
{
using boost::spirit::bool_;
start_
= "4bools:"
>> bool_ >> ','
>> bool_ >> ','
>> bool_ >> ','
>> bool_ >> ';' …Run Code Online (Sandbox Code Playgroud) 我在c ++中使用一个使用特殊dprintf函数打印信息的应用程序,这是一个例子:
dprintf(verbose, "The value is: %d", i);
Run Code Online (Sandbox Code Playgroud)
我正在做的是当我为测试目的定义详细信息然后我打印信息时,当我正常执行时,我没有定义它,我没有在屏幕上看到无用的信息.我的问题是我该如何实现这一功能或实现相同的想法?