我想解析一個文件,並將數據複製到一個類對象內的向量。我採取了員工示例,並將其修改爲我正在嘗試執行的操作。正在解析的文件看起來像這樣(但多行)...精神x3如何添加一個向量的AST
1 0.2 0.3 0.4
我添加了一個向量爲結構的員工和我在phrase_parse線越來越斷言失敗。
static assertion failed: Attribute does not have the expected size.
static_assert(
^
我有點認爲預期的大小與矢量有關。關於我哪裏出錯的想法?
namespace client {
namespace ast {
struct employee
{
int id;
std::vector<double> coords;
};
using boost::fusion::operator<<;
}}
BOOST_FUSION_ADAPT_STRUCT(
client::ast::employee,
(int, id)
(std::vector<double>, coords)
)
namespace client
{
namespace parser
{
namespace x3 = boost::spirit::x3;
namespace ascii = boost::spirit::x3::ascii;
using x3::int_;
using x3::double_;
x3::rule<class employee, ast::employee> const employee = "employee";
auto const employee_def =
int_ >> double_ >> double_ >> double_;
BOOST_SPIRIT_DEFINE(employee)
}
}
int main()
{
using boost::spirit::x3::ascii::space;
using client::parser::employee;
string fil("test-file.in");
mapped_file_source map(fil);
istringstream iss(map.data());
map.close();
client::ast::employee emp;
boost::spirit::istream_iterator iter(iss >> noskipws), eof;
phrase_parse(iter, eof, employee, space, emp);
// failure on above line
}
「使用」'運營商<<'確實什麼也沒有。爲什麼在地球上將文件映射覆制到字符串流?爲什麼你的代碼示例被破壞而不是自包含? – sehe