function_template.hpp
Go to the documentation of this file.
1 // Boost.Function library
2 
3 // Copyright Douglas Gregor 2001-2006
4 // Copyright Emil Dotchevski 2007
5 // Use, modification and distribution is subject to the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 
9 // For more information, see http://www.boost.org
10 
11 // Note: this header is a header template and must NOT have multiple-inclusion
12 // protection.
15 
16 #if defined(BOOST_MSVC)
17 # pragma warning( push )
18 # pragma warning( disable : 4127 ) // "conditional expression is constant"
19 #endif
20 
21 #define BOOST_FUNCTION_TEMPLATE_PARMS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, typename T)
22 
23 #define BOOST_FUNCTION_TEMPLATE_ARGS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, T)
24 
25 #define BOOST_FUNCTION_PARM(J,I,D) BOOST_PP_CAT(T,I) BOOST_PP_CAT(a,I)
26 
27 #define BOOST_FUNCTION_PARMS BOOST_PP_ENUM(BOOST_FUNCTION_NUM_ARGS,BOOST_FUNCTION_PARM,BOOST_PP_EMPTY)
28 
29 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
30 # define BOOST_FUNCTION_ARGS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, a)
31 #else
33 # define BOOST_FUNCTION_ARG(J,I,D) ::boost::forward< BOOST_PP_CAT(T,I) >(BOOST_PP_CAT(a,I))
34 # define BOOST_FUNCTION_ARGS BOOST_PP_ENUM(BOOST_FUNCTION_NUM_ARGS,BOOST_FUNCTION_ARG,BOOST_PP_EMPTY)
35 #endif
36 
37 #define BOOST_FUNCTION_ARG_TYPE(J,I,D) \
38  typedef BOOST_PP_CAT(T,I) BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(I)),_type);
39 
40 #define BOOST_FUNCTION_ARG_TYPES BOOST_PP_REPEAT(BOOST_FUNCTION_NUM_ARGS,BOOST_FUNCTION_ARG_TYPE,BOOST_PP_EMPTY)
41 
42 // Comma if nonzero number of arguments
43 #if BOOST_FUNCTION_NUM_ARGS == 0
44 # define BOOST_FUNCTION_COMMA
45 #else
46 # define BOOST_FUNCTION_COMMA ,
47 #endif // BOOST_FUNCTION_NUM_ARGS > 0
48 
49 // Class names used in this version of the code
50 #define BOOST_FUNCTION_FUNCTION BOOST_JOIN(function,BOOST_FUNCTION_NUM_ARGS)
51 #define BOOST_FUNCTION_FUNCTION_INVOKER \
52  BOOST_JOIN(function_invoker,BOOST_FUNCTION_NUM_ARGS)
53 #define BOOST_FUNCTION_VOID_FUNCTION_INVOKER \
54  BOOST_JOIN(void_function_invoker,BOOST_FUNCTION_NUM_ARGS)
55 #define BOOST_FUNCTION_FUNCTION_OBJ_INVOKER \
56  BOOST_JOIN(function_obj_invoker,BOOST_FUNCTION_NUM_ARGS)
57 #define BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER \
58  BOOST_JOIN(void_function_obj_invoker,BOOST_FUNCTION_NUM_ARGS)
59 #define BOOST_FUNCTION_FUNCTION_REF_INVOKER \
60  BOOST_JOIN(function_ref_invoker,BOOST_FUNCTION_NUM_ARGS)
61 #define BOOST_FUNCTION_VOID_FUNCTION_REF_INVOKER \
62  BOOST_JOIN(void_function_ref_invoker,BOOST_FUNCTION_NUM_ARGS)
63 #define BOOST_FUNCTION_MEMBER_INVOKER \
64  BOOST_JOIN(function_mem_invoker,BOOST_FUNCTION_NUM_ARGS)
65 #define BOOST_FUNCTION_VOID_MEMBER_INVOKER \
66  BOOST_JOIN(function_void_mem_invoker,BOOST_FUNCTION_NUM_ARGS)
67 #define BOOST_FUNCTION_GET_FUNCTION_INVOKER \
68  BOOST_JOIN(get_function_invoker,BOOST_FUNCTION_NUM_ARGS)
69 #define BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER \
70  BOOST_JOIN(get_function_obj_invoker,BOOST_FUNCTION_NUM_ARGS)
71 #define BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER \
72  BOOST_JOIN(get_function_ref_invoker,BOOST_FUNCTION_NUM_ARGS)
73 #define BOOST_FUNCTION_GET_MEMBER_INVOKER \
74  BOOST_JOIN(get_member_invoker,BOOST_FUNCTION_NUM_ARGS)
75 #define BOOST_FUNCTION_GET_INVOKER \
76  BOOST_JOIN(get_invoker,BOOST_FUNCTION_NUM_ARGS)
77 #define BOOST_FUNCTION_VTABLE BOOST_JOIN(basic_vtable,BOOST_FUNCTION_NUM_ARGS)
78 
79 #ifndef BOOST_NO_VOID_RETURNS
80 # define BOOST_FUNCTION_VOID_RETURN_TYPE void
81 # define BOOST_FUNCTION_RETURN(X) X
82 #else
83 # define BOOST_FUNCTION_VOID_RETURN_TYPE boost::detail::function::unusable
84 # define BOOST_FUNCTION_RETURN(X) X; return BOOST_FUNCTION_VOID_RETURN_TYPE ()
85 #endif
86 
87 namespace boost {
88  namespace detail {
89  namespace function {
90  template<
91  typename FunctionPtr,
92  typename R BOOST_FUNCTION_COMMA
94  >
96  {
99  {
100  FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.func_ptr);
101  return f(BOOST_FUNCTION_ARGS);
102  }
103  };
104 
105  template<
106  typename FunctionPtr,
107  typename R BOOST_FUNCTION_COMMA
109  >
111  {
115 
116  {
117  FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.func_ptr);
119  }
120  };
121 
122  template<
123  typename FunctionObj,
124  typename R BOOST_FUNCTION_COMMA
126  >
128  {
129  static R invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
131 
132  {
133  FunctionObj* f;
135  f = reinterpret_cast<FunctionObj*>(&function_obj_ptr.data);
136  else
137  f = reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);
138  return (*f)(BOOST_FUNCTION_ARGS);
139  }
140  };
141 
142  template<
143  typename FunctionObj,
144  typename R BOOST_FUNCTION_COMMA
146  >
148  {
152 
153  {
154  FunctionObj* f;
156  f = reinterpret_cast<FunctionObj*>(&function_obj_ptr.data);
157  else
158  f = reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);
160  }
161  };
162 
163  template<
164  typename FunctionObj,
165  typename R BOOST_FUNCTION_COMMA
167  >
169  {
170  static R invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
172 
173  {
174  FunctionObj* f =
175  reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);
176  return (*f)(BOOST_FUNCTION_ARGS);
177  }
178  };
179 
180  template<
181  typename FunctionObj,
182  typename R BOOST_FUNCTION_COMMA
184  >
186  {
190 
191  {
192  FunctionObj* f =
193  reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);
195  }
196  };
197 
198 #if BOOST_FUNCTION_NUM_ARGS > 0
199  /* Handle invocation of member pointers. */
200  template<
201  typename MemberPtr,
202  typename R BOOST_FUNCTION_COMMA
204  >
206  {
207  static R invoke(function_buffer& function_obj_ptr BOOST_FUNCTION_COMMA
209 
210  {
211  MemberPtr* f =
212  reinterpret_cast<MemberPtr*>(&function_obj_ptr.data);
213  return std::mem_fn(*f)(BOOST_FUNCTION_ARGS);
214  }
215  };
216 
217  template<
218  typename MemberPtr,
219  typename R BOOST_FUNCTION_COMMA
221  >
223  {
227 
228  {
229  MemberPtr* f =
230  reinterpret_cast<MemberPtr*>(&function_obj_ptr.data);
231  BOOST_FUNCTION_RETURN(std::mem_fn(*f)(BOOST_FUNCTION_ARGS));
232  }
233  };
234 #endif
235 
236  template<
237  typename FunctionPtr,
238  typename R BOOST_FUNCTION_COMMA
240  >
242  {
243  typedef typename mpl::if_c<(is_void<R>::value),
245  FunctionPtr,
248  >,
250  FunctionPtr,
253  >
254  >::type type;
255  };
256 
257  template<
258  typename FunctionObj,
259  typename R BOOST_FUNCTION_COMMA
261  >
263  {
264  typedef typename mpl::if_c<(is_void<R>::value),
266  FunctionObj,
269  >,
271  FunctionObj,
274  >
275  >::type type;
276  };
277 
278  template<
279  typename FunctionObj,
280  typename R BOOST_FUNCTION_COMMA
282  >
284  {
285  typedef typename mpl::if_c<(is_void<R>::value),
287  FunctionObj,
290  >,
292  FunctionObj,
295  >
296  >::type type;
297  };
298 
299 #if BOOST_FUNCTION_NUM_ARGS > 0
300  /* Retrieve the appropriate invoker for a member pointer. */
301  template<
302  typename MemberPtr,
303  typename R BOOST_FUNCTION_COMMA
305  >
307  {
308  typedef typename mpl::if_c<(is_void<R>::value),
310  MemberPtr,
313  >,
315  MemberPtr,
318  >
319  >::type type;
320  };
321 #endif
322 
323  /* Given the tag returned by get_function_tag, retrieve the
324  actual invoker that will be used for the given function
325  object.
326 
327  Each specialization contains an "apply" nested class template
328  that accepts the function object, return type, function
329  argument types, and allocator. The resulting "apply" class
330  contains two typedefs, "invoker_type" and "manager_type",
331  which correspond to the invoker and manager types. */
332  template<typename Tag>
334 
335  /* Retrieve the invoker for a function pointer. */
336  template<>
338  {
339  template<typename FunctionPtr,
341  struct apply
342  {
343  typedef typename BOOST_FUNCTION_GET_FUNCTION_INVOKER<
344  FunctionPtr,
347  >::type
349 
351  };
352 
353  template<typename FunctionPtr,
355  typename Allocator>
356  struct apply_a
357  {
358  typedef typename BOOST_FUNCTION_GET_FUNCTION_INVOKER<
359  FunctionPtr,
362  >::type
364 
366  };
367  };
368 
369 #if BOOST_FUNCTION_NUM_ARGS > 0
370  /* Retrieve the invoker for a member pointer. */
371  template<>
373  {
374  template<typename MemberPtr,
376  struct apply
377  {
378  typedef typename BOOST_FUNCTION_GET_MEMBER_INVOKER<
379  MemberPtr,
382  >::type
383  invoker_type;
384 
386  };
387 
388  template<typename MemberPtr,
390  typename Allocator>
391  struct apply_a
392  {
393  typedef typename BOOST_FUNCTION_GET_MEMBER_INVOKER<
394  MemberPtr,
397  >::type
398  invoker_type;
399 
401  };
402  };
403 #endif
404 
405  /* Retrieve the invoker for a function object. */
406  template<>
408  {
409  template<typename FunctionObj,
411  struct apply
412  {
414  FunctionObj,
417  >::type
419 
421  };
422 
423  template<typename FunctionObj,
425  typename Allocator>
426  struct apply_a
427  {
429  FunctionObj,
432  >::type
434 
436  };
437  };
438 
439  /* Retrieve the invoker for a reference to a function object. */
440  template<>
442  {
443  template<typename RefWrapper,
445  struct apply
446  {
448  typename RefWrapper::type,
451  >::type
453 
455  };
456 
457  template<typename RefWrapper,
459  typename Allocator>
460  struct apply_a
461  {
463  typename RefWrapper::type,
466  >::type
468 
470  };
471  };
472 
473 
481  template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
483  {
484 #ifndef BOOST_NO_VOID_RETURNS
485  typedef R result_type;
486 #else
487  typedef typename function_return_type<R>::type result_type;
488 #endif // BOOST_NO_VOID_RETURNS
489 
490  typedef result_type (*invoker_type)(function_buffer&
493 
494  template<typename F>
495  bool assign_to(F f, function_buffer& functor) const
496  {
497  typedef typename get_function_tag<F>::type tag;
498  return assign_to(f, functor, tag());
499  }
500  template<typename F,typename Allocator>
501  bool assign_to_a(F f, function_buffer& functor, Allocator a) const
502  {
503  typedef typename get_function_tag<F>::type tag;
504  return assign_to_a(f, functor, a, tag());
505  }
506 
507  void clear(function_buffer& functor) const
508  {
509  if (base.manager)
510  base.manager(functor, functor, destroy_functor_tag);
511  }
512 
513  private:
514  // Function pointers
515  template<typename FunctionPtr>
516  bool
517  assign_to(FunctionPtr f, function_buffer& functor, function_ptr_tag) const
518  {
519  this->clear(functor);
520  if (f) {
521  // should be a reinterpret cast, but some compilers insist
522  // on giving cv-qualifiers to free functions
523  functor.func_ptr = reinterpret_cast<void (*)()>(f);
524  return true;
525  } else {
526  return false;
527  }
528  }
529  template<typename FunctionPtr,typename Allocator>
530  bool
531  assign_to_a(FunctionPtr f, function_buffer& functor, Allocator, function_ptr_tag) const
532  {
533  return assign_to(f,functor,function_ptr_tag());
534  }
535 
536  // Member pointers
537 #if BOOST_FUNCTION_NUM_ARGS > 0
538  template<typename MemberPtr>
539  bool assign_to(MemberPtr f, function_buffer& functor, member_ptr_tag) const
540  {
541  // DPG TBD: Add explicit support for member function
542  // objects, so we invoke through mem_fn() but we retain the
543  // right target_type() values.
544  if (f) {
545  this->assign_to(std::mem_fn(f), functor);
546  return true;
547  } else {
548  return false;
549  }
550  }
551  template<typename MemberPtr,typename Allocator>
552  bool assign_to_a(MemberPtr f, function_buffer& functor, Allocator a, member_ptr_tag) const
553  {
554  // DPG TBD: Add explicit support for member function
555  // objects, so we invoke through mem_fn() but we retain the
556  // right target_type() values.
557  if (f) {
558  this->assign_to_a(std::mem_fn(f), functor, a);
559  return true;
560  } else {
561  return false;
562  }
563  }
564 #endif // BOOST_FUNCTION_NUM_ARGS > 0
565 
566  // Function objects
567  // Assign to a function object using the small object optimization
568  template<typename FunctionObj>
569  void
570  assign_functor(FunctionObj f, function_buffer& functor, mpl::true_) const
571  {
572  new (reinterpret_cast<void*>(&functor.data)) FunctionObj(f);
573  }
574  template<typename FunctionObj,typename Allocator>
575  void
576  assign_functor_a(FunctionObj f, function_buffer& functor, Allocator, mpl::true_) const
577  {
578  assign_functor(f,functor,mpl::true_());
579  }
580 
581  // Assign to a function object allocated on the heap.
582  template<typename FunctionObj>
583  void
584  assign_functor(FunctionObj f, function_buffer& functor, mpl::false_) const
585  {
586  functor.obj_ptr = new FunctionObj(f);
587  }
588  template<typename FunctionObj,typename Allocator>
589  void
590  assign_functor_a(FunctionObj f, function_buffer& functor, Allocator a, mpl::false_) const
591  {
592  typedef functor_wrapper<FunctionObj,Allocator> functor_wrapper_type;
593  typedef typename Allocator::template rebind<functor_wrapper_type>::other
594  wrapper_allocator_type;
595  typedef typename wrapper_allocator_type::pointer wrapper_allocator_pointer_type;
596  wrapper_allocator_type wrapper_allocator(a);
597  wrapper_allocator_pointer_type copy = wrapper_allocator.allocate(1);
598  wrapper_allocator.construct(copy, functor_wrapper_type(f,a));
599  functor_wrapper_type* new_f = static_cast<functor_wrapper_type*>(copy);
600  functor.obj_ptr = new_f;
601  }
602 
603  template<typename FunctionObj>
604  bool
605  assign_to(FunctionObj f, function_buffer& functor, function_obj_tag) const
606  {
608  assign_functor(f, functor,
610  return true;
611  } else {
612  return false;
613  }
614  }
615  template<typename FunctionObj,typename Allocator>
616  bool
617  assign_to_a(FunctionObj f, function_buffer& functor, Allocator a, function_obj_tag) const
618  {
620  assign_functor_a(f, functor, a,
622  return true;
623  } else {
624  return false;
625  }
626  }
627 
628  // Reference to a function object
629  template<typename FunctionObj>
630  bool
632  function_buffer& functor, function_obj_ref_tag) const
633  {
634  functor.obj_ref.obj_ptr = (void *)(f.get_pointer());
637  return true;
638  }
639  template<typename FunctionObj,typename Allocator>
640  bool
642  function_buffer& functor, Allocator, function_obj_ref_tag) const
643  {
644  return assign_to(f,functor,function_obj_ref_tag());
645  }
646 
647  public:
649  invoker_type invoker;
650  };
651  } // end namespace function
652  } // end namespace detail
653 
654  template<
655  typename R BOOST_FUNCTION_COMMA
657  >
659 
660 #if BOOST_FUNCTION_NUM_ARGS == 1
661 
662  , public std::unary_function<T0,R>
663 
664 #elif BOOST_FUNCTION_NUM_ARGS == 2
665 
666  , public std::binary_function<T0,T1,R>
667 
668 #endif
669 
670  {
671  public:
672 #ifndef BOOST_NO_VOID_RETURNS
673  typedef R result_type;
674 #else
676  result_type;
677 #endif // BOOST_NO_VOID_RETURNS
678 
679  private:
683 
685  return reinterpret_cast<vtable_type*>(
686  reinterpret_cast<std::size_t>(vtable) & ~static_cast<std::size_t>(0x01));
687  }
688 
689  struct clear_type {};
690 
691  public:
693 
694  // add signature for boost::lambda
695  template<typename Args>
696  struct sig
697  {
698  typedef result_type type;
699  };
700 
701 #if BOOST_FUNCTION_NUM_ARGS == 1
702  typedef T0 argument_type;
703 #elif BOOST_FUNCTION_NUM_ARGS == 2
704  typedef T0 first_argument_type;
705  typedef T1 second_argument_type;
706 #endif
707 
710 
712 
714 
715  // MSVC chokes if the following two constructors are collapsed into
716  // one with a default parameter.
717  template<typename Functor>
719 #ifndef BOOST_NO_SFINAE
720  ,typename enable_if_c<
723  int>::type = 0
724 #endif // BOOST_NO_SFINAE
725  ) :
726  function_base()
727  {
728  this->assign_to(f);
729  }
730  template<typename Functor,typename Allocator>
732 #ifndef BOOST_NO_SFINAE
733  ,typename enable_if_c<
736  int>::type = 0
737 #endif // BOOST_NO_SFINAE
738  ) :
739  function_base()
740  {
741  this->assign_to_a(f,a);
742  }
743 
744 #ifndef BOOST_NO_SFINAE
746 #else
748  {
749  BOOST_ASSERT(zero == 0);
750  }
751 #endif
752 
754  {
755  this->assign_to_own(f);
756  }
757 
758 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
760  {
761  this->move_assign(f);
762  }
763 #endif
764 
766 
767  result_type operator()(BOOST_FUNCTION_PARMS) const
768  {
769  if (this->empty())
771 
772  return get_vtable()->invoker
774  }
775 
776  // The distinction between when to use BOOST_FUNCTION_FUNCTION and
777  // when to use self_type is obnoxious. MSVC cannot handle self_type as
778  // the return type of these assignment operators, but Borland C++ cannot
779  // handle BOOST_FUNCTION_FUNCTION as the type of the temporary to
780  // construct.
781  template<typename Functor>
782 #ifndef BOOST_NO_SFINAE
783  typename enable_if_c<
787 #else
789 #endif
791  {
792  this->clear();
793  BOOST_TRY {
794  this->assign_to(f);
795  } BOOST_CATCH (...) {
796  vtable = 0;
798  }
800  return *this;
801  }
802  template<typename Functor,typename Allocator>
803  void assign(Functor BOOST_FUNCTION_TARGET_FIX(const &) f, Allocator a)
804  {
805  this->clear();
806  BOOST_TRY{
807  this->assign_to_a(f,a);
808  } BOOST_CATCH (...) {
809  vtable = 0;
811  }
813  }
814 
815 #ifndef BOOST_NO_SFINAE
817  {
818  this->clear();
819  return *this;
820  }
821 #else
822  BOOST_FUNCTION_FUNCTION& operator=(int zero)
823  {
824  BOOST_ASSERT(zero == 0);
825  this->clear();
826  return *this;
827  }
828 #endif
829 
830  // Assignment from another BOOST_FUNCTION_FUNCTION
832  {
833  if (&f == this)
834  return *this;
835 
836  this->clear();
837  BOOST_TRY {
838  this->assign_to_own(f);
839  } BOOST_CATCH (...) {
840  vtable = 0;
842  }
844  return *this;
845  }
846 
847 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
848  // Move assignment from another BOOST_FUNCTION_FUNCTION
850  {
851 
852  if (&f == this)
853  return *this;
854 
855  this->clear();
856  BOOST_TRY {
857  this->move_assign(f);
858  } BOOST_CATCH (...) {
859  vtable = 0;
861  }
863  return *this;
864  }
865 #endif
866 
868  {
869  if (&other == this)
870  return;
871 
873  tmp.move_assign(*this);
874  this->move_assign(other);
875  other.move_assign(tmp);
876  }
877 
878  // Clear out a target, if there is one
879  void clear()
880  {
881  if (vtable) {
882  if (!this->has_trivial_copy_and_destroy())
883  get_vtable()->clear(this->functor);
884  vtable = 0;
885  }
886  }
887 
888 #if (defined __SUNPRO_CC) && (__SUNPRO_CC <= 0x530) && !(defined BOOST_NO_COMPILER_CONFIG)
889  // Sun C++ 5.3 can't handle the safe_bool idiom, so don't use it
890  operator bool () const { return !this->empty(); }
891 #else
892  private:
893  struct dummy {
894  void nonnull() {}
895  };
896 
897  typedef void (dummy::*safe_bool)();
898 
899  public:
900  operator safe_bool () const
901  { return (this->empty())? 0 : &dummy::nonnull; }
902 
903  bool operator!() const
904  { return this->empty(); }
905 #endif
906 
907  private:
909  {
910  if (!f.empty()) {
911  this->vtable = f.vtable;
912  if (this->has_trivial_copy_and_destroy())
913  this->functor = f.functor;
914  else
915  get_vtable()->base.manager(f.functor, this->functor,
917  }
918  }
919 
920  template<typename Functor>
921  void assign_to(Functor f)
922  {
924 
927  typedef typename get_invoker::
928  template apply<Functor, R BOOST_FUNCTION_COMMA
930  handler_type;
931 
932  typedef typename handler_type::invoker_type invoker_type;
933  typedef typename handler_type::manager_type manager_type;
934 
935  // Note: it is extremely important that this initialization use
936  // static initialization. Otherwise, we will have a race
937  // condition here in multi-threaded code. See
938  // http://thread.gmane.org/gmane.comp.lib.boost.devel/164902/.
939  static const vtable_type stored_vtable =
940  { { &manager_type::manage }, &invoker_type::invoke };
941 
942  if (stored_vtable.assign_to(f, functor)) {
943  std::size_t value = reinterpret_cast<std::size_t>(&stored_vtable.base);
944  // coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
948  value |= static_cast<std::size_t>(0x01);
949  vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value);
950  } else
951  vtable = 0;
952  }
953 
954  template<typename Functor,typename Allocator>
955  void assign_to_a(Functor f,Allocator a)
956  {
958 
961  typedef typename get_invoker::
962  template apply_a<Functor, R BOOST_FUNCTION_COMMA
964  Allocator>
965  handler_type;
966 
967  typedef typename handler_type::invoker_type invoker_type;
968  typedef typename handler_type::manager_type manager_type;
969 
970  // Note: it is extremely important that this initialization use
971  // static initialization. Otherwise, we will have a race
972  // condition here in multi-threaded code. See
973  // http://thread.gmane.org/gmane.comp.lib.boost.devel/164902/.
974  static const vtable_type stored_vtable =
975  { { &manager_type::manage }, &invoker_type::invoke };
976 
977  if (stored_vtable.assign_to_a(f, functor, a)) {
978  std::size_t value = reinterpret_cast<std::size_t>(&stored_vtable.base);
979  // coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
983  value |= static_cast<std::size_t>(0x01);
984  vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value);
985  } else
986  vtable = 0;
987  }
988 
989  // Moves the value from the specified argument to *this. If the argument
990  // has its function object allocated on the heap, move_assign will pass
991  // its buffer to *this, and set the argument's buffer pointer to NULL.
993  {
994  if (&f == this)
995  return;
996 
997  BOOST_TRY {
998  if (!f.empty()) {
999  this->vtable = f.vtable;
1000  if (this->has_trivial_copy_and_destroy())
1001  this->functor = f.functor;
1002  else
1003  get_vtable()->base.manager(f.functor, this->functor,
1005  f.vtable = 0;
1006  } else {
1007  clear();
1008  }
1009  } BOOST_CATCH (...) {
1010  vtable = 0;
1011  BOOST_RETHROW;
1012  }
1014  }
1015  };
1016 
1017  template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
1021  >& f1,
1025  >& f2)
1026  {
1027  f1.swap(f2);
1028  }
1029 
1030 // Poison comparisons between boost::function objects of the same type.
1031 template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
1038 template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS>
1045 
1046 #if !defined(BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX)
1047 
1048 #if BOOST_FUNCTION_NUM_ARGS == 0
1049 #define BOOST_FUNCTION_PARTIAL_SPEC R (void)
1050 #else
1051 #define BOOST_FUNCTION_PARTIAL_SPEC R (BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS,T))
1052 #endif
1053 
1054 template<typename R BOOST_FUNCTION_COMMA
1057  : public BOOST_FUNCTION_FUNCTION<R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS>
1058 {
1060  typedef function self_type;
1061 
1062  struct clear_type {};
1063 
1064 public:
1065 
1066  function() : base_type() {}
1067 
1068  template<typename Functor>
1069  function(Functor f
1070 #ifndef BOOST_NO_SFINAE
1071  ,typename enable_if_c<
1074  int>::type = 0
1075 #endif
1076  ) :
1077  base_type(f)
1078  {
1079  }
1080  template<typename Functor,typename Allocator>
1081  function(Functor f, Allocator a
1082 #ifndef BOOST_NO_SFINAE
1083  ,typename enable_if_c<
1086  int>::type = 0
1087 #endif
1088  ) :
1089  base_type(f,a)
1090  {
1091  }
1092 
1093 #ifndef BOOST_NO_SFINAE
1094  function(clear_type*) : base_type() {}
1095 #endif
1096 
1097  function(const self_type& f) : base_type(static_cast<const base_type&>(f)){}
1098 
1099  function(const base_type& f) : base_type(static_cast<const base_type&>(f)){}
1100 
1101 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
1102  // Move constructors
1103  function(self_type&& f): base_type(static_cast<base_type&&>(f)){}
1104  function(base_type&& f): base_type(static_cast<base_type&&>(f)){}
1105 #endif
1106 
1107  self_type& operator=(const self_type& f)
1108  {
1109  self_type(f).swap(*this);
1110  return *this;
1111  }
1112 
1113 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
1114  self_type& operator=(self_type&& f)
1115  {
1116  self_type(static_cast<self_type&&>(f)).swap(*this);
1117  return *this;
1118  }
1119 #endif
1120 
1121  template<typename Functor>
1122 #ifndef BOOST_NO_SFINAE
1123  typename enable_if_c<
1126  self_type&>::type
1127 #else
1128  self_type&
1129 #endif
1130  operator=(Functor f)
1131  {
1132  self_type(f).swap(*this);
1133  return *this;
1134  }
1135 
1136 #ifndef BOOST_NO_SFINAE
1137  self_type& operator=(clear_type*)
1138  {
1139  this->clear();
1140  return *this;
1141  }
1142 #endif
1143 
1144  self_type& operator=(const base_type& f)
1145  {
1146  self_type(f).swap(*this);
1147  return *this;
1148  }
1149 
1150 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
1151  self_type& operator=(base_type&& f)
1152  {
1153  self_type(static_cast<base_type&&>(f)).swap(*this);
1154  return *this;
1155  }
1156 #endif
1157 };
1158 
1159 #undef BOOST_FUNCTION_PARTIAL_SPEC
1160 #endif // have partial specialization
1161 
1162 } // end namespace boost
1163 
1164 // Cleanup after ourselves...
1165 #undef BOOST_FUNCTION_VTABLE
1166 #undef BOOST_FUNCTION_COMMA
1167 #undef BOOST_FUNCTION_FUNCTION
1168 #undef BOOST_FUNCTION_FUNCTION_INVOKER
1169 #undef BOOST_FUNCTION_VOID_FUNCTION_INVOKER
1170 #undef BOOST_FUNCTION_FUNCTION_OBJ_INVOKER
1171 #undef BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER
1172 #undef BOOST_FUNCTION_FUNCTION_REF_INVOKER
1173 #undef BOOST_FUNCTION_VOID_FUNCTION_REF_INVOKER
1174 #undef BOOST_FUNCTION_MEMBER_INVOKER
1175 #undef BOOST_FUNCTION_VOID_MEMBER_INVOKER
1176 #undef BOOST_FUNCTION_GET_FUNCTION_INVOKER
1177 #undef BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER
1178 #undef BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER
1179 #undef BOOST_FUNCTION_GET_MEM_FUNCTION_INVOKER
1180 #undef BOOST_FUNCTION_GET_INVOKER
1181 #undef BOOST_FUNCTION_TEMPLATE_PARMS
1182 #undef BOOST_FUNCTION_TEMPLATE_ARGS
1183 #undef BOOST_FUNCTION_PARMS
1184 #undef BOOST_FUNCTION_PARM
1185 #ifdef BOOST_FUNCTION_ARG
1186 # undef BOOST_FUNCTION_ARG
1187 #endif
1188 #undef BOOST_FUNCTION_ARGS
1189 #undef BOOST_FUNCTION_ARG_TYPE
1190 #undef BOOST_FUNCTION_ARG_TYPES
1191 #undef BOOST_FUNCTION_VOID_RETURN_TYPE
1192 #undef BOOST_FUNCTION_RETURN
1193 
1194 #if defined(BOOST_MSVC)
1195 # pragma warning( pop )
1196 #endif
void assign_to_own(const BOOST_FUNCTION_FUNCTION &f)
bool assign_to_a(FunctionPtr f, function_buffer &functor, Allocator, function_ptr_tag) const
BOOST_FORCEINLINE T * addressof(T &v)
BOOST_FUNCTION_FUNCTION & operator=(const BOOST_FUNCTION_FUNCTION &f)
void assign(Functor BOOST_FUNCTION_TARGET_FIX(const &) f, Allocator a)
GLenum GLsizei const void * pointer
boost_foreach_argument_dependent_lookup_hack tag
Definition: foreach_fwd.hpp:31
bool_< true > true_
Definition: bool_fwd.hpp:21
bool assign_to_a(FunctionObj f, function_buffer &functor, Allocator a, function_obj_tag) const
enable_if_c< (boost::type_traits::ice_not< (is_integral< Functor >::value)>::value), BOOST_FUNCTION_FUNCTION & >::type operator=(Functor BOOST_FUNCTION_TARGET_FIX(const &) f)
typedef void(APIENTRY *GLDEBUGPROC)(GLenum source
#define BOOST_FUNCTION_TEMPLATE_ARGS
void assign_to_a(Functor f, Allocator a)
BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE.
#define BOOST_FUNCTION_VOID_RETURN_TYPE
mpl::if_c<(is_void< R >::value), BOOST_FUNCTION_VOID_FUNCTION_OBJ_INVOKER< FunctionObj, R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS >, BOOST_FUNCTION_FUNCTION_OBJ_INVOKER< FunctionObj, R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS > >::type type
bool assign_to_a(const reference_wrapper< FunctionObj > &f, function_buffer &functor, Allocator, function_obj_ref_tag) const
BOOST_FUNCTION_GET_FUNCTION_INVOKER< FunctionPtr, R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS >::type invoker_type
BOOST_FORCEINLINE T * get_pointer() const
Definition: core/ref.hpp:106
BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER< FunctionObj, R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS >::type invoker_type
static R invoke(function_buffer &function_obj_ptr BOOST_FUNCTION_COMMA BOOST_FUNCTION_PARMS)
bool has_empty_target(const function_base *f)
#define BOOST_FUNCTION_ARG_TYPES
#define BOOST_FUNCTION_RETURN(X)
GLfloat value
BOOST_FUNCTION_GET_FUNCTION_OBJ_INVOKER< FunctionObj, R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS >::type invoker_type
detail::function::vtable_base * vtable
BOOST_NORETURN void throw_exception(E const &e)
void swap(BOOST_FUNCTION_FUNCTION &other)
BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER< typename RefWrapper::type, R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS >::type invoker_type
#define BOOST_FUNCTION_TARGET_FIX(x)
static BOOST_FUNCTION_VOID_RETURN_TYPE invoke(function_buffer &function_ptr BOOST_FUNCTION_COMMA BOOST_FUNCTION_PARMS)
#define BOOST_FUNCTION_MEMBER_INVOKER
#define BOOST_FUNCTION_PARTIAL_SPEC
#define BOOST_FUNCTION_TEMPLATE_PARMS
bool assign_to(FunctionObj f, function_buffer &functor, function_obj_tag) const
bool operator!=(const function_base &f, detail::function::useless_clear_type *)
GLboolean GLboolean GLboolean GLboolean a
BOOST_FUNCTION_FUNCTION(Functor BOOST_FUNCTION_TARGET_FIX(const &) f, typename enable_if_c< (boost::type_traits::ice_not< (is_integral< Functor >::value)>::value), int >::type=0)
#define BOOST_FUNCTION_FUNCTION
GLdouble f
struct boost::detail::function::function_buffer::obj_ref_t obj_ref
BOOST_FUNCTION_FUNCTION(Functor BOOST_FUNCTION_TARGET_FIX(const &) f, Allocator a, typename enable_if_c< (boost::type_traits::ice_not< (is_integral< Functor >::value)>::value), int >::type=0)
mpl::if_c<(is_void< R >::value), BOOST_FUNCTION_VOID_FUNCTION_REF_INVOKER< FunctionObj, R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS >, BOOST_FUNCTION_FUNCTION_REF_INVOKER< FunctionObj, R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS > >::type type
mpl::if_c<(is_void< R >::value), BOOST_FUNCTION_VOID_FUNCTION_INVOKER< FunctionPtr, R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS >, BOOST_FUNCTION_FUNCTION_INVOKER< FunctionPtr, R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS > >::type type
vtable_type * get_vtable() const
BOOST_FUNCTION_FUNCTION< R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS > base_type
BOOST_FUNCTION_FUNCTION(const BOOST_FUNCTION_FUNCTION &f)
enable_if_c< (boost::type_traits::ice_not< (is_integral< Functor >::value)>::value), self_type & >::type operator=(Functor f)
#define BOOST_FUNCTION_COMMA
static BOOST_FUNCTION_VOID_RETURN_TYPE invoke(function_buffer &function_obj_ptr BOOST_FUNCTION_COMMA BOOST_FUNCTION_PARMS)
Contains a reference to an object of type T.
Definition: core/ref.hpp:59
bool_< false > false_
Definition: bool_fwd.hpp:25
#define BOOST_TRY
bool assign_to(F f, function_buffer &functor) const
const char * detail
BOOST_FUNCTION_GET_FUNCTION_INVOKER< FunctionPtr, R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS >::type invoker_type
static R invoke(function_buffer &function_ptr BOOST_FUNCTION_COMMA BOOST_FUNCTION_PARMS)
#define BOOST_FUNCTION_VOID_MEMBER_INVOKER
void assign_functor(FunctionObj f, function_buffer &functor, mpl::true_) const
void(* function_ptr)()
BOOST_GPU_ENABLED void swap(T1 &left, T2 &right)
Definition: core/swap.hpp:54
BOOST_FUNCTION_ARG_TYPES typedef BOOST_FUNCTION_FUNCTION self_type
GLenum type
BOOST_FUNCTION_FUNCTION & operator=(clear_type *)
#define BOOST_FUNCTION_GET_MEMBER_INVOKER
static R invoke(function_buffer &function_obj_ptr BOOST_FUNCTION_COMMA BOOST_FUNCTION_PARMS)
#define BOOST_FUNCTION_ARGS
#define BOOST_CATCH(x)
void assign_functor_a(FunctionObj f, function_buffer &functor, Allocator a, mpl::false_) const
#define BOOST_FUNCTION_PARMS
static BOOST_FUNCTION_VOID_RETURN_TYPE invoke(function_buffer &function_obj_ptr BOOST_FUNCTION_COMMA BOOST_FUNCTION_PARMS)
BOOST_FUNCTION_GET_FUNCTION_REF_INVOKER< typename RefWrapper::type, R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS >::type invoker_type
void assign_functor_a(FunctionObj f, function_buffer &functor, Allocator, mpl::true_) const
#define BOOST_ASSERT(expr)
Definition: assert.hpp:56
void assign_functor(FunctionObj f, function_buffer &functor, mpl::false_) const
bool assign_to(FunctionPtr f, function_buffer &functor, function_ptr_tag) const
bool assign_to_a(F f, function_buffer &functor, Allocator a) const
result_type operator()(BOOST_FUNCTION_PARMS) const
#define BOOST_STATIC_CONSTANT(type, assignment)
Definition: suffix.hpp:394
#define BOOST_CATCH_END
boost::detail::function::BOOST_FUNCTION_VTABLE< R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS > vtable_type
BOOST_FUNCTION_FUNCTION(BOOST_FUNCTION_FUNCTION &&f)
void move_assign(BOOST_FUNCTION_FUNCTION &f)
detail::function::function_buffer functor
BOOST_FUNCTION_FUNCTION & operator=(BOOST_FUNCTION_FUNCTION &&f)
#define BOOST_FUNCTION_NUM_ARGS
#define BOOST_RETHROW
bool assign_to(const reference_wrapper< FunctionObj > &f, function_buffer &functor, function_obj_ref_tag) const
bool operator==(const function_base &f, detail::function::useless_clear_type *)
void clear(function_buffer &functor) const
void copy(void *dst, void const *src, size_t size)
Definition: types.cpp:836


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:15