annotate DEPENDENCIES/generic/include/boost/function/function_template.hpp @ 133:4acb5d8d80b6 tip

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