|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r81165 - in trunk: boost/fusion/adapted/struct/detail libs/fusion/test/sequence
From: joel_at_[hidden]
Date: 2012-11-03 20:18:42
Author: djowel
Date: 2012-11-03 20:18:41 EDT (Sat, 03 Nov 2012)
New Revision: 81165
URL: http://svn.boost.org/trac/boost/changeset/81165
Log:
Fixes for Ticket #7569 ( Compile Error using BOOST_FUSION_DEFINE_STRUCT_INLINE with VC10 and GCC <4.5 )
Text files modified:
trunk/boost/fusion/adapted/struct/detail/define_struct_inline.hpp | 133 ++++++++++++++++++++++++++++++++++++---
trunk/libs/fusion/test/sequence/define_struct_inline.cpp | 41 ++++++++---
trunk/libs/fusion/test/sequence/define_tpl_struct_inline.cpp | 44 +++++++++----
3 files changed, 181 insertions(+), 37 deletions(-)
Modified: trunk/boost/fusion/adapted/struct/detail/define_struct_inline.hpp
==============================================================================
--- trunk/boost/fusion/adapted/struct/detail/define_struct_inline.hpp (original)
+++ trunk/boost/fusion/adapted/struct/detail/define_struct_inline.hpp 2012-11-03 20:18:41 EDT (Sat, 03 Nov 2012)
@@ -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 <boost/config.hpp>
#include <boost/fusion/support/category_of.hpp>
#include <boost/fusion/sequence/sequence_facade.hpp>
#include <boost/fusion/iterator/iterator_facade.hpp>
@@ -25,8 +26,32 @@
#include <boost/preprocessor/seq/for_each_i.hpp>
#include <boost/preprocessor/seq/size.hpp>
#include <boost/preprocessor/seq/enum.hpp>
+#include <boost/preprocessor/seq/seq.hpp>
#include <boost/preprocessor/tuple/elem.hpp>
+// 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 <boost/type_traits/add_const.hpp>
+#include <boost/type_traits/remove_const.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/fusion/sequence/intrinsic/at_c.hpp>
+#include <boost/fusion/container/vector.hpp>
+#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 <typename boost_fusion_detail_Iterator> \
+ 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 <typename boost_fusion_detail_Iterator> \
+ 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 iterator_raw_type::sequence_type>, \
+ typename boost::add_const<result_raw_type>::type, \
+ result_raw_type \
+ >::type type; \
+ \
+ static type call(iterator_raw_type const& iter) \
+ { \
+ return boost::fusion::at_c<index>(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<boost_fusion_detail_Seq>, \
+ 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 <typename boost_fusion_detail_T> 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 <typename boost_fusion_detail_T> 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,21 +333,18 @@
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 <typename boost_fusion_detail_T> 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 <typename boost_fusion_detail_T> 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 <typename boost_fusion_detail_It> \
struct next \
Modified: trunk/libs/fusion/test/sequence/define_struct_inline.cpp
==============================================================================
--- trunk/libs/fusion/test/sequence/define_struct_inline.cpp (original)
+++ trunk/libs/fusion/test/sequence/define_struct_inline.cpp 2012-11-03 20:18:41 EDT (Sat, 03 Nov 2012)
@@ -26,6 +26,16 @@
)
};
+template <typename = int>
+struct tpl_cls
+{
+ BOOST_FUSION_DEFINE_STRUCT_INLINE(
+ point,
+ (int, x)
+ (int, y)
+ )
+};
+
namespace ns
{
BOOST_FUSION_DEFINE_STRUCT_INLINE(s, (int, m))
@@ -33,8 +43,8 @@
BOOST_FUSION_DEFINE_STRUCT_INLINE(empty_struct, )
}
-int
-main()
+template <typename Point>
+void run_test()
{
using namespace boost::fusion;
@@ -48,8 +58,8 @@
}
{
- BOOST_MPL_ASSERT_NOT((traits::is_view<cls::point>));
- cls::point p(123, 456);
+ BOOST_MPL_ASSERT_NOT((traits::is_view<Point>));
+ Point p(123, 456);
std::cout << at_c<0>(p) << std::endl;
std::cout << at_c<1>(p) << std::endl;
@@ -60,8 +70,8 @@
at_c<1>(p) = 9;
BOOST_TEST(p == make_vector(6, 9));
- BOOST_STATIC_ASSERT(boost::fusion::result_of::size<cls::point>::value == 2);
- BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<cls::point>::value);
+ BOOST_STATIC_ASSERT(boost::fusion::result_of::size<Point>::value == 2);
+ BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<Point>::value);
BOOST_TEST(front(p) == 6);
BOOST_TEST(back(p) == 9);
@@ -69,7 +79,7 @@
{
vector<int, float> v1(4, 2);
- cls::point v2(5, 3);
+ Point v2(5, 3);
vector<long, double> v3(5, 4);
BOOST_TEST(v1 < v2);
BOOST_TEST(v1 <= v2);
@@ -82,15 +92,15 @@
}
{
- // conversion from cls::point to vector
- cls::point p(5, 3);
+ // conversion from Point to vector
+ Point p(5, 3);
vector<int, long> v(p);
v = p;
}
{
- // conversion from cls::point to list
- cls::point p(5, 3);
+ // conversion from Point to list
+ Point p(5, 3);
list<int, long> l(p);
l = p;
}
@@ -105,13 +115,20 @@
}
{
- cls::point p = make_list(5,3);
+ Point p = make_list(5,3);
BOOST_TEST(p == make_vector(5,3));
p = make_list(3,5);
BOOST_TEST(p == make_vector(3,5));
}
+}
+int
+main()
+{
+ run_test<cls::point>(); // test with non-template enclosing class
+ run_test<tpl_cls<>::point>(); // test with template enclosing class
return boost::report_errors();
+
}
Modified: trunk/libs/fusion/test/sequence/define_tpl_struct_inline.cpp
==============================================================================
--- trunk/libs/fusion/test/sequence/define_tpl_struct_inline.cpp (original)
+++ trunk/libs/fusion/test/sequence/define_tpl_struct_inline.cpp 2012-11-03 20:18:41 EDT (Sat, 03 Nov 2012)
@@ -27,6 +27,17 @@
)
};
+template <typename = int>
+struct tpl_cls
+{
+ BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE(
+ (X)(Y),
+ point,
+ (X, x)
+ (Y, y)
+ )
+};
+
namespace ns
{
BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE((M), s, (M, m))
@@ -34,13 +45,11 @@
BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE((M), empty_struct, )
}
-int
-main()
+template <typename Point>
+void run_test()
{
using namespace boost::fusion;
- typedef cls::point<int, int> point;
-
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
@@ -51,8 +60,8 @@
}
{
- BOOST_MPL_ASSERT_NOT((traits::is_view<point>));
- point p(123, 456);
+ BOOST_MPL_ASSERT_NOT((traits::is_view<Point>));
+ Point p(123, 456);
std::cout << at_c<0>(p) << std::endl;
std::cout << at_c<1>(p) << std::endl;
@@ -63,8 +72,8 @@
at_c<1>(p) = 9;
BOOST_TEST(p == make_vector(6, 9));
- BOOST_STATIC_ASSERT(boost::fusion::result_of::size<point>::value == 2);
- BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<point>::value);
+ BOOST_STATIC_ASSERT(boost::fusion::result_of::size<Point>::value == 2);
+ BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<Point>::value);
BOOST_TEST(front(p) == 6);
BOOST_TEST(back(p) == 9);
@@ -72,7 +81,7 @@
{
vector<int, float> v1(4, 2);
- point v2(5, 3);
+ Point v2(5, 3);
vector<long, double> v3(5, 4);
BOOST_TEST(v1 < v2);
BOOST_TEST(v1 <= v2);
@@ -85,15 +94,15 @@
}
{
- // conversion from point to vector
- point p(5, 3);
+ // conversion from Point to vector
+ Point p(5, 3);
vector<int, long> v(p);
v = p;
}
{
- // conversion from point to list
- point p(5, 3);
+ // conversion from Point to list
+ Point p(5, 3);
list<int, long> l(p);
l = p;
}
@@ -109,13 +118,20 @@
{
- point p = make_list(5,3);
+ Point p = make_list(5,3);
BOOST_TEST(p == make_vector(5,3));
p = make_list(3,5);
BOOST_TEST(p == make_vector(3,5));
}
+}
+int
+main()
+{
+ run_test<cls::point<int, int> >(); // test non-template enclosing class
+ run_test<tpl_cls<>::point<int, int> >(); // test template enclosing class
+
return boost::report_errors();
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk