summaryrefslogtreecommitdiff
path: root/development/boost/boost-1_34_1-function-bugfix.diff
blob: 200e6c79fc356e540a4a4f6e5c21ee6d55f27567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
diff -U 3 -H -d -r -N -- boost_1_34_1/boost/function/function_base.hpp boost_1_34_1-patched/boost/function/function_base.hpp
--- boost_1_34_1/boost/function/function_base.hpp	2006-10-13 16:29:45.000000000 +0200
+++ boost_1_34_1-patched/boost/function/function_base.hpp	2007-12-22 10:21:10.000000000 +0100
@@ -15,6 +15,7 @@
 #include <memory>
 #include <new>
 #include <typeinfo>
+#include <functional> // unary_function, binary_function
 #include <boost/config.hpp>
 #include <boost/assert.hpp>
 #include <boost/type_traits/is_integral.hpp>
@@ -30,6 +31,20 @@
 #endif
 #include <boost/function_equal.hpp>
 
+#if defined(BOOST_MSVC)
+#   pragma warning( push )
+#   pragma warning( disable : 4793 ) // complaint about native code generation
+#   pragma warning( disable : 4127 ) // "conditional expression is constant"
+#endif       
+
+// Define BOOST_FUNCTION_STD_NS to the namespace that contains type_info.
+#ifdef BOOST_NO_EXCEPTION_STD_NAMESPACE
+// Embedded VC++ does not have type_info in namespace std
+#  define BOOST_FUNCTION_STD_NS
+#else
+#  define BOOST_FUNCTION_STD_NS std
+#endif
+
 // Borrowed from Boost.Python library: determines the cases where we
 // need to use std::type_info::name to compare instead of operator==.
 # if (defined(__GNUC__) && __GNUC__ >= 3) \
@@ -59,7 +74,7 @@
 
 #if defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)                    \
  || defined(BOOST_BCB_PARTIAL_SPECIALIZATION_BUG)                         \
- || !(BOOST_STRICT_CONFIG || !defined(__SUNPRO_CC) || __SUNPRO_CC > 0x540)
+ || !(defined(BOOST_STRICT_CONFIG) || !defined(__SUNPRO_CC) || __SUNPRO_CC > 0x540)
 #  define BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX
 #endif
 
@@ -198,8 +213,8 @@
       struct reference_manager
       {
         static inline void
-        get(const function_buffer& in_buffer, function_buffer& out_buffer, 
-            functor_manager_operation_type op)
+        manage(const function_buffer& in_buffer, function_buffer& out_buffer, 
+               functor_manager_operation_type op)
         {
           switch (op) {
           case clone_functor_tag: 
@@ -215,8 +230,8 @@
               // DPG TBD: Since we're only storing a pointer, it's
               // possible that the user could ask for a base class or
               // derived class. Is that okay?
-              const std::type_info& check_type = 
-                *static_cast<const std::type_info*>(out_buffer.const_obj_ptr);
+              const BOOST_FUNCTION_STD_NS::type_info& check_type = 
+                *static_cast<const BOOST_FUNCTION_STD_NS::type_info*>(out_buffer.const_obj_ptr);
               if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, typeid(F)))
                 out_buffer.obj_ptr = in_buffer.obj_ptr;
               else
@@ -265,8 +280,8 @@
           else if (op == destroy_functor_tag)
             out_buffer.func_ptr = 0;
           else /* op == check_functor_type_tag */ {
-            const std::type_info& check_type = 
-              *static_cast<const std::type_info*>(out_buffer.const_obj_ptr);
+            const BOOST_FUNCTION_STD_NS::type_info& check_type = 
+              *static_cast<const BOOST_FUNCTION_STD_NS::type_info*>(out_buffer.const_obj_ptr);
             if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, typeid(Functor)))
               out_buffer.obj_ptr = &in_buffer.func_ptr;
             else
