当BOOST_FUSION_ADAPT_STRUCT的参数数量为2时,Boost Fusion编译失败

时间:2012-04-01 21:53:49

标签: c++ boost

为什么用g ++ -c filename.cpp编译失败:

#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/io.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/variant/variant.hpp>
#include <iostream>

namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
namespace phoenix = boost::phoenix;
namespace lambda = boost::lambda;

using namespace std;


struct Intensity
{
    int intensity_;
};

BOOST_FUSION_ADAPT_STRUCT(
    Intensity,
    (int, intensity_)
)

template <typename Iterator>
struct InternalParser : qi::grammar<Iterator, Intensity(), ascii::space_type>
{
    InternalParser() : InternalParser::base_type(intensity)
    {
        intensity %= qi::int_;
    }
    qi::rule<Iterator, Intensity(), ascii::space_type> intensity;
};

typedef InternalParser<string::const_iterator> TheParser;

TheParser parser;

但是,如果我在结构强度中添加一个新字段,它可以工作:

#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/io.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/variant/variant.hpp>
#include <iostream>

namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
namespace phoenix = boost::phoenix;
namespace lambda = boost::lambda;

using namespace std;


struct Intensity
{
    int dummy_;
    int intensity_;
};

BOOST_FUSION_ADAPT_STRUCT(
    Intensity,
    (int, dummy_)
    (int, intensity_)
)

template <typename Iterator>
struct InternalParser : qi::grammar<Iterator, Intensity(), ascii::space_type>
{
    InternalParser() : InternalParser::base_type(intensity)
    {
        intensity %= qi::int_ >> qi::int_;
    }
    qi::rule<Iterator, Intensity(), ascii::space_type> intensity;
};

typedef InternalParser<string::const_iterator> TheParser;

TheParser parser;

g ++版本: gcc版本4.4.6 20110731(Red Hat 4.4.6-3)(GCC)

Boost版本:1.41.0

1 个答案:

答案 0 :(得分:0)

这是boost 1.41.0中的一个错误。我用1.49.0编译了第一个例子并且它有效。