C++ Spirit Boost real_p解析器行为异常

C++ Spirit Boost real_p解析器行为异常,c++,boost-spirit,C++,Boost Spirit,我有以下问题:我正在重用使用real_p解析器解析实数的旧代码。我想捕获每个数字,将其转换为字符串,并将其放入字符串向量中。 我使用以下代码,其中l_double是double类型的变量,convertdouble函数将double转换为字符串,result.m_literalValues是字符串的向量。 但是,代码不会将解析后的值分配给l_double rule<> alternative3 = +(real_p [assign_a(l_double)]

我有以下问题:我正在重用使用real_p解析器解析实数的旧代码。我想捕获每个数字,将其转换为字符串,并将其放入字符串向量中。 我使用以下代码,其中l_double是double类型的变量,convertdouble函数将double转换为字符串,result.m_literalValues是字符串的向量。 但是,代码不会将解析后的值分配给l_double

rule<> alternative3 =   +(real_p        [assign_a(l_double)]
                                        [push_back_a(result.m_LiteralValues, convertdouble(l_double))]
                                        >>  str_p(",")
                            )
rule alternative3=+(实数p[assign_a(l_double)]
[push_back_a(result.m_LiteralValues,convertdouble(l_double))]
>>str_p(“,”)
)
有人知道我做错了什么吗


注意:我不会重新设计旧代码,这比给出的示例要复杂得多。我只想提取所有解析值的字符串,并将它们放入字符串向量中。

问题似乎出在
push_back_a(result.m_LiteralValues,convertdouble(l_double))
,特别是在
convertdouble(l_double)
中。它的第二个参数是要存储在“policycholder actor”中的引用,因此在那里使用函数调用会导致错误。如果您不需要存储
l\u double
,而只是将其用作临时存储,那么实现所需功能的一种方法是创建自己的phoenix函数,其行为类似于所解释的
push\u back\u a
(完整示例)。 您可以这样定义phoenix函数:

struct push_back_impl
{
    template <typename Container, typename Item>
    struct result
    {
        typedef void type;
    };

    template <typename Container, typename Item>
    void operator()(Container& c, Item const& item) const
    {
        c.push_back(convertdouble(item));
    }
};

function<push_back_impl> const push_back = push_back_impl();
rule<> alternative3 =   +( real_p[push_back(var(result.m_LiteralValues),arg1)] >>  str_p(",") );
struct push\u back\u impl
{
模板
结构结果
{
typedef-void型;
};
模板
void运算符()(容器和c、项目常量和项目)常量
{
c、 推回(项目);
}
};
函数const push_back=push_back_impl();
然后像这样定义规则:

struct push_back_impl
{
    template <typename Container, typename Item>
    struct result
    {
        typedef void type;
    };

    template <typename Container, typename Item>
    void operator()(Container& c, Item const& item) const
    {
        c.push_back(convertdouble(item));
    }
};

function<push_back_impl> const push_back = push_back_impl();
rule<> alternative3 =   +( real_p[push_back(var(result.m_LiteralValues),arg1)] >>  str_p(",") );
rule alternative3=+(real_p[push_back(var(result.m_LiteralValues),arg1)]>>str_p(“,”);
完整的可编译代码(如果不能/不想使用c++11,请更改for循环以显示结果):

#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间boost::spirit::classic;
使用名称空间phoenix;
std::string convertdouble(const double&d)
{   
std::stringstream-ss;
ss str_p(“,”);
if(解析(test,alternative3,space_p).full)
{

std::cout问题似乎出在
push_back_a(result.m_LiteralValues,convertdoull(l_double))
中,特别是在
convertdoull(l_double)
中。其第二个参数是要存储在“保单持有人参与者”中的引用因此,在那里使用函数调用会导致错误。如果您不需要存储
l\u double
,而只是将其用作临时存储,则实现所需功能的一种方法是创建自己的phoenix函数,其行为类似于所解释的
push\u a
(完整示例)。 您可以这样定义phoenix函数:

struct push_back_impl
{
    template <typename Container, typename Item>
    struct result
    {
        typedef void type;
    };

    template <typename Container, typename Item>
    void operator()(Container& c, Item const& item) const
    {
        c.push_back(convertdouble(item));
    }
};

function<push_back_impl> const push_back = push_back_impl();
rule<> alternative3 =   +( real_p[push_back(var(result.m_LiteralValues),arg1)] >>  str_p(",") );
struct push\u back\u impl
{
模板
结构结果
{
typedef-void型;
};
模板
void运算符()(容器和c、项目常量和项目)常量
{
c、 推回(项目);
}
};
函数const push_back=push_back_impl();
然后像这样定义规则:

struct push_back_impl
{
    template <typename Container, typename Item>
    struct result
    {
        typedef void type;
    };

    template <typename Container, typename Item>
    void operator()(Container& c, Item const& item) const
    {
        c.push_back(convertdouble(item));
    }
};

function<push_back_impl> const push_back = push_back_impl();
rule<> alternative3 =   +( real_p[push_back(var(result.m_LiteralValues),arg1)] >>  str_p(",") );
rule alternative3=+(real_p[push_back(var(result.m_LiteralValues),arg1)]>>str_p(“,”);
完整的可编译代码(如果不能/不想使用c++11,请更改for循环以显示结果):

#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间boost::spirit::classic;
使用名称空间phoenix;
std::string convertdouble(const double&d)
{   
std::stringstream-ss;
ss str_p(“,”);
if(解析(test,alternative3,space_p).full)
{
标准::cout