@@ -287,8 +302,8 @@
             // Some compilers (Borland, vc6, ...) are unhappy with ~functor_type.
             reinterpret_cast<functor_type*>(&out_buffer.data)->~Functor();
           } else /* op == check_functor_type_tag */ {
-            const std::type_info& check_type = 
-              *static_cast<const std::type_info*>(out_buffer.const_obj_ptr);
+            const BOOST_FUNCTION_STD_NS::type_info& check_type = 
+              *static_cast<const BOOST_FUNCTION_STD_NS::type_info*>(out_buffer.const_obj_ptr);
             if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, typeid(Functor)))
               out_buffer.obj_ptr = &in_buffer.data;
             else
@@ -348,8 +363,8 @@
 #  endif // BOOST_NO_STD_ALLOCATOR
             out_buffer.obj_ptr = 0;
           } else /* op == check_functor_type_tag */ {
-            const std::type_info& check_type = 
-              *static_cast<const std::type_info*>(out_buffer.const_obj_ptr);
+            const BOOST_FUNCTION_STD_NS::type_info& check_type = 
+              *static_cast<const BOOST_FUNCTION_STD_NS::type_info*>(out_buffer.const_obj_ptr);
             if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, typeid(Functor)))
               out_buffer.obj_ptr = in_buffer.obj_ptr;
             else
@@ -368,6 +383,15 @@
                   mpl::bool_<(function_allows_small_object_optimization<functor_type>::value)>());
         }
 
+        // For member pointers, we treat them as function objects with
+        // the small-object optimization always enabled.
+        static inline void
+        manager(const function_buffer& in_buffer, function_buffer& out_buffer, 
+                functor_manager_operation_type op, member_ptr_tag)
+        {
+          manager(in_buffer, out_buffer, op, mpl::true_());
+        }
+
       public:
         /* Dispatch to an appropriate manager based on whether we have a
            function pointer or a function object pointer. */
@@ -456,7 +480,6 @@
        */
       struct vtable_base
       {
-        vtable_base() : manager(0) { }
         void (*manager)(const function_buffer& in_buffer, 
                         function_buffer& out_buffer, 
                         functor_manager_operation_type op);
@@ -480,13 +503,13 @@
 
   /** Retrieve the type of the stored function object, or typeid(void)
       if this is empty. */
-  const std::type_info& target_type() const
+  const BOOST_FUNCTION_STD_NS::type_info& target_type() const
   {
     if (!vtable) return typeid(void);
 
     detail::function::function_buffer type;
     vtable->manager(functor, type, detail::function::get_functor_type_tag);
-    return *static_cast<const std::type_info*>(type.const_obj_ptr);
+    return *static_cast<const BOOST_FUNCTION_STD_NS::type_info*>(type.const_obj_ptr);
   }
 
   template<typename Functor>
@@ -558,7 +581,7 @@
 #endif
 
 public: // should be protected, but GCC 2.95.3 will fail to allow access
-  detail::function::vtable_base* vtable;
+  const detail::function::vtable_base* vtable;
   mutable detail::function::function_buffer functor;
 };
 
@@ -733,4 +756,8 @@
 #undef BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL
 #undef BOOST_FUNCTION_COMPARE_TYPE_ID
 
+#if defined(BOOST_MSVC)
+#   pragma warning( pop )
+#endif       
+
 #endif // BOOST_FUNCTION_BASE_HEADER
diff -U 3 -H -d -r -N -- boost_1_34_1/boost/function/function_template.hpp boost_1_34_1-patched/boost/function/function_template.hpp
--- boost_1_34_1/boost/function/function_template.hpp	2006-09-29 19:23:28.000000000 +0200
+++ boost_1_34_1-patched/boost/function/function_template.hpp	2007-12-21 10:03:05.000000000 +0100
@@ -11,6 +11,11 @@
 // protection.
 #include <boost/function/detail/prologue.hpp>
 
