例如,使用库Boost::hana中的宏BOOST_HANA_DEFINE_STRUCT定义具有40个以上字段的结构,
#include <boost/hana/define_struct.hpp>
namespace hana = boost::hana;
// a simple struct having 41 fields
struct Foo {
BOOST_HANA_DEFINE_STRUCT(Foo,
(int, bar_0),
(int, bar_1),
...,
(int, bar_40)
);
};
将引发编译错误
pasting "BOOST_HANA_DEFINE_STRUCT_IMPL_" and "(" does not give a valid preprocessing token.
深入研究Hana的源代码,可以发现在
boost/hana/detail/struct_macros.hpp
文件中,所有宏均使用样板中的硬编码工具定义,
...
#define BOOST_HANA_DEFINE_STRUCT_IMPL_40(TYPE , m1, m2, ..., m39) \
#define BOOST_HANA_DEFINE_STRUCT_IMPL_41(TYPE , m1, m2, m3, ..., m40) \
所以我的问题是
非常感谢!
最佳答案
有boost / hana / detail / struct_macros.hpp.erb可用于使用以下命令重新生成boost / hana / detail / struct_macros.hpp
MAX_NUMBER_OF_MEMBERS=55 erb struct_macros.hpp.erb > struct_macros.hpp
关于c++ - 在Boost::Hana中使用BOOST_HANA_DEFINE_STRUCT定义具有40个以上字段的结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59405856/