由于BOOST_FUSION_ADAPT_TPL_STRUCT,我正在尝试迭代 C++ 模板结构。我的结构包含固定大小的多维数组,其大小是模板参数。如果我们考虑修改 Boost 的示例以适应我的问题:
#include <iostream>
#include <string>
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
// Example:
// http://www.boost.org/doc/libs/1_53_0/libs/fusion/doc/html/fusion/adapted/adapt_tpl_struct.html
namespace demo
{
template<typename T, unsigned int SIZE1, unsigned int SIZE2, typename Name, typename Age>
struct employee
{
Name name;
Age age;
T ar[SIZE1][SIZE2];
};
}
// Any instantiated demo::employee is now a Fusion sequence
BOOST_FUSION_ADAPT_TPL_STRUCT(
(T)(SIZE1)(SIZE2)(Name)(Age),
(demo::employee) (T)(SIZE1)(SIZE2)(Name)(Age),
(Name, name)
(Age, age)
(T, ar[SIZE1][SIZE2]))
int main()
{
demo::employee<float, 2, 2, std::string, int> e;
e.name = "Bob";
e.age = 25;
e.ar[0][0] = e.ar[1][0] = 0.1;
e.ar[0][1] = e.ar[1][1] = 0.2;
}
编译失败。此外,如果我们只添加一个整数模板参数而不使用它作为数组大小,它也会失败。
这甚至可能BOOST_FUSION_ADAPT_TPL_STRUCT
吗?如果没有,我该怎么做?