+#if defined(BOOST_MSVC)
+#   pragma warning( push )
+#   pragma warning( disable : 4127 ) // "conditional expression is constant"
+#endif       
+
 #define BOOST_FUNCTION_TEMPLATE_PARMS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, typename T)
 
 #define BOOST_FUNCTION_TEMPLATE_ARGS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, T)
@@ -54,12 +59,20 @@
   BOOST_JOIN(function_ref_invoker,BOOST_FUNCTION_NUM_ARGS)
 #define BOOST_FUNCTION_VOID_FUNCTION_REF_INVOKER \
   BOOST_JOIN(void_function_ref_invoker,BOOST_FUNCTION_NUM_ARGS)
+#define BOOST_FUNCTION_MEMBER_INVOKER \
+  BOOST_JOIN(member_invoker,BOOST_FUNCTION_NUM_ARGS)
+#define BOOST_FUNCTION_VOID_MEMBER_INVOKER \
+  BOOST_JOIN(void_member_invoker,BOOST_FUNCTION_NUM_ARGS)
 #define BOOST_FUNCTION_GET_FUNCTION_INVOKER \
   BOOST_JOIN(get_function_invoker,BOOST_FUNCTION_NUM_ARGS)
 #define BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER \
   BOOST_JOIN(get_function_obj_invoker,BOOST_FUNCTION_NUM_ARGS)
 #define BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER \
   BOOST_JOIN(get_function_ref_invoker,BOOST_FUNCTION_NUM_ARGS)
+#define BOOST_FUNCTION_GET_MEMBER_INVOKER \
+  BOOST_JOIN(get_member_invoker,BOOST_FUNCTION_NUM_ARGS)
+#define BOOST_FUNCTION_GET_INVOKER \
+  BOOST_JOIN(get_invoker,BOOST_FUNCTION_NUM_ARGS)
 #define BOOST_FUNCTION_VTABLE BOOST_JOIN(basic_vtable,BOOST_FUNCTION_NUM_ARGS)
 
 #ifndef BOOST_NO_VOID_RETURNS
@@ -70,16 +83,6 @@
 #  define BOOST_FUNCTION_RETURN(X) X; return BOOST_FUNCTION_VOID_RETURN_TYPE ()
 #endif
 
-#ifdef BOOST_MSVC
-#  pragma warning(push)
-#  pragma warning(disable: 4127) // conditional expression is constant.
-#endif
-
-#ifdef BOOST_MSVC
-#  pragma warning(push)
-#  pragma warning(disable: 4127) // conditional expression is constant.
-#endif
-
 namespace boost {
   namespace detail {
     namespace function {
@@ -191,6 +194,44 @@
         }
       };
 
+#if BOOST_FUNCTION_NUM_ARGS > 0
+      /* Handle invocation of member pointers. */
+      template<
+        typename MemberPtr,
+        typename R BOOST_FUNCTION_COMMA
+        BOOST_FUNCTION_TEMPLATE_PARMS
+      >
+      struct BOOST_FUNCTION_MEMBER_INVOKER
+      {
+        static R invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
+                        BOOST_FUNCTION_PARMS)
+
+        {
+          MemberPtr* f = 
+            reinterpret_cast<MemberPtr*>(&function_obj_ptr.data);
+          return boost::mem_fn(*f)(BOOST_FUNCTION_ARGS);
+        }
+      };
+
+      template<
+        typename MemberPtr,
+        typename R BOOST_FUNCTION_COMMA
+        BOOST_FUNCTION_TEMPLATE_PARMS
+      >
+      struct BOOST_FUNCTION_VOID_MEMBER_INVOKER
+      {
+        static BOOST_FUNCTION_VOID_RETURN_TYPE
+        invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
+               BOOST_FUNCTION_PARMS)
+
+        {
+          MemberPtr* f = 
+            reinterpret_cast<MemberPtr*>(&function_obj_ptr.data);
+          BOOST_FUNCTION_RETURN(boost::mem_fn(*f)(BOOST_FUNCTION_ARGS));
+        }
+      };
+#endif
+
       template<
         typename FunctionPtr,
         typename R BOOST_FUNCTION_COMMA
