From 3203e349ade4bebf458eff6cde713e61bbd9debd Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Sat, 7 Apr 2012 18:45:13 +0000 Subject: [PATCH] Wrapped a metafunction call into a local struct to try to workaround a problem with add_template on the intel compiler. [SVN r77820] --- .../aux_/macro/code_/functor.hpp | 18 ++++--- .../aux_/macro/code_/result.hpp | 51 ++++++++++--------- test/return_derivative.cpp | 1 + test/return_derivative_seq.cpp | 1 + 4 files changed, 38 insertions(+), 33 deletions(-) diff --git a/include/boost/local_function/aux_/macro/code_/functor.hpp b/include/boost/local_function/aux_/macro/code_/functor.hpp index c9a0bdc..fe4e10f 100644 --- a/include/boost/local_function/aux_/macro/code_/functor.hpp +++ b/include/boost/local_function/aux_/macro/code_/functor.hpp @@ -325,8 +325,8 @@ BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_MAYBECONST_BIND_MEMBER_INIT_ENUM_( \ // Expand to the function type `R (A1, ...)`. #define BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_F_( \ - id, decl_traits, has_type, function_type) \ - BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id) \ + id, typename01, decl_traits, has_type, function_type) \ + BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id, typename01) \ BOOST_PP_EXPR_IIF(has_type, (function_type) ) \ ( \ BOOST_PP_LIST_FOR_EACH_I( \ @@ -385,7 +385,8 @@ BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_MAYBECONST_BIND_MEMBER_INIT_ENUM_( \ #define BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_CALL_(z, defaults_n, \ id, typename01, decl_traits, params, \ const_binds, has_const_bind_this, binds, has_bind_this) \ - inline BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id) operator()( \ + inline BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id, typename01) \ + operator()( \ BOOST_PP_LIST_FOR_EACH_I( \ BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_PARAM_ARG_DECL_ENUM_, \ typename01, params) \ @@ -461,7 +462,7 @@ BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_STATIC_CALL_COMMA_BIND_PARAM_DECLS_( \ #define BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_STATIC_CALL_(z, defaults_n, \ id, typename01, decl_traits, params, \ const_binds, has_const_bind_this, binds, has_bind_this) \ - inline static BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id) \ + inline static BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id, typename01) \ BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_STATIC_CALL_FUNC_(z, defaults_n, ~)( \ void* object \ BOOST_PP_IIF(BOOST_LOCAL_FUNCTION_CONFIG_LOCALS_AS_TPARAMS, \ @@ -691,8 +692,8 @@ BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_STATIC_CALL_COMMA_BIND_PARAM_DECLS_( \ { \ /* function type */ \ typedef \ - BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_F_(id, decl_traits, \ - 1 /* has type */, \ + BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_F_(id, typename01, \ + decl_traits, 1 /* has type */, \ BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_F_TYPE_) \ ; \ /* functor type -- this type cannot have ID postfix because it is */ \ @@ -721,7 +722,8 @@ BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_STATIC_CALL_COMMA_BIND_PARAM_DECLS_( \ /* (traits must be defined in both this and the global functor) */ \ enum { arity = ::boost::function_traits< /* can't use static data */ \ BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_F_TYPE_ >::arity }; \ - typedef BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id) result_type; \ + typedef BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id, typename01) \ + result_type; \ BOOST_PP_LIST_FOR_EACH_I( \ BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_ARG_TYPEDEF_, \ typename01, params) \ @@ -791,7 +793,7 @@ BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_STATIC_CALL_COMMA_BIND_PARAM_DECLS_( \ /* body function (unfortunately, cannot be static to allow access */ \ /* to member var with local function name for recursion but doing */ \ /* so also allows the body to misuse `this` instead of `this_`) */ \ - inline BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id) \ + inline BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id, typename01) \ BOOST_LOCAL_FUNCTION_AUX_CODE_FUNCTOR_BODY_FUNC_( \ /* const binds */ \ BOOST_PP_LIST_FOR_EACH_I( \ diff --git a/include/boost/local_function/aux_/macro/code_/result.hpp b/include/boost/local_function/aux_/macro/code_/result.hpp index d4a3f2c..4dbd46d 100644 --- a/include/boost/local_function/aux_/macro/code_/result.hpp +++ b/include/boost/local_function/aux_/macro/code_/result.hpp @@ -39,8 +39,8 @@ #define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_PARAMS_(id) \ BOOST_LOCAL_FUNCTION_AUX_SYMBOL( (deduce_result_params)(id) ) -#define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_FUNC_TYPE_(id) \ - BOOST_LOCAL_FUNCTION_AUX_SYMBOL( (deduce_result_function_type)(id) ) +#define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE_(id) \ + BOOST_LOCAL_FUNCTION_AUX_SYMBOL( (result_type)(id) ) // User did not explicitly specified result type, deduce it (using Typeof). #define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_DEDUCE_( \ @@ -70,37 +70,38 @@ BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_CAPTURE_(id) \ ; \ struct BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_PARAMS_(id) { \ - /* this typedef is internal to struct so its name will not clash */ \ - typedef BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_CAPTURE_(id) \ - function_ptr; \ - }; \ - typedef BOOST_PP_EXPR_IIF(typename01, typename) \ - ::boost::remove_pointer< BOOST_PP_EXPR_IIF(typename01, typename) \ - BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_PARAMS_(id)::function_ptr \ - >::type \ - BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_FUNC_TYPE_(id) \ - ; \ - typedef BOOST_PP_EXPR_IIF(typename01, typename) \ - ::boost::function_traits< \ - BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_FUNC_TYPE_(id) \ - >::result_type \ - BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id) \ - ; + /* internal to struct to workaround GCC and other compiler's issues */ \ + typedef \ + BOOST_PP_EXPR_IIF(typename01, typename) \ + ::boost::function_traits< \ + BOOST_PP_EXPR_IIF(typename01, typename) \ + ::boost::remove_pointer< \ + BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_CAPTURE_(id) \ + >::type \ + >::result_type \ + BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE_(id) \ + ; \ + }; // Use result type as explicitly specified by user (no type deduction needed). // Precondition: RETURNS(decl_traits) != NIL #define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPED_( \ id, typename01, decl_traits) \ - typedef \ - BOOST_PP_LIST_FIRST(BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_RETURNS( \ - decl_traits)) \ - BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id) \ - ; + struct BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_PARAMS_(id) { \ + typedef \ + BOOST_PP_LIST_FIRST( \ + BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_RETURNS( \ + decl_traits)) \ + BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE_(id) \ + ; \ + }; // PUBLIC // -#define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id) \ - BOOST_LOCAL_FUNCTION_AUX_SYMBOL( (result_type)(id) ) +#define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id, typename01) \ + BOOST_PP_EXPR_IIF(typename01, typename) \ + BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_PARAMS_(id) :: \ + BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE_(id) #define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_DECL(id) \ /* result type here */ (*BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_FUNC_(id))(); diff --git a/test/return_derivative.cpp b/test/return_derivative.cpp index 5bd05dc..fe36d1f 100644 --- a/test/return_derivative.cpp +++ b/test/return_derivative.cpp @@ -17,6 +17,7 @@ #include BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function, 1) +BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function1, 2) // Also `functionN`. boost::function derivative(boost::function& f, int dx) { int BOOST_LOCAL_FUNCTION(bind& f, const bind dx, int x) { diff --git a/test/return_derivative_seq.cpp b/test/return_derivative_seq.cpp index b32ba37..9a33c00 100644 --- a/test/return_derivative_seq.cpp +++ b/test/return_derivative_seq.cpp @@ -12,6 +12,7 @@ #include BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function, 1) +BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function1, 2) // Also `functionN`. boost::function derivative(boost::function& f, int dx) { int BOOST_LOCAL_FUNCTION( (bind& f) (const bind dx) (int x) ) {