Ticket #4717: djw_function_const_vtable.patch
File djw_function_const_vtable.patch, 6.6 KB (added by , 12 years ago) |
---|
-
boost/function/function_template.hpp
486 486 BOOST_FUNCTION_TEMPLATE_ARGS); 487 487 488 488 template<typename F> 489 bool assign_to(F f, function_buffer& functor) 489 bool assign_to(F f, function_buffer& functor) const 490 490 { 491 491 typedef typename get_function_tag<F>::type tag; 492 492 return assign_to(f, functor, tag()); 493 493 } 494 494 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 496 496 { 497 497 typedef typename get_function_tag<F>::type tag; 498 498 return assign_to_a(f, functor, a, tag()); 499 499 } 500 500 501 void clear(function_buffer& functor) 501 void clear(function_buffer& functor) const 502 502 { 503 503 if (base.manager) 504 504 base.manager(functor, functor, destroy_functor_tag); … … 508 508 // Function pointers 509 509 template<typename FunctionPtr> 510 510 bool 511 assign_to(FunctionPtr f, function_buffer& functor, function_ptr_tag) 511 assign_to(FunctionPtr f, function_buffer& functor, function_ptr_tag) const 512 512 { 513 513 this->clear(functor); 514 514 if (f) { … … 522 522 } 523 523 template<typename FunctionPtr,typename Allocator> 524 524 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 526 526 { 527 527 return assign_to(f,functor,function_ptr_tag()); 528 528 } … … 530 530 // Member pointers 531 531 #if BOOST_FUNCTION_NUM_ARGS > 0 532 532 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 534 534 { 535 535 // DPG TBD: Add explicit support for member function 536 536 // objects, so we invoke through mem_fn() but we retain the … … 543 543 } 544 544 } 545 545 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 547 547 { 548 548 // DPG TBD: Add explicit support for member function 549 549 // objects, so we invoke through mem_fn() but we retain the … … 561 561 // Assign to a function object using the small object optimization 562 562 template<typename FunctionObj> 563 563 void 564 assign_functor(FunctionObj f, function_buffer& functor, mpl::true_) 564 assign_functor(FunctionObj f, function_buffer& functor, mpl::true_) const 565 565 { 566 566 new (reinterpret_cast<void*>(&functor.data)) FunctionObj(f); 567 567 } 568 568 template<typename FunctionObj,typename Allocator> 569 569 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 571 571 { 572 572 assign_functor(f,functor,mpl::true_()); 573 573 } … … 575 575 // Assign to a function object allocated on the heap. 576 576 template<typename FunctionObj> 577 577 void 578 assign_functor(FunctionObj f, function_buffer& functor, mpl::false_) 578 assign_functor(FunctionObj f, function_buffer& functor, mpl::false_) const 579 579 { 580 580 functor.obj_ptr = new FunctionObj(f); 581 581 } 582 582 template<typename FunctionObj,typename Allocator> 583 583 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 585 585 { 586 586 typedef functor_wrapper<FunctionObj,Allocator> functor_wrapper_type; 587 587 typedef typename Allocator::template rebind<functor_wrapper_type>::other … … 596 596 597 597 template<typename FunctionObj> 598 598 bool 599 assign_to(FunctionObj f, function_buffer& functor, function_obj_tag) 599 assign_to(FunctionObj f, function_buffer& functor, function_obj_tag) const 600 600 { 601 601 if (!boost::detail::function::has_empty_target(boost::addressof(f))) { 602 602 assign_functor(f, functor, … … 608 608 } 609 609 template<typename FunctionObj,typename Allocator> 610 610 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 612 612 { 613 613 if (!boost::detail::function::has_empty_target(boost::addressof(f))) { 614 614 assign_functor_a(f, functor, a, … … 623 623 template<typename FunctionObj> 624 624 bool 625 625 assign_to(const reference_wrapper<FunctionObj>& f, 626 function_buffer& functor, function_obj_ref_tag) 626 function_buffer& functor, function_obj_ref_tag) const 627 627 { 628 628 functor.obj_ref.obj_ptr = (void *)(f.get_pointer()); 629 629 functor.obj_ref.is_const_qualified = is_const<FunctionObj>::value; … … 633 633 template<typename FunctionObj,typename Allocator> 634 634 bool 635 635 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 637 637 { 638 638 return assign_to(f,functor,function_obj_ref_tag()); 639 639 } … … 909 909 // static initialization. Otherwise, we will have a race 910 910 // condition here in multi-threaded code. See 911 911 // http://thread.gmane.org/gmane.comp.lib.boost.devel/164902/. 912 static vtable_type stored_vtable =912 static const vtable_type stored_vtable = 913 913 { { &manager_type::manage }, &invoker_type::invoke }; 914 914 915 915 if (stored_vtable.assign_to(f, functor)) { … … 943 943 // static initialization. Otherwise, we will have a race 944 944 // condition here in multi-threaded code. See 945 945 // http://thread.gmane.org/gmane.comp.lib.boost.devel/164902/. 946 static vtable_type stored_vtable =946 static const vtable_type stored_vtable = 947 947 { { &manager_type::manage }, &invoker_type::invoke }; 948 948 949 949 if (stored_vtable.assign_to_a(f, functor, a)) {