@@ -254,12 +295,130 @@
                        >::type type;
       };
 
+#if BOOST_FUNCTION_NUM_ARGS > 0
+      /* Retrieve the appropriate invoker for a member pointer.  */
+      template<
+        typename MemberPtr,
+        typename R BOOST_FUNCTION_COMMA
+        BOOST_FUNCTION_TEMPLATE_PARMS
+       >
+      struct BOOST_FUNCTION_GET_MEMBER_INVOKER
+      {
+        typedef typename mpl::if_c<(is_void<R>::value),
+                            BOOST_FUNCTION_VOID_MEMBER_INVOKER<
+                            MemberPtr,
+                            R BOOST_FUNCTION_COMMA
+                            BOOST_FUNCTION_TEMPLATE_ARGS
+                          >,
+                          BOOST_FUNCTION_MEMBER_INVOKER<
+                            MemberPtr,
+                            R BOOST_FUNCTION_COMMA
+                            BOOST_FUNCTION_TEMPLATE_ARGS
+                          >
+                       >::type type;
+      };
+#endif
+
+      /* Given the tag returned by get_function_tag, retrieve the
+         actual invoker that will be used for the given function
+         object. 
+
+         Each specialization contains an "apply" nested class template
+         that accepts the function object, return type, function
+         argument types, and allocator. The resulting "apply" class
+         contains two typedefs, "invoker_type" and "manager_type",
+         which correspond to the invoker and manager types. */
+      template<typename Tag>
+      struct BOOST_FUNCTION_GET_INVOKER { };
+
+      /* Retrieve the invoker for a function pointer. */
+      template<>
+      struct BOOST_FUNCTION_GET_INVOKER<function_ptr_tag>
+      {
+        template<typename FunctionPtr,
+                 typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS,
+                 typename Allocator>
+        struct apply
+        {
+          typedef typename BOOST_FUNCTION_GET_FUNCTION_INVOKER<
+                             FunctionPtr,
+                             R BOOST_FUNCTION_COMMA
+                             BOOST_FUNCTION_TEMPLATE_ARGS
+                           >::type
+            invoker_type;
+
+          typedef functor_manager<FunctionPtr, Allocator> manager_type;
+        };
+      };
+
+#if BOOST_FUNCTION_NUM_ARGS > 0
+      /* Retrieve the invoker for a member pointer. */
+      template<>
+      struct BOOST_FUNCTION_GET_INVOKER<member_ptr_tag>
+      {
+        template<typename MemberPtr,
+                 typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS,
+                 typename Allocator>
+        struct apply
+        {
+          typedef typename BOOST_FUNCTION_GET_MEMBER_INVOKER<
+                             MemberPtr,
+                             R BOOST_FUNCTION_COMMA
+                             BOOST_FUNCTION_TEMPLATE_ARGS
+                           >::type
+            invoker_type;
+
+          typedef functor_manager<MemberPtr, Allocator> manager_type;
+        };
+      };
+#endif
+
+      /* Retrieve the invoker for a function object. */
+      template<>
+      struct BOOST_FUNCTION_GET_INVOKER<function_obj_tag>
+      {
+        template<typename FunctionObj,
+                 typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS,
+                 typename Allocator>
+        struct apply
+        {
+          typedef typename BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER<
+                             FunctionObj,
+                             R BOOST_FUNCTION_COMMA
+                             BOOST_FUNCTION_TEMPLATE_ARGS
+                           >::type
+            invoker_type;
+
+          typedef functor_manager<FunctionObj, Allocator> manager_type;
+        };
+      };
+
+      /* Retrieve the invoker for a reference to a function object. */
+      template<>
+      struct BOOST_FUNCTION_GET_INVOKER<function_obj_ref_tag>
+      {
+        template<typename RefWrapper,
+                 typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS,
+                 typename Allocator>
+        struct apply
+        {
+          typedef typename BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER<
+                             typename RefWrapper::type,
+                             R BOOST_FUNCTION_COMMA
+                             BOOST_FUNCTION_TEMPLATE_ARGS
+                           >::type
+            invoker_type;
+
+          typedef reference_manager<typename RefWrapper::type> manager_type;
+        };
+      };
+
       /**
        * vtable for a specific boost::function instance.
        */
       template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS,
                typename Allocator>
