C++ 提升精神业力多重选择
我看到了一个错误,但我没有看到解决的方法。首先,有关守则:C++ 提升精神业力多重选择,c++,boost,boost-spirit,boost-spirit-karma,boost-optional,C++,Boost,Boost Spirit,Boost Spirit Karma,Boost Optional,我看到了一个错误,但我没有看到解决的方法。首先,有关守则: namespace C { struct RangeEntry { size_t byte; boost::optional<size_t> bit; }; struct Range { RangeEntry firstPart; boost::optional<RangeEntry> secondPart;
namespace C {
struct RangeEntry {
size_t byte;
boost::optional<size_t> bit;
};
struct Range {
RangeEntry firstPart;
boost::optional<RangeEntry> secondPart;
boost::optional<size_t> shift;
};
}
BOOST_FUSION_ADAPT_STRUCT(
C::RangeEntry,
(size_t, byte)
(boost::optional<size_t>, bit)
)
BOOST_FUSION_ADAPT_STRUCT(
C::Range,
(C::RangeEntry , firstPart)
(boost::optional<C::RangeEntry> , secondPart)
(boost::optional<size_t> , shift)
)
... Declare the rules ...
karma::rule<Iterator, C::Range()> range;
karma::rule<Iterator, C::RangeEntry()> range_part;
... Define rules ...
range_part %= no_delimit[ulong_ << -(lit(":") << ulong_)];
range %= no_delimit[range_part << -(lit("-") << range_part)] << -(lit("<<") << ulong_);
我猜它试图将一个RangeEntry与ulong_u规则匹配,但我不明白为什么?我遗漏了什么?无定界指令正在重组暴露的融合序列。请注意,以下内容不会编译:
range %= range_part << -(lit("-") << range_part) << -(lit("<<") << ulong_);
range%=range\u部分仅为a。问题中缺少RangeEntry使其几乎无法回答。下一次,请确保包含一个@llonesmiz您可能有兴趣知道现在有,它允许您通过c++filt
管道输出,以便更轻松地发出命令:@sehe这真的很有趣,谢谢。@sehe抱歉,我忘了包括它(没有理由我不能)。不过,你的“幻想”例子非常贴切。(我自己的无符号长结构是可选的,而不是成对的)。
range %= range_part << -(lit("-") << range_part) << -(lit("<<") << ulong_);
range %= no_delimit[range_part << -(lit("-") << range_part) << -(lit("<<") << ulong_)];
#include <boost/fusion/adapted.hpp>
#include <boost/spirit/include/karma.hpp>
namespace karma = boost::spirit::karma;
namespace C {
typedef std::pair<unsigned long, boost::optional<unsigned long> > RangeEntry;
struct Range {
RangeEntry firstPart;
boost::optional<RangeEntry> secondPart;
boost::optional<size_t> shift;
};
}
BOOST_FUSION_ADAPT_STRUCT(
C::Range,
(C::RangeEntry , firstPart)
(boost::optional<C::RangeEntry> , secondPart)
(boost::optional<size_t> , shift)
);
//... Declare the rules ...
int main()
{
typedef char* Iterator;
karma::rule<Iterator, C::Range()> range;
karma::rule<Iterator, C::RangeEntry()> range_part;
//... Define rules ...
using namespace karma;
range_part %= no_delimit[ulong_ << -(lit(":") << ulong_)];
range %= no_delimit[range_part << -(lit("-") << range_part) << -(lit("<<") << ulong_)];
}