Ticket #4717: djw_function_const_vtable.patch

File djw_function_const_vtable.patch, 6.6 KB (added by Daniel Walker, 12 years ago)

Implements a const stored_vtable. Passes regressions on gcc 4.2, msvc 7.1, 10.0

  • boost/function/function_template.hpp

     
    486486                                            BOOST_FUNCTION_TEMPLATE_ARGS);
    487487
    488488        template<typename F>
    489         bool assign_to(F f, function_buffer& functor)
     489        bool assign_to(F f, function_buffer& functor) const
    490490        {
    491491          typedef typename get_function_tag<F>::type tag;
    492492          return assign_to(f, functor, tag());
    493493        }
    494494        template<typename F,typename Allocator>
    495         bool assign_to_a(F f, function_buffer& functor, Allocator a)
     495        bool assign_to_a(F f, function_buffer& functor, Allocator a) const
    496496        {
    497497          typedef typename get_function_tag<F>::type tag;
    498498          return assign_to_a(f, functor, a, tag());
    499499        }
    500500
    501         void clear(function_buffer& functor)
     501        void clear(function_buffer& functor) const
    502502        {
    503503          if (base.manager)
    504504            base.manager(functor, functor, destroy_functor_tag);
     
    508508        // Function pointers
    509509        template<typename FunctionPtr>
    510510        bool
    511         assign_to(FunctionPtr f, function_buffer& functor, function_ptr_tag)
     511        assign_to(FunctionPtr f, function_buffer& functor, function_ptr_tag) const
    512512        {
    513513          this->clear(functor);
    514514          if (f) {
     
    522522        }
    523523        template<typename FunctionPtr,typename Allocator>
    524524        bool
    525         assign_to_a(FunctionPtr f, function_buffer& functor, Allocator, function_ptr_tag)
     525        assign_to_a(FunctionPtr f, function_buffer& functor, Allocator, function_ptr_tag) const
    526526        {
    527527          return assign_to(f,functor,function_ptr_tag());
    528528        }
     
    530530        // Member pointers
    531531#if BOOST_FUNCTION_NUM_ARGS > 0
    532532        template<typename MemberPtr>
    533         bool assign_to(MemberPtr f, function_buffer& functor, member_ptr_tag)
     533        bool assign_to(MemberPtr f, function_buffer& functor, member_ptr_tag) const
    534534        {
    535535          // DPG TBD: Add explicit support for member function
    536536          // objects, so we invoke through mem_fn() but we retain the
     
    543543          }
    544544        }
    545545        template<typename MemberPtr,typename Allocator>
    546         bool assign_to_a(MemberPtr f, function_buffer& functor, Allocator a, member_ptr_tag)
     546        bool assign_to_a(MemberPtr f, function_buffer& functor, Allocator a, member_ptr_tag) const
    547547        {
    548548          // DPG TBD: Add explicit support for member function
    549549          // objects, so we invoke through mem_fn() but we retain the
     
    561561        // Assign to a function object using the small object optimization
    562562        template<typename FunctionObj>
    563563        void
    564         assign_functor(FunctionObj f, function_buffer& functor, mpl::true_)
     564        assign_functor(FunctionObj f, function_buffer& functor, mpl::true_) const
    565565        {
    566566          new (reinterpret_cast<void*>(&functor.data)) FunctionObj(f);
    567567        }
    568568        template<typename FunctionObj,typename Allocator>
    569569        void
    570         assign_functor_a(FunctionObj f, function_buffer& functor, Allocator, mpl::true_)
     570        assign_functor_a(FunctionObj f, function_buffer& functor, Allocator, mpl::true_) const
    571571        {
    572572          assign_functor(f,functor,mpl::true_());
    573573        }
     
    575575        // Assign to a function object allocated on the heap.
    576576        template<typename FunctionObj>
    577577        void
    578         assign_functor(FunctionObj f, function_buffer& functor, mpl::false_)
     578        assign_functor(FunctionObj f, function_buffer& functor, mpl::false_) const
    579579        {
    580580          functor.obj_ptr = new FunctionObj(f);
    581581        }
    582582        template<typename FunctionObj,typename Allocator>
    583583        void
    584         assign_functor_a(FunctionObj f, function_buffer& functor, Allocator a, mpl::false_)
     584        assign_functor_a(FunctionObj f, function_buffer& functor, Allocator a, mpl::false_) const
    585585        {
    586586          typedef functor_wrapper<FunctionObj,Allocator> functor_wrapper_type;
    587587          typedef typename Allocator::template rebind<functor_wrapper_type>::other
     
    596596
    597597        template<typename FunctionObj>
    598598        bool
    599         assign_to(FunctionObj f, function_buffer& functor, function_obj_tag)
     599        assign_to(FunctionObj f, function_buffer& functor, function_obj_tag) const
    600600        {
    601601          if (!boost::detail::function::has_empty_target(boost::addressof(f))) {
    602602            assign_functor(f, functor,
     
    608608        }
    609609        template<typename FunctionObj,typename Allocator>
    610610        bool
    611         assign_to_a(FunctionObj f, function_buffer& functor, Allocator a, function_obj_tag)
     611        assign_to_a(FunctionObj f, function_buffer& functor, Allocator a, function_obj_tag) const
    612612        {
    613613          if (!boost::detail::function::has_empty_target(boost::addressof(f))) {
    614614            assign_functor_a(f, functor, a,
     
    623623        template<typename FunctionObj>
    624624        bool
    625625        assign_to(const reference_wrapper<FunctionObj>& f,
    626                   function_buffer& functor, function_obj_ref_tag)
     626                  function_buffer& functor, function_obj_ref_tag) const
    627627        {
    628628          functor.obj_ref.obj_ptr = (void *)(f.get_pointer());
    629629          functor.obj_ref.is_const_qualified = is_const<FunctionObj>::value;
     
    633633        template<typename FunctionObj,typename Allocator>
    634634        bool
    635635        assign_to_a(const reference_wrapper<FunctionObj>& f,
    636                   function_buffer& functor, Allocator, function_obj_ref_tag)
     636                  function_buffer& functor, Allocator, function_obj_ref_tag) const
    637637        {
    638638          return assign_to(f,functor,function_obj_ref_tag());
    639639        }
     
    909909      // static initialization. Otherwise, we will have a race
    910910      // condition here in multi-threaded code. See
    911911      // http://thread.gmane.org/gmane.comp.lib.boost.devel/164902/.
    912       static vtable_type stored_vtable =
     912      static const vtable_type stored_vtable =
    913913        { { &manager_type::manage }, &invoker_type::invoke };
    914914
    915915      if (stored_vtable.assign_to(f, functor)) {
     
    943943      // static initialization. Otherwise, we will have a race
    944944      // condition here in multi-threaded code. See
    945945      // http://thread.gmane.org/gmane.comp.lib.boost.devel/164902/.
    946       static vtable_type stored_vtable =
     946      static const vtable_type stored_vtable =
    947947        { { &manager_type::manage }, &invoker_type::invoke };
    948948
    949949      if (stored_vtable.assign_to_a(f, functor, a)) {