-      struct BOOST_FUNCTION_VTABLE : vtable_base
+      struct BOOST_FUNCTION_VTABLE
       {
 #ifndef BOOST_NO_VOID_RETURNS
         typedef R         result_type;
@@ -272,50 +431,25 @@
                                             BOOST_FUNCTION_TEMPLATE_ARGS);
 
         template<typename F>
-        BOOST_FUNCTION_VTABLE(F f) : vtable_base(), invoker(0)
-        {
-          init(f);
-        }
-
-        template<typename F>
-        bool assign_to(F f, function_buffer& functor)
+        bool assign_to(const F& f, function_buffer& functor) const
         {
           typedef typename get_function_tag<F>::type tag;
           return assign_to(f, functor, tag());
         }
 
-        void clear(function_buffer& functor)
+        void clear(function_buffer& functor) const
         {
-          if (manager)
-            manager(functor, functor, destroy_functor_tag);
+          if (base.manager)
+            base.manager(functor, functor, destroy_functor_tag);
         }
-
+#ifndef BOOST_NO_PRIVATE_IN_AGGREGATE
       private:
-        template<typename F>
-        void init(F f)
-        {
-          typedef typename get_function_tag<F>::type tag;
-          init(f, tag());
-        }
-
+#endif
         // Function pointers
         template<typename FunctionPtr>
-        void init(FunctionPtr /*f*/, function_ptr_tag)
-        {
-          typedef typename BOOST_FUNCTION_GET_FUNCTION_INVOKER<
-                             FunctionPtr,
-                             R BOOST_FUNCTION_COMMA
-                             BOOST_FUNCTION_TEMPLATE_ARGS
-                           >::type
-            actual_invoker_type;
-
-          invoker = &actual_invoker_type::invoke;
-          manager = &functor_manager<FunctionPtr, Allocator>::manage;
-        }
-
-        template<typename FunctionPtr>
         bool 
