Ticket #4542: bind.patch

File bind.patch, 9.0 KB (added by anonymous, 12 years ago)

PoC patch. only supports 2 arguments and specific bindings

  • bind.hpp

     
    2929#include <boost/bind/arg.hpp>
    3030#include <boost/detail/workaround.hpp>
    3131#include <boost/visit_each.hpp>
     32#include <boost/utility/result_of.hpp>
    3233
    3334// Borland-specific bug, visit_each() silently fails to produce code
    3435
     
    272273struct logical_and;
    273274struct logical_or;
    274275
     276struct invalid{};
     277
     278template<class F,class L,class T,class Args>
     279struct argresult;
     280
     281template<class F,class L,class T,class Args>
     282struct argresult<F,L,value<T>,Args>{
     283    typedef T type;
     284};
     285
     286template<class F, class L,int I>
     287struct argresult<F,L,boost::arg<I>,bind_t<unspecified,F,L>()>{
     288    typedef invalid type;
     289};
     290
     291template<class F, class L, class A1>
     292struct argresult<F,L,boost::arg<1>,bind_t<unspecified,F,L>(A1)>{
     293    typedef A1 type;
     294};
     295
     296template<class F, class L, class A1>
     297struct argresult<F,L,boost::arg<1>,bind_t<unspecified,F,L>(A1 &)>{
     298    typedef A1 const &type;
     299};
     300
     301template<class F, class L, class A1,class A2>
     302struct argresult<F,L,boost::arg<1>,bind_t<unspecified,F,L>(A1,A2)>{
     303    typedef A1 type;
     304};
     305
     306template<class F, class L, class A1,class A2>
     307struct argresult<F,L,boost::arg<1>,bind_t<unspecified,F,L>(A1 &,A2)>{
     308    typedef A1 const &type;
     309};
     310
     311template<class F, class A1, class A2>
     312struct fresult2{
     313    typedef typename boost::result_of<F(A1,A2)>::type type;
     314};
     315
     316template<class F,class A1>
     317struct fresult2<F,A1,invalid>{
     318    typedef invalid type;
     319};
     320
     321template<class F,class A2>
     322struct fresult2<F,invalid,A2>{
     323    typedef invalid type;
     324};
     325
     326template<class F>
     327struct fresult2<F,invalid,invalid>{
     328    typedef invalid type;
     329};
     330
    275331template< class A1, class A2 > class list2: private storage2< A1, A2 >
    276332{
    277333private:
     
    280336
    281337public:
    282338
     339    template<class R, class F, class Args>
     340    struct bresult{
     341        typedef typename fresult2<
     342            F,
     343            typename argresult<F,list2,A1,Args>::type,
     344            typename argresult<F,list2,A2,Args>::type
     345        >::type type;
     346    };
     347
    283348    list2( A1 a1, A2 a2 ): base_type( a1, a2 ) {}
    284349
    285350    A1 operator[] (boost::arg<1>) const { return base_type::a1_; }
     
    349414    }
    350415};
    351416
     417
    352418template< class A1, class A2, class A3 > class list3: private storage3< A1, A2, A3 >
    353419{
    354420private:
     
    861927
    862928#ifndef BOOST_NO_VOID_RETURNS
    863929
     930template<class R, class F, class L, class Args>
     931struct bind_result;
     932
    864933template<class R, class F, class L> class bind_t
    865934{
    866935public:
     
    875944
    876945};
    877946
     947
    878948#else
    879949
    880950template<class R> struct bind_t_generator
  • bind_template.hpp

     
    1212//  See http://www.boost.org/libs/bind/bind.html for documentation.
    1313//
    1414
    15     typedef typename result_traits<R, F>::type result_type;
     15    template<typename Args>
     16    struct result{
     17        typedef typename L::bresult<R,F,Args>::type type;
     18    };
    1619
    17     result_type operator()()
     20    typename result<this_type()>::type operator()()
    1821    {
    1922        list0 a;
    20         BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     23        BOOST_BIND_RETURN l_(type<typename result<this_type()>::type>(), f_, a, 0);
    2124    }
    2225
    23     result_type operator()() const
     26    typename result<this_type()>::type operator()() const
    2427    {
    2528        list0 a;
    26         BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     29        BOOST_BIND_RETURN l_(type<typename result<this_type()>::type>(), f_, a, 0);
    2730    }
    2831
    29     template<class A1> result_type operator()(A1 & a1)
     32    template<class A1> typename result<this_type(A1 &)>::type operator()(A1 & a1)
    3033    {
    3134        list1<A1 &> a(a1);
    32         BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     35        BOOST_BIND_RETURN l_(type<typename result<this_type(A1 &)>::type>(), f_, a, 0);
    3336    }
    3437
    35     template<class A1> result_type operator()(A1 & a1) const
     38    template<class A1> typename result<this_type(A1 &)>::type operator()(A1 & a1) const
    3639    {
    3740        list1<A1 &> a(a1);
    38         BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     41        BOOST_BIND_RETURN l_(type<typename result<this_type(A1 &)>::type>(), f_, a, 0);
    3942    }
    4043
    4144#if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) \
    4245 && !BOOST_WORKAROUND(__EDG_VERSION__, <= 238)
    4346
    44     template<class A1> result_type operator()(A1 const & a1)
     47    template<class A1> typename result<this_type(A1 const &)>::type operator()(A1 const & a1)
    4548    {
    4649        list1<A1 const &> a(a1);
    47         BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     50        BOOST_BIND_RETURN l_(type<typename result<this_type(A1 const &)>::type>(), f_, a, 0);
    4851    }
    4952
    50     template<class A1> result_type operator()(A1 const & a1) const
     53    template<class A1> typename result<this_type(A1 const &)>::type operator()(A1 const & a1) const
    5154    {
    5255        list1<A1 const &> a(a1);
    53         BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     56        BOOST_BIND_RETURN l_(type<typename result<this_type(A1 const &)>::type>(), f_, a, 0);
    5457    }
    5558
    5659#endif
    5760
    58     template<class A1, class A2> result_type operator()(A1 & a1, A2 & a2)
     61    template<class A1, class A2> typename result<this_type(A1 &,A2 &)>::type operator()(A1 & a1, A2 & a2)
    5962    {
    6063        list2<A1 &, A2 &> a(a1, a2);
    61         BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     64        BOOST_BIND_RETURN l_(type<typename result<this_type(A1 &,A2 &)>::type>(), f_, a, 0);
    6265    }
    6366
    64     template<class A1, class A2> result_type operator()(A1 & a1, A2 & a2) const
     67    template<class A1, class A2> typename result<this_type(A1 &,A2 &)>::type operator()(A1 & a1, A2 & a2) const
    6568    {
    6669        list2<A1 &, A2 &> a(a1, a2);
    67         BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     70        BOOST_BIND_RETURN l_(type<typename result<this_type(A1 &,A2 &)>::type>(), f_, a, 0);
    6871    }
    6972
    7073#if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) \
    7174 && !BOOST_WORKAROUND(__EDG_VERSION__, <= 238)
    7275
    73     template<class A1, class A2> result_type operator()(A1 const & a1, A2 & a2)
     76    template<class A1, class A2> typename result<this_type(A1 const &,A2 &)>::type operator()(A1 const & a1, A2 & a2)
    7477    {
    7578        list2<A1 const &, A2 &> a(a1, a2);
    76         BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     79        BOOST_BIND_RETURN l_(type<typename result<this_type(A1 const &,A2 &)>::type>(), f_, a, 0);
    7780    }
    7881
    79     template<class A1, class A2> result_type operator()(A1 const & a1, A2 & a2) const
     82    template<class A1, class A2> typename result<this_type(A1 const &,A2 &)>::type operator()(A1 const & a1, A2 & a2) const
    8083    {
    8184        list2<A1 const &, A2 &> a(a1, a2);
    82         BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     85        BOOST_BIND_RETURN l_(type<typename result<this_type(A1 const &,A2 &)>::type>(), f_, a, 0);
    8386    }
    8487
    8588
    86     template<class A1, class A2> result_type operator()(A1 & a1, A2 const & a2)
     89    template<class A1, class A2> typename result<this_type(A1 &,A2 const &)>::type operator()(A1 & a1, A2 const & a2)
    8790    {
    8891        list2<A1 &, A2 const &> a(a1, a2);
    89         BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     92        BOOST_BIND_RETURN l_(type<typename result<this_type(A1 &,A2 const &)>::type>(), f_, a, 0);
    9093    }
    9194
    92     template<class A1, class A2> result_type operator()(A1 & a1, A2 const & a2) const
     95    template<class A1, class A2> typename result<this_type(A1 &,A2 const &)>::type operator()(A1 & a1, A2 const & a2) const
    9396    {
    9497        list2<A1 &, A2 const &> a(a1, a2);
    95         BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     98        BOOST_BIND_RETURN l_(type<typename result<this_type(A1 &,A2 const &)>::type>(), f_, a, 0);
    9699    }
    97100
    98101
    99     template<class A1, class A2> result_type operator()(A1 const & a1, A2 const & a2)
     102    template<class A1, class A2> typename result<this_type(A1 const &,A2 const &)>::type operator()(A1 const & a1, A2 const & a2)
    100103    {
    101104        list2<A1 const &, A2 const &> a(a1, a2);
    102         BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     105        BOOST_BIND_RETURN l_(type<typename result<this_type(A1 const &,A2 const &)>::type>(), f_, a, 0);
    103106    }
    104107
    105     template<class A1, class A2> result_type operator()(A1 const & a1, A2 const & a2) const
     108    template<class A1, class A2> typename result<this_type(A1 const &,A2 const &)>::type operator()(A1 const & a1, A2 const & a2) const
    106109    {
    107110        list2<A1 const &, A2 const &> a(a1, a2);
    108         BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     111        BOOST_BIND_RETURN l_(type<typename result<this_type(A1 const &,A2 const &)>::type>(), f_, a, 0);
    109112    }
    110113
    111114#endif
    112 
     115#if 0
    113116    template<class A1, class A2, class A3> result_type operator()(A1 & a1, A2 & a2, A3 & a3)
    114117    {
    115118        list3<A1 &, A2 &, A3 &> a(a1, a2, a3);
     
    312315    }
    313316
    314317#endif
    315 
     318#endif
     319#if 0
    316320    template<class A> result_type eval(A & a)
    317321    {
    318322        BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
     
    322326    {
    323327        BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
    324328    }
     329#endif
    325330
    326331    template<class V> void accept(V & v) const
    327332    {