更新BOOST后fusion宏中的编译器错误 我试图恢复一些由别人编写的C++代码,在更新Boost到最新版本后,我很难让它编译。下面是一段经过重构和简化的自给自足的代码,可以用BOOST 1.42编译,但不能用更高版本编译。简化的代码没有意义,但它保留了原始代码在这个BOOST更改方面的行为,即使用v编译。但对于更高版本,它会生成一个编译器错误,如下所示 #include <boost/preprocessor.hpp> #include <boost/fusion/adapted/struct/adapt_struct.hpp> #include <boost/fusion/functional/invocation/invoke.hpp> #include <boost/shared_ptr.hpp> #define DEFINE_STRUCT(name, fields) \ DEFINE_STRUCT_I(name, \ BOOST_PP_CAT(DEFINE_STRUCT_X fields, 0)) #define DEFINE_STRUCT_X(x, y) ((x, y)) DEFINE_STRUCT_Y #define DEFINE_STRUCT_Y(x, y) ((x, y)) DEFINE_STRUCT_X #define DEFINE_STRUCT_X0 #define DEFINE_STRUCT_Y0 #define DEFINE_STRUCT_I(name, fields) \ class name \ { \ BOOST_PP_SEQ_FOR_EACH_I \ (DEFINE_STRUCT_FIELD, _, fields) \ public: \ name() {} \ public: \ template <class T, int> friend struct boost::fusion::extension::access::struct_member;\ }; \ BOOST_FUSION_ADAPT_STRUCT_I_PTR(name, fields)\ struct name##_table : public table_container<name>\ {\ }; #define DEFINE_STRUCT_FIELD(r, _, i, xy) \ BOOST_PP_TUPLE_ELEM(2, 0, xy) \ *BOOST_PP_TUPLE_ELEM(2, 1, xy); #define BOOST_FUSION_ADAPT_STRUCT_I_PTR(name, seq) \ namespace boost { namespace fusion { namespace traits \ { \ template <> \ struct tag_of<name> \ { \ typedef struct_tag type; \ }; \ }}} \ namespace boost { namespace fusion { namespace extension \ { \ template <> \ struct struct_size<name> : mpl::int_<BOOST_PP_SEQ_SIZE(seq)> {}; \ BOOST_PP_SEQ_FOR_EACH_I(BOOST_FUSION_ADAPT_STRUCT_C_PTR, name, seq) \ }}} \ #define BOOST_FUSION_ADAPT_STRUCT_C_PTR(r, name, i, xy) \ template <> \ struct access::struct_member<name, i> \ { \ typedef BOOST_PP_TUPLE_ELEM(2, 0, xy)* type; \ static type& call(name& struct_) \ { \ return struct_.BOOST_PP_TUPLE_ELEM(2, 1, xy); \ }; \ }; \ template<class T> struct table_container { T val; }; DEFINE_STRUCT(new_buildin, (int, col1) (char, col2)) int main() { new_buildin_table b; boost::fusion::at<boost::mpl::int_<1>>(b.val); return 0; }