-        assign_to(FunctionPtr f, function_buffer& functor, function_ptr_tag)
+        assign_to(FunctionPtr f, function_buffer& functor, 
+                  function_ptr_tag) const
         {
           this->clear(functor);
           if (f) {
@@ -331,22 +465,13 @@
         // Member pointers
 #if BOOST_FUNCTION_NUM_ARGS > 0
         template<typename MemberPtr>
-        void init(MemberPtr f, member_ptr_tag)
-        {
-          // DPG TBD: Add explicit support for member function
-          // objects, so we invoke through mem_fn() but we retain the
-          // right target_type() values.
-          this->init(mem_fn(f));
-        }
-
-        template<typename MemberPtr>
-        bool assign_to(MemberPtr f, function_buffer& functor, member_ptr_tag)
+        bool 
+        assign_to(MemberPtr f, function_buffer& functor, member_ptr_tag) const
         {
-          // DPG TBD: Add explicit support for member function
-          // objects, so we invoke through mem_fn() but we retain the
-          // right target_type() values.
           if (f) {
-            this->assign_to(mem_fn(f), functor);
+            // Always use the small-object optimization for member
+            // pointers.
+            assign_functor(f, functor, mpl::true_());
             return true;
           } else {
             return false;
@@ -355,24 +480,11 @@
 #endif // BOOST_FUNCTION_NUM_ARGS > 0
 
         // Function objects
-        template<typename FunctionObj>
-        void init(FunctionObj /*f*/, function_obj_tag)
-        {
-          typedef typename BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER<
-                             FunctionObj,
-                             R BOOST_FUNCTION_COMMA
-                             BOOST_FUNCTION_TEMPLATE_ARGS
-                           >::type
-            actual_invoker_type;
-
-          invoker = &actual_invoker_type::invoke;
-          manager = &functor_manager<FunctionObj, Allocator>::manage;
-        }
-
         // Assign to a function object using the small object optimization
         template<typename FunctionObj>
         void 
-        assign_functor(FunctionObj f, function_buffer& functor, mpl::true_)
+        assign_functor(const FunctionObj& f, function_buffer& functor, 
+                       mpl::true_) const
         {
           new ((void*)&functor.data) FunctionObj(f);
         }
@@ -380,7 +492,8 @@
         // Assign to a function object allocated on the heap.
         template<typename FunctionObj>
         void 
-        assign_functor(FunctionObj f, function_buffer& functor, mpl::false_)
+        assign_functor(const FunctionObj& f, function_buffer& functor, 
+                       mpl::false_) const
         {
 #ifndef BOOST_NO_STD_ALLOCATOR
           typedef typename Allocator::template rebind<FunctionObj>::other
@@ -400,7 +513,8 @@
 
         template<typename FunctionObj>
         bool 
-        assign_to(FunctionObj f, function_buffer& functor, function_obj_tag)
+        assign_to(const FunctionObj& f, function_buffer& functor, 
+                  function_obj_tag) const
         {
           if (!boost::detail::function::has_empty_target(boost::addressof(f))) {
             assign_functor(f, functor, 
@@ -413,24 +527,9 @@
 
         // Reference to a function object
         template<typename FunctionObj>
-        void 
-        init(const reference_wrapper<FunctionObj>& /*f*/, function_obj_ref_tag)
-        {
-          typedef typename BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER<
-                             FunctionObj,
-                             R BOOST_FUNCTION_COMMA
-                             BOOST_FUNCTION_TEMPLATE_ARGS
-                           >::type
-            actual_invoker_type;
-
-          invoker = &actual_invoker_type::invoke;
-          manager = &reference_manager<FunctionObj>::get;
-        }
-
-        template<typename FunctionObj>
         bool 
         assign_to(const reference_wrapper<FunctionObj>& f, 
-                  function_buffer& functor, function_obj_ref_tag)
+                  function_buffer& functor, function_obj_ref_tag) const
         {
           if (!boost::detail::function::has_empty_target(f.get_pointer())) {
             // DPG TBD: We might need to detect constness of
@@ -445,6 +544,7 @@
         }
 
       public:
+        vtable_base base;
         invoker_type invoker;
       };
     } // end namespace function
@@ -456,6 +556,17 @@
     typename Allocator = BOOST_FUNCTION_DEFAULT_ALLOCATOR
   >
   class BOOST_FUNCTION_FUNCTION : public function_base
+
+#if BOOST_FUNCTION_NUM_ARGS == 1
+
+    , public std::unary_function<T0,R>
+
+#elif BOOST_FUNCTION_NUM_ARGS == 2
+
+    , public std::binary_function<T0,T1,R>
+
+#endif
+
   {
   public:
 #ifndef BOOST_NO_VOID_RETURNS
@@ -537,7 +648,7 @@
       if (this->empty())
         boost::throw_exception(bad_function_call());
 
-      return static_cast<vtable_type*>(vtable)->invoker
+      return reinterpret_cast<const vtable_type*>(vtable)->invoker
                (this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS);
     }
 #else
@@ -561,12 +672,16 @@
     operator=(Functor BOOST_FUNCTION_TARGET_FIX(const &) f)
     {
       this->clear();
+#ifndef BOOST_NO_EXCEPTIONS
       try {
         this->assign_to(f);
       } catch (...) {
         vtable = 0;
         throw;
       }
+#else
+      this->assign_to(f);
+#endif
       return *this;
     }
 
@@ -592,12 +707,16 @@
         return *this;
 
       this->clear();
+#ifndef BOOST_NO_EXCEPTIONS
       try {
         this->assign_to_own(f);
       } catch (...) {
         vtable = 0;
         throw;
       }
+#else
+      this->assign_to_own(f);
+#endif
       return *this;
     }
 
@@ -615,7 +734,7 @@
     void clear()
     {
       if (vtable) {
-        static_cast<vtable_type*>(vtable)->clear(this->functor);
+        reinterpret_cast<const vtable_type*>(vtable)->clear(this->functor);
         vtable = 0;
       }
     }
@@ -650,10 +769,24 @@
     }
 
     template<typename Functor>
-    void assign_to(Functor f)
+    void assign_to(const Functor& f)
     {
-      static vtable_type stored_vtable(f);
-      if (stored_vtable.assign_to(f, functor)) vtable = &stored_vtable;
+      using detail::function::vtable_base;
+
+      typedef typename detail::function::get_function_tag<Functor>::type tag;
+      typedef detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
+      typedef typename get_invoker::
+                         template apply<Functor, R BOOST_FUNCTION_COMMA 
+                        BOOST_FUNCTION_TEMPLATE_ARGS, Allocator>
+        handler_type;
+      
+      typedef typename handler_type::invoker_type invoker_type;
+      typedef typename handler_type::manager_type manager_type;
+      
+      static const vtable_type stored_vtable = 
+        { { &manager_type::manage }, &invoker_type::invoke };
+
+      if (stored_vtable.assign_to(f, functor)) vtable = &stored_vtable.base;
       else vtable = 0;
     }
   };
@@ -688,7 +821,7 @@
     if (this->empty())
       boost::throw_exception(bad_function_call());
 
-    return static_cast<vtable_type*>(vtable)->invoker
+    return reinterpret_cast<const vtable_type*>(vtable)->invoker
              (this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS);
   }
 #endif
@@ -798,21 +931,14 @@
   }
 };
 
