我一直在尝试使用一些boost融合的东西来编写一个常规的c struct to file.XML文件似乎是捕获数据并使其与其他工具兼容或手动编辑的好方法.看起来我几乎拥有它,但似乎缺少一些基本的东西.我使用的东西非常类似于boost :: fusion快速入门页面上的内容:http://www.boost.org/doc/libs/1_54_0/libs/fusion/doc/html/fusion/quick_start.html.作为旁注,我已经仔细查看了这里和boost的文档,但似乎没有人访问字段名称.
struct print_xml
{
template <typename T>
void operator()(T const& x) const
{
std::cout
<< '<' << x.first << '>'
<< x
<< "</" << x.first << '>'
;
}
};
Run Code Online (Sandbox Code Playgroud)
我想用它如下:
BOOST_FUSION_ADAPT_STRUCT(
myStructType,
(double, val1)
(double, val2)
(char, letter)
(int, number)
)
myStructType saveMe = { 3.4, 5.6, 'g', 9};
for_each(saveMe, print_xml());
Run Code Online (Sandbox Code Playgroud)
其他时候我将结构定义如下,但仍然没有运气:
namespace fields{
struct val1;
struct val2;
struct letter;
struct number;
}
typedef fusion::map<
fusion::pair<fields::val1, double>,
fusion::pair<fields::val2, double>, …Run Code Online (Sandbox Code Playgroud)