更新BOOST后fusion宏中的编译器错误 我试图恢复一些由别人编写的C++代码,在更新Boost到最新版本后,我很难让它编译。下面是一段经过重构和简化的自给自足的代码,可以用BOOST 1.42编译,但不能用更高版本编译。简化的代码没有意义,但它保留了原始代码在这个BOOST更改方面的行为,即使用v编译。但对于更高版本,它会生成一个编译器错误,如下所示 #include <boost/preprocessor.hpp> #include <boost/fusion/adapted/struct/adapt_struct.hpp> #include <boost/fusion/functional/invocation/invoke.hpp> #include <boost/shared_ptr.hpp> #define DEFINE_STRUCT(name, fields) \ DEFINE_STRUCT_I(name, \ BOOST_PP_CAT(DEFINE_STRUCT_X fields, 0)) #define DEFINE_STRUCT_X(x, y) ((x, y)) DEFINE_STRUCT_Y #define DEFINE_STRUCT_Y(x, y) ((x, y)) DEFINE_STRUCT_X #define DEFINE_STRUCT_X0 #define DEFINE_STRUCT_Y0 #define DEFINE_STRUCT_I(name, fields) \ class name \ { \ BOOST_PP_SEQ_FOR_EACH_I \ (DEFINE_STRUCT_FIELD, _, fields) \ public: \ name() {} \ public: \ template <class T, int> friend struct boost::fusion::extension::access::struct_member;\ }; \ BOOST_FUSION_ADAPT_STRUCT_I_PTR(name, fields)\ struct name##_table : public table_container<name>\ {\ }; #define DEFINE_STRUCT_FIELD(r, _, i, xy) \ BOOST_PP_TUPLE_ELEM(2, 0, xy) \ *BOOST_PP_TUPLE_ELEM(2, 1, xy); #define BOOST_FUSION_ADAPT_STRUCT_I_PTR(name, seq) \ namespace boost { namespace fusion { namespace traits \ { \ template <> \ struct tag_of<name> \ { \ typedef struct_tag type; \ }; \ }}} \ namespace boost { namespace fusion { namespace extension \ { \ template <> \ struct struct_size<name> : mpl::int_<BOOST_PP_SEQ_SIZE(seq)> {}; \ BOOST_PP_SEQ_FOR_EACH_I(BOOST_FUSION_ADAPT_STRUCT_C_PTR, name, seq) \ }}} \ #define BOOST_FUSION_ADAPT_STRUCT_C_PTR(r, name, i, xy) \ template <> \ struct access::struct_member<name, i> \ { \ typedef BOOST_PP_TUPLE_ELEM(2, 0, xy)* type; \ static type& call(name& struct_) \ { \ return struct_.BOOST_PP_TUPLE_ELEM(2, 1, xy); \ }; \ }; \ template<class T> struct table_container { T val; }; DEFINE_STRUCT(new_buildin, (int, col1) (char, col2)) int main() { new_buildin_table b; boost::fusion::at<boost::mpl::int_<1>>(b.val); return 0; },c++,boost,C++,Boost,你知道是什么原因造成的吗?我无法访问构建了boost库的机器,但我注意到这段代码使用的是可变宏,而您使用的是msvc进行编译。当使用不同的编译器/不同版本的编译器时,我在boost中遇到了变量宏的问题。查看此链接:注意最后一个示例。它可能适用于您。好的,这里没有涉及变量宏,或者您是指像DEFINE_STRUCT_X/DEFINE_STRUCT_Y这样的构造吗?它们的工作方式有点像可变宏,实际上不使用可变宏语法。无论如何,如果用户代码中的可变宏是一个问题,那么它不会用任何BOOST版本编译,但它会

你知道是什么原因造成的吗?

我无法访问构建了boost库的机器,但我注意到这段代码使用的是可变宏,而您使用的是msvc进行编译。当使用不同的编译器/不同版本的编译器时,我在boost中遇到了变量宏的问题。查看此链接:注意最后一个示例。它可能适用于您。好的,这里没有涉及变量宏,或者您是指像DEFINE_STRUCT_X/DEFINE_STRUCT_Y这样的构造吗?它们的工作方式有点像可变宏,实际上不使用可变宏语法。无论如何,如果用户代码中的可变宏是一个问题,那么它不会用任何BOOST版本编译,但它会用BOOST编译并工作到v。1.42.
 1>c:\local\boost_1_56_0\boost\fusion\adapted\struct\detail\at_impl.hpp(29): error C2903: 'apply' : symbol is neither a class template nor a function template
             c:\local\boost_1_56_0\boost\fusion\sequence\intrinsic\at.hpp(65) : see reference to class template instantiation 'boost::fusion::extension::at_impl<boost::fusion::struct_tag>::apply<Seq,N>' being compiled
             with
             [
                 Seq=const new_buildin,
                 N=boost::mpl::int_<1>
             ]
             c:\smartdb_pqtypes_lib\smartdb_pqtypes_debug\smartdb_pqtypes_debug.cpp(78) : see reference to class template instantiation 'boost::fusion::result_of::at<Sequence,N>' being compiled
             with
             [
                 Sequence=const new_buildin,
                 N=boost::mpl::int_<1>
             ]