-#ifdef BOOST_MSVC
-# pragma warning(pop)
-#endif
-
 #undef BOOST_FUNCTION_PARTIAL_SPEC
 #endif // have partial specialization
 
 } // end namespace boost
 
-#ifdef BOOST_MSVC
-# pragma warning(pop)
-#endif
-
 // Cleanup after ourselves...
 #undef BOOST_FUNCTION_VTABLE
+#undef BOOST_FUNCTION_GET_INVOKER
 #undef BOOST_FUNCTION_DEFAULT_ALLOCATOR
 #undef BOOST_FUNCTION_COMMA
 #undef BOOST_FUNCTION_FUNCTION
@@ -822,10 +948,12 @@
 #undef BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER
 #undef BOOST_FUNCTION_FUNCTION_REF_INVOKER
 #undef BOOST_FUNCTION_VOID_FUNCTION_REF_INVOKER
+#undef BOOST_FUNCTION_MEMBER_INVOKER
+#undef BOOST_FUNCTION_VOID_MEMBER_INVOKER
 #undef BOOST_FUNCTION_GET_FUNCTION_INVOKER
 #undef BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER
 #undef BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER
-#undef BOOST_FUNCTION_GET_MEM_FUNCTION_INVOKER
+#undef BOOST_FUNCTION_GET_MEMBER_INVOKER
 #undef BOOST_FUNCTION_TEMPLATE_PARMS
 #undef BOOST_FUNCTION_TEMPLATE_ARGS
 #undef BOOST_FUNCTION_PARMS
@@ -835,3 +963,7 @@
 #undef BOOST_FUNCTION_ARG_TYPES
 #undef BOOST_FUNCTION_VOID_RETURN_TYPE
 #undef BOOST_FUNCTION_RETURN
+
+#if defined(BOOST_MSVC)
+#   pragma warning( pop )
+#endif