Ticket #6828: forward_adaptor.patch

File forward_adaptor.patch, 10.6 KB (added by Eric Niebler, 10 years ago)

the following patch fixes the problem

  • boost/functional/detail/forward_adaptor_detail.hpp

     
     1/*=============================================================================
     2    Copyright (c) 2012 Eric Niebler
     3 
     4    Use modification and distribution are subject to the Boost Software
     5    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
     6    http://www.boost.org/LICENSE_1_0.txt).
     7==============================================================================*/
     8
     9#ifndef BOOST_FUNCTIONAL_FORWARD_ADAPTER_DETAIL_HPP_INCLUDED
     10#define BOOST_FUNCTIONAL_FORWARD_ADAPTER_DETAIL_HPP_INCLUDED
     11
     12#include <boost/config.hpp>
     13#include <boost/utility/result_of.hpp>
     14
     15namespace boost
     16{
     17    namespace detail
     18    {
     19        struct not_a_valid_type {};
     20        typedef not_a_valid_type (*pfn_vararg_t)(...);
     21
     22        template< class Sig, class Result = BOOST_DEDUCED_TYPENAME boost::result_of< Sig >::type >
     23        struct result_of_wrap
     24        {
     25            typedef Result type;
     26        };
     27
     28        template< class Sig >
     29        struct result_of_wrap< Sig, not_a_valid_type >
     30        { };
     31
     32        template< class F >
     33        struct vararg_function_wrapper
     34            : F
     35        {
     36            using F::operator();
     37            operator pfn_vararg_t() const volatile;
     38            vararg_function_wrapper();
     39        };
     40
     41        template< class F >
     42        struct wrap_vararg_function
     43        {
     44            typedef vararg_function_wrapper< F > type;
     45        };
     46
     47        template< class F >
     48        struct wrap_vararg_function< F const >
     49        {
     50            typedef vararg_function_wrapper< F > const type;
     51        };
     52    }
     53}
     54
     55#endif
     56
  • boost/functional/lightweight_forward_adapter.hpp

     
    1919#   include <boost/preprocessor/repetition/enum_binary_params.hpp>
    2020#   include <boost/preprocessor/facilities/intercept.hpp>
    2121
     22#   include <boost/functional/detail/forward_adaptor_detail.hpp>
    2223#   include <boost/utility/result_of.hpp>
    2324#   include <boost/ref.hpp>
    2425
     
    153154        struct lightweight_forward_adapter_impl<MD,F,FC,0,0>
    154155            : lightweight_forward_adapter_result
    155156        {
    156             inline typename boost::result_of< FC() >::type
     157            typedef BOOST_DEDUCED_TYPENAME wrap_vararg_function< FC >::type WFC;
     158            inline typename boost::result_of< WFC() >::type
    157159            operator()() const
    158160            {
    159161                return static_cast<MD const*>(this)->target_function()();
    160162            }
    161163
    162             inline typename boost::result_of< F() >::type
     164            typedef BOOST_DEDUCED_TYPENAME wrap_vararg_function< F >::type WF;
     165            inline typename boost::result_of< WF() >::type
    163166            operator()()
    164167            {
    165168                return static_cast<MD*>(this)->target_function()();
     
    213216        struct lightweight_forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),N>
    214217            : lightweight_forward_adapter_result
    215218        {
     219            typedef BOOST_DEDUCED_TYPENAME wrap_vararg_function< F >::type WF;
    216220            template< BOOST_PP_ENUM_PARAMS(N,typename T) >
    217             inline typename boost::result_of< F(BOOST_PP_ENUM_BINARY_PARAMS(N,
     221            inline typename result_of_wrap< WF(BOOST_PP_ENUM_BINARY_PARAMS(N,
    218222                T,const& BOOST_PP_INTERCEPT)) >::type
    219223            operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT));
    220224        };
  • boost/functional/forward_adapter.hpp

     
    1919#   include <boost/preprocessor/arithmetic/dec.hpp>
    2020
    2121#   include <boost/utility/result_of.hpp>
     22#   include <boost/functional/detail/forward_adaptor_detail.hpp>
    2223
    2324#   ifndef BOOST_FUNCTIONAL_FORWARD_ADAPTER_MAX_ARITY
    2425#     define BOOST_FUNCTIONAL_FORWARD_ADAPTER_MAX_ARITY 6
     
    147148        template< class MD, class F, class FC >
    148149        struct forward_adapter_impl<MD,F,FC,0,0>
    149150        {
    150             inline typename boost::result_of< FC() >::type
     151            typedef BOOST_DEDUCED_TYPENAME wrap_vararg_function< FC >::type WFC;
     152            inline typename boost::result_of< WFC() >::type
    151153            operator()() const
    152154            {
    153155                return static_cast<MD const*>(this)->target_function()();
    154156            }
    155157
    156             inline typename boost::result_of< F() >::type
     158            typedef BOOST_DEDUCED_TYPENAME wrap_vararg_function< F >::type WF;
     159            inline typename boost::result_of< WF() >::type
    157160            operator()()
    158161            {
    159162                return static_cast<MD*>(this)->target_function()();
     
    161164
    162165        // closing brace gets generated by preprocessing code, below
    163166
    164 #       define BOOST_TMP_MACRO(tpl_params,arg_types,params,args)              \
     167#       define BOOST_TMP_MACRO(tpl_params,arg_types,params,args)               \
    165168            template< tpl_params >                                             \
    166             inline typename boost::result_of< FC(arg_types) >::type            \
     169            inline typename result_of_wrap< WFC(arg_types) >::type             \
    167170            operator()(params) const                                           \
    168171            {                                                                  \
    169172                return static_cast<MD const*>(this)->target_function()(args);  \
    170173            }                                                                  \
    171174            template< tpl_params >                                             \
    172             inline typename boost::result_of< F(arg_types)>::type              \
     175            inline typename result_of_wrap< WF(arg_types)>::type               \
    173176            operator()(params)                                                 \
    174177            {                                                                  \
    175178                return static_cast<MD*>(this)->target_function()(args);        \
     
    333336        struct forward_adapter_impl<MD,F,FC,N,MinArity>
    334337            : forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),MinArity>
    335338        {
     339            typedef BOOST_DEDUCED_TYPENAME forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),MinArity>::WF WF;
     340            typedef BOOST_DEDUCED_TYPENAME forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),MinArity>::WFC WFC;
    336341            using forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),MinArity>::operator();
    337342
    338343#       endif
     
    424429
    425430#       if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1400))
    426431            template< BOOST_PP_ENUM_PARAMS(N,typename T) >
    427             inline typename boost::result_of<  FC(BOOST_PP_ENUM_PARAMS(N,PT))
     432            inline typename result_of_wrap<  WFC(BOOST_PP_ENUM_PARAMS(N,PT))
    428433                >::type
    429434            operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,PT,a)) const
    430435            {
     
    432437                    ->target_function()(BOOST_PP_ENUM_PARAMS(N,a));
    433438            }
    434439            template< BOOST_PP_ENUM_PARAMS(N,typename T) >
    435             inline typename boost::result_of<  F(BOOST_PP_ENUM_PARAMS(N,PT))
     440            inline typename result_of_wrap<  WF(BOOST_PP_ENUM_PARAMS(N,PT))
    436441                >::type
    437442            operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,PT,a))
    438443            {
  • libs/functional/forward/test/lightweight_forward_adapter.cpp

     
    6060    struct result< Self(int&,int const&) > { typedef long type; };
    6161
    6262    template <class Self>
    63     struct result< Self(int&,int&) > { typedef char type; };
     63    struct result< Self const(int&,int&) > { typedef int type; };
     64
     65    template <class Self>
     66    struct result< Self(int&,int&) > { typedef long type; };
    6467};
    6568
    6669enum { int_, long_, char_ };
     
    9093            result_of< f const (ref, cref) >::type, int >::value ));
    9194        // lvalue,lvalue
    9295        BOOST_TEST(( is_same<
    93             result_of< f(ref, ref) >::type, char >::value ));
     96            result_of< f(ref, ref) >::type, long >::value ));
    9497        BOOST_TEST(( is_same<
    95             result_of< f const (ref, ref) >::type, char >::value ));
     98            result_of< f const (ref, ref) >::type, int >::value ));
    9699    }
    97100    {
    98101        using boost::noncopyable;
     
    113116        BOOST_TEST( type_of( func_c(x,1) ) == int_ );
    114117        BOOST_TEST( type_of( func_c2(x,1) ) == int_ );
    115118        BOOST_TEST( type_of( func_c_ref(x,1) ) == int_ );
    116         BOOST_TEST( type_of( func(x,x) ) == char_ );
     119        BOOST_TEST( type_of( func(x,x) ) == long_ );
    117120
    118121        BOOST_TEST( func(x,1) == -8 );
    119122        BOOST_TEST( func_ref(x,1) == -8 );
  • libs/functional/forward/test/forward_adapter.cpp

     
    6060    struct result< Self(int&,int const&) > { typedef long type; };
    6161
    6262    template <class Self>
    63     struct result< Self(int&,int&) > { typedef char type; };
     63    struct result< Self const(int&,int&) > { typedef int type; };
     64
     65    template <class Self>
     66    struct result< Self(int&,int&) > { typedef long type; };
    6467};
    6568
    6669enum { int_, long_, char_ };
     
    8891            result_of< f const (int&, int const &) >::type, int >::value ));
    8992        // lvalue,lvalue
    9093        BOOST_TEST(( is_same<
    91             result_of< f(int&, int&) >::type, char >::value ));
     94            result_of< f(int&, int&) >::type, long >::value ));
    9295        BOOST_TEST(( is_same<
    93             result_of< f const (int&, int&) >::type, char >::value ));
     96            result_of< f const (int&, int&) >::type, int >::value ));
    9497    }
    9598
    9699    {
     
    112115        BOOST_TEST( type_of( func_c(x,1) ) == int_ );
    113116        BOOST_TEST( type_of( func_c2(x,1) ) == int_ );
    114117        BOOST_TEST( type_of( func_c_ref(x,1) ) == int_ );
    115         BOOST_TEST( type_of( func(x,x) ) == char_ );
     118        BOOST_TEST( type_of( func(x,x) ) == long_ );
    116119
    117120        BOOST_TEST( func(x,1) == -8 );
    118121        BOOST_TEST( func_ref(x,1) == -8 );