Index: boost/fusion/adapted/struct/detail/define_struct_inline.hpp =================================================================== --- boost/fusion/adapted/struct/detail/define_struct_inline.hpp (revision 81078) +++ boost/fusion/adapted/struct/detail/define_struct_inline.hpp (working copy) @@ -8,6 +8,7 @@ #ifndef BOOST_FUSION_ADAPTED_STRUCT_DETAIL_DEFINE_STRUCT_INLINE_HPP #define BOOST_FUSION_ADAPTED_STRUCT_DETAIL_DEFINE_STRUCT_INLINE_HPP +#include #include #include #include @@ -25,8 +26,32 @@ #include #include #include +#include #include +// MSVC and GCC <= 4.4 have a bug that affects partial specializations of +// nested templates under some circumstances. This affects the implementation +// of BOOST_FUSION_DEFINE_STRUCT_INLINE, which uses such specializations for +// the iterator class's 'deref' and 'value_of' metafunctions. On these compilers +// an alternate implementation for these metafunctions is used that does not +// require such specializations. The alternate implementation takes longer +// to compile so its use is restricted to the offending compilers. +// For MSVC, the bug was was reported at https://connect.microsoft.com/VisualStudio/feedback/details/757891/c-compiler-error-involving-partial-specializations-of-nested-templates +// For GCC, 4.4 and earlier are no longer maintained so there is no need +// to report a bug. +#if defined(BOOST_MSVC) || (defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ <= 4))) + #define BOOST_FUSION_NEED_NESTED_TEMPLATE_PARTIAL_SPEC_WKND +#endif + +#ifdef BOOST_FUSION_NEED_NESTED_TEMPLATE_PARTIAL_SPEC_WKND +#include +#include +#include +#include +#include +#endif + + #define BOOST_FUSION_MAKE_DEFAULT_INIT_LIST_ENTRY(R, DATA, N, ATTRIBUTE) \ BOOST_PP_COMMA_IF(N) BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE)() @@ -148,6 +173,95 @@ #define BOOST_FUSION_MAKE_DATA_MEMBER(R, DATA, N, ATTRIBUTE) \ BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE) BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE); +#ifdef BOOST_FUSION_NEED_NESTED_TEMPLATE_PARTIAL_SPEC_WKND + +#define BOOST_FUSION_DEFINE_ITERATOR_VALUE_OF(NAME, ATTRIBUTE_SEQ_SIZE) \ + template \ + struct value_of : boost::fusion::result_of::at_c< \ + ref_vec_t, \ + boost_fusion_detail_Iterator::index::value \ + > \ + { \ + }; + +#define BOOST_FUSION_DEFINE_ITERATOR_DEREF(NAME, ATTRIBUTES_SEQ) \ + template \ + struct deref \ + { \ + typedef typename boost::remove_const< \ + boost_fusion_detail_Iterator \ + >::type iterator_raw_type; \ + \ + static const int index = iterator_raw_type::index::value; \ + \ + typedef typename boost::fusion::result_of::at_c< \ + ref_vec_t, \ + index \ + >::type result_raw_type; \ + \ + typedef typename boost::mpl::if_< \ + boost::is_const, \ + typename boost::add_const::type, \ + result_raw_type \ + >::type type; \ + \ + static type call(iterator_raw_type const& iter) \ + { \ + return boost::fusion::at_c(iter.ref_vec); \ + } \ + }; + +#define BOOST_FUSION_MAKE_ITERATOR_WKND_FIELD_NAME(R, DATA, N, ATTRIBUTE) \ + BOOST_PP_COMMA_IF(N) seq.BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE) + +#define BOOST_FUSION_DEFINE_ITERATOR_WKND_INIT_LIST_ENTRIES(ATTRIBUTES_SEQ) \ + , ref_vec(BOOST_PP_SEQ_FOR_EACH_I( \ + BOOST_FUSION_MAKE_ITERATOR_WKND_FIELD_NAME, \ + ~, \ + BOOST_PP_SEQ_TAIL(ATTRIBUTES_SEQ))) + +#define BOOST_FUSION_MAKE_ITERATOR_WKND_REF(Z, N, DATA) \ + BOOST_PP_COMMA_IF(N) \ + typename boost::mpl::if_< \ + boost::is_const, \ + typename boost::add_const< \ + typename boost_fusion_detail_Seq::t##N##_type \ + >::type, \ + typename boost_fusion_detail_Seq::t##N##_type \ + >::type& + +#define BOOST_FUSION_DEFINE_ITERATOR_WKND_MEMBERS(ATTRIBUTES_SEQ_SIZE) \ + typedef boost::fusion::vector< \ + BOOST_PP_REPEAT( \ + ATTRIBUTES_SEQ_SIZE, \ + BOOST_FUSION_MAKE_ITERATOR_WKND_REF, \ + ~) \ + > ref_vec_t; \ + \ + ref_vec_t ref_vec; + +#else + +#define BOOST_FUSION_DEFINE_ITERATOR_VALUE_OF(NAME, ATTRIBUTES_SEQ_SIZE) \ + template struct value_of; \ + BOOST_PP_REPEAT( \ + ATTRIBUTES_SEQ_SIZE, \ + BOOST_FUSION_MAKE_ITERATOR_VALUE_OF_SPECS, \ + NAME) + +#define BOOST_FUSION_DEFINE_ITERATOR_DEREF(NAME, ATTRIBUTES_SEQ) \ + template struct deref; \ + BOOST_PP_SEQ_FOR_EACH_I( \ + BOOST_FUSION_MAKE_ITERATOR_DEREF_SPECS, \ + NAME, \ + ATTRIBUTES_SEQ) + +#define BOOST_FUSION_DEFINE_ITERATOR_WKND_INIT_LIST_ENTRIES(ATTRIBUTES_SEQ) + +#define BOOST_FUSION_DEFINE_ITERATOR_WKND_MEMBERS(ATTRIBUTES_SEQ_SIZE) + +#endif // BOOST_FUSION_NEED_NESTED_TEMPLATE_PARTIAL_SPEC_WKND + // Note: We can't nest the iterator inside the struct because we run into // a MSVC10 bug involving partial specializations of nested templates. @@ -219,22 +333,19 @@ typedef boost_fusion_detail_Seq sequence_type; \ \ BOOST_FUSION_ITERATOR_NAME(NAME)(boost_fusion_detail_Seq& seq) \ - : seq_(seq) {} \ + : seq_(seq) \ + BOOST_FUSION_DEFINE_ITERATOR_WKND_INIT_LIST_ENTRIES( \ + (0)ATTRIBUTES_SEQ) \ + {} \ \ boost_fusion_detail_Seq& seq_; \ \ - template struct value_of; \ - BOOST_PP_REPEAT( \ - ATTRIBUTES_SEQ_SIZE, \ - BOOST_FUSION_MAKE_ITERATOR_VALUE_OF_SPECS, \ - NAME) \ + BOOST_FUSION_DEFINE_ITERATOR_WKND_MEMBERS(ATTRIBUTES_SEQ_SIZE) \ \ - template struct deref; \ - BOOST_PP_SEQ_FOR_EACH_I( \ - BOOST_FUSION_MAKE_ITERATOR_DEREF_SPECS, \ - NAME, \ - ATTRIBUTES_SEQ) \ + BOOST_FUSION_DEFINE_ITERATOR_VALUE_OF(NAME, ATTRIBUTES_SEQ_SIZE) \ \ + BOOST_FUSION_DEFINE_ITERATOR_DEREF(NAME, ATTRIBUTES_SEQ) \ + \ template \ struct next \ { \