Ticket #4720: djw_unsafe_function.patch
File djw_unsafe_function.patch, 36.4 KB (added by , 12 years ago) |
---|
-
boost/function/detail/gen_maybe_include.pl
29 29 print OUT " BOOST_FUNCTION_NUM_ARGS == $on_arg\n"; 30 30 print OUT "# ifndef BOOST_FUNCTION_$on_arg\n"; 31 31 print OUT "# define BOOST_FUNCTION_$on_arg\n"; 32 print OUT "# define BOOST_FUNCTION_BE_SAFE\n"; 32 33 print OUT "# include <boost/function/function_template.hpp>\n"; 34 print OUT "# undef BOOST_FUNCTION_BE_SAFE\n"; 35 print OUT "# include <boost/function/function_template.hpp>\n"; 33 36 print OUT "# endif\n"; 34 37 } 35 38 print OUT "#else\n"; -
boost/function/detail/maybe_include.hpp
10 10 #if BOOST_FUNCTION_NUM_ARGS == 0 11 11 # ifndef BOOST_FUNCTION_0 12 12 # define BOOST_FUNCTION_0 13 # define BOOST_FUNCTION_BE_SAFE 13 14 # include <boost/function/function_template.hpp> 15 # undef BOOST_FUNCTION_BE_SAFE 16 # include <boost/function/function_template.hpp> 14 17 # endif 15 18 #elif BOOST_FUNCTION_NUM_ARGS == 1 16 19 # ifndef BOOST_FUNCTION_1 17 20 # define BOOST_FUNCTION_1 21 # define BOOST_FUNCTION_BE_SAFE 18 22 # include <boost/function/function_template.hpp> 23 # undef BOOST_FUNCTION_BE_SAFE 24 # include <boost/function/function_template.hpp> 19 25 # endif 20 26 #elif BOOST_FUNCTION_NUM_ARGS == 2 21 27 # ifndef BOOST_FUNCTION_2 22 28 # define BOOST_FUNCTION_2 29 # define BOOST_FUNCTION_BE_SAFE 23 30 # include <boost/function/function_template.hpp> 31 # undef BOOST_FUNCTION_BE_SAFE 32 # include <boost/function/function_template.hpp> 24 33 # endif 25 34 #elif BOOST_FUNCTION_NUM_ARGS == 3 26 35 # ifndef BOOST_FUNCTION_3 27 36 # define BOOST_FUNCTION_3 37 # define BOOST_FUNCTION_BE_SAFE 28 38 # include <boost/function/function_template.hpp> 39 # undef BOOST_FUNCTION_BE_SAFE 40 # include <boost/function/function_template.hpp> 29 41 # endif 30 42 #elif BOOST_FUNCTION_NUM_ARGS == 4 31 43 # ifndef BOOST_FUNCTION_4 32 44 # define BOOST_FUNCTION_4 45 # define BOOST_FUNCTION_BE_SAFE 33 46 # include <boost/function/function_template.hpp> 47 # undef BOOST_FUNCTION_BE_SAFE 48 # include <boost/function/function_template.hpp> 34 49 # endif 35 50 #elif BOOST_FUNCTION_NUM_ARGS == 5 36 51 # ifndef BOOST_FUNCTION_5 37 52 # define BOOST_FUNCTION_5 53 # define BOOST_FUNCTION_BE_SAFE 38 54 # include <boost/function/function_template.hpp> 55 # undef BOOST_FUNCTION_BE_SAFE 56 # include <boost/function/function_template.hpp> 39 57 # endif 40 58 #elif BOOST_FUNCTION_NUM_ARGS == 6 41 59 # ifndef BOOST_FUNCTION_6 42 60 # define BOOST_FUNCTION_6 61 # define BOOST_FUNCTION_BE_SAFE 43 62 # include <boost/function/function_template.hpp> 63 # undef BOOST_FUNCTION_BE_SAFE 64 # include <boost/function/function_template.hpp> 44 65 # endif 45 66 #elif BOOST_FUNCTION_NUM_ARGS == 7 46 67 # ifndef BOOST_FUNCTION_7 47 68 # define BOOST_FUNCTION_7 69 # define BOOST_FUNCTION_BE_SAFE 48 70 # include <boost/function/function_template.hpp> 71 # undef BOOST_FUNCTION_BE_SAFE 72 # include <boost/function/function_template.hpp> 49 73 # endif 50 74 #elif BOOST_FUNCTION_NUM_ARGS == 8 51 75 # ifndef BOOST_FUNCTION_8 52 76 # define BOOST_FUNCTION_8 77 # define BOOST_FUNCTION_BE_SAFE 53 78 # include <boost/function/function_template.hpp> 79 # undef BOOST_FUNCTION_BE_SAFE 80 # include <boost/function/function_template.hpp> 54 81 # endif 55 82 #elif BOOST_FUNCTION_NUM_ARGS == 9 56 83 # ifndef BOOST_FUNCTION_9 57 84 # define BOOST_FUNCTION_9 85 # define BOOST_FUNCTION_BE_SAFE 58 86 # include <boost/function/function_template.hpp> 87 # undef BOOST_FUNCTION_BE_SAFE 88 # include <boost/function/function_template.hpp> 59 89 # endif 60 90 #elif BOOST_FUNCTION_NUM_ARGS == 10 61 91 # ifndef BOOST_FUNCTION_10 62 92 # define BOOST_FUNCTION_10 93 # define BOOST_FUNCTION_BE_SAFE 63 94 # include <boost/function/function_template.hpp> 95 # undef BOOST_FUNCTION_BE_SAFE 96 # include <boost/function/function_template.hpp> 64 97 # endif 65 98 #elif BOOST_FUNCTION_NUM_ARGS == 11 66 99 # ifndef BOOST_FUNCTION_11 67 100 # define BOOST_FUNCTION_11 101 # define BOOST_FUNCTION_BE_SAFE 68 102 # include <boost/function/function_template.hpp> 103 # undef BOOST_FUNCTION_BE_SAFE 104 # include <boost/function/function_template.hpp> 69 105 # endif 70 106 #elif BOOST_FUNCTION_NUM_ARGS == 12 71 107 # ifndef BOOST_FUNCTION_12 72 108 # define BOOST_FUNCTION_12 109 # define BOOST_FUNCTION_BE_SAFE 73 110 # include <boost/function/function_template.hpp> 111 # undef BOOST_FUNCTION_BE_SAFE 112 # include <boost/function/function_template.hpp> 74 113 # endif 75 114 #elif BOOST_FUNCTION_NUM_ARGS == 13 76 115 # ifndef BOOST_FUNCTION_13 77 116 # define BOOST_FUNCTION_13 117 # define BOOST_FUNCTION_BE_SAFE 78 118 # include <boost/function/function_template.hpp> 119 # undef BOOST_FUNCTION_BE_SAFE 120 # include <boost/function/function_template.hpp> 79 121 # endif 80 122 #elif BOOST_FUNCTION_NUM_ARGS == 14 81 123 # ifndef BOOST_FUNCTION_14 82 124 # define BOOST_FUNCTION_14 125 # define BOOST_FUNCTION_BE_SAFE 83 126 # include <boost/function/function_template.hpp> 127 # undef BOOST_FUNCTION_BE_SAFE 128 # include <boost/function/function_template.hpp> 84 129 # endif 85 130 #elif BOOST_FUNCTION_NUM_ARGS == 15 86 131 # ifndef BOOST_FUNCTION_15 87 132 # define BOOST_FUNCTION_15 133 # define BOOST_FUNCTION_BE_SAFE 88 134 # include <boost/function/function_template.hpp> 135 # undef BOOST_FUNCTION_BE_SAFE 136 # include <boost/function/function_template.hpp> 89 137 # endif 90 138 #elif BOOST_FUNCTION_NUM_ARGS == 16 91 139 # ifndef BOOST_FUNCTION_16 92 140 # define BOOST_FUNCTION_16 141 # define BOOST_FUNCTION_BE_SAFE 93 142 # include <boost/function/function_template.hpp> 143 # undef BOOST_FUNCTION_BE_SAFE 144 # include <boost/function/function_template.hpp> 94 145 # endif 95 146 #elif BOOST_FUNCTION_NUM_ARGS == 17 96 147 # ifndef BOOST_FUNCTION_17 97 148 # define BOOST_FUNCTION_17 149 # define BOOST_FUNCTION_BE_SAFE 98 150 # include <boost/function/function_template.hpp> 151 # undef BOOST_FUNCTION_BE_SAFE 152 # include <boost/function/function_template.hpp> 99 153 # endif 100 154 #elif BOOST_FUNCTION_NUM_ARGS == 18 101 155 # ifndef BOOST_FUNCTION_18 102 156 # define BOOST_FUNCTION_18 157 # define BOOST_FUNCTION_BE_SAFE 103 158 # include <boost/function/function_template.hpp> 159 # undef BOOST_FUNCTION_BE_SAFE 160 # include <boost/function/function_template.hpp> 104 161 # endif 105 162 #elif BOOST_FUNCTION_NUM_ARGS == 19 106 163 # ifndef BOOST_FUNCTION_19 107 164 # define BOOST_FUNCTION_19 165 # define BOOST_FUNCTION_BE_SAFE 108 166 # include <boost/function/function_template.hpp> 167 # undef BOOST_FUNCTION_BE_SAFE 168 # include <boost/function/function_template.hpp> 109 169 # endif 110 170 #elif BOOST_FUNCTION_NUM_ARGS == 20 111 171 # ifndef BOOST_FUNCTION_20 112 172 # define BOOST_FUNCTION_20 173 # define BOOST_FUNCTION_BE_SAFE 113 174 # include <boost/function/function_template.hpp> 175 # undef BOOST_FUNCTION_BE_SAFE 176 # include <boost/function/function_template.hpp> 114 177 # endif 115 178 #elif BOOST_FUNCTION_NUM_ARGS == 21 116 179 # ifndef BOOST_FUNCTION_21 117 180 # define BOOST_FUNCTION_21 181 # define BOOST_FUNCTION_BE_SAFE 118 182 # include <boost/function/function_template.hpp> 183 # undef BOOST_FUNCTION_BE_SAFE 184 # include <boost/function/function_template.hpp> 119 185 # endif 120 186 #elif BOOST_FUNCTION_NUM_ARGS == 22 121 187 # ifndef BOOST_FUNCTION_22 122 188 # define BOOST_FUNCTION_22 189 # define BOOST_FUNCTION_BE_SAFE 123 190 # include <boost/function/function_template.hpp> 191 # undef BOOST_FUNCTION_BE_SAFE 192 # include <boost/function/function_template.hpp> 124 193 # endif 125 194 #elif BOOST_FUNCTION_NUM_ARGS == 23 126 195 # ifndef BOOST_FUNCTION_23 127 196 # define BOOST_FUNCTION_23 197 # define BOOST_FUNCTION_BE_SAFE 128 198 # include <boost/function/function_template.hpp> 199 # undef BOOST_FUNCTION_BE_SAFE 200 # include <boost/function/function_template.hpp> 129 201 # endif 130 202 #elif BOOST_FUNCTION_NUM_ARGS == 24 131 203 # ifndef BOOST_FUNCTION_24 132 204 # define BOOST_FUNCTION_24 205 # define BOOST_FUNCTION_BE_SAFE 133 206 # include <boost/function/function_template.hpp> 207 # undef BOOST_FUNCTION_BE_SAFE 208 # include <boost/function/function_template.hpp> 134 209 # endif 135 210 #elif BOOST_FUNCTION_NUM_ARGS == 25 136 211 # ifndef BOOST_FUNCTION_25 137 212 # define BOOST_FUNCTION_25 213 # define BOOST_FUNCTION_BE_SAFE 138 214 # include <boost/function/function_template.hpp> 215 # undef BOOST_FUNCTION_BE_SAFE 216 # include <boost/function/function_template.hpp> 139 217 # endif 140 218 #elif BOOST_FUNCTION_NUM_ARGS == 26 141 219 # ifndef BOOST_FUNCTION_26 142 220 # define BOOST_FUNCTION_26 221 # define BOOST_FUNCTION_BE_SAFE 143 222 # include <boost/function/function_template.hpp> 223 # undef BOOST_FUNCTION_BE_SAFE 224 # include <boost/function/function_template.hpp> 144 225 # endif 145 226 #elif BOOST_FUNCTION_NUM_ARGS == 27 146 227 # ifndef BOOST_FUNCTION_27 147 228 # define BOOST_FUNCTION_27 229 # define BOOST_FUNCTION_BE_SAFE 148 230 # include <boost/function/function_template.hpp> 231 # undef BOOST_FUNCTION_BE_SAFE 232 # include <boost/function/function_template.hpp> 149 233 # endif 150 234 #elif BOOST_FUNCTION_NUM_ARGS == 28 151 235 # ifndef BOOST_FUNCTION_28 152 236 # define BOOST_FUNCTION_28 237 # define BOOST_FUNCTION_BE_SAFE 153 238 # include <boost/function/function_template.hpp> 239 # undef BOOST_FUNCTION_BE_SAFE 240 # include <boost/function/function_template.hpp> 154 241 # endif 155 242 #elif BOOST_FUNCTION_NUM_ARGS == 29 156 243 # ifndef BOOST_FUNCTION_29 157 244 # define BOOST_FUNCTION_29 245 # define BOOST_FUNCTION_BE_SAFE 158 246 # include <boost/function/function_template.hpp> 247 # undef BOOST_FUNCTION_BE_SAFE 248 # include <boost/function/function_template.hpp> 159 249 # endif 160 250 #elif BOOST_FUNCTION_NUM_ARGS == 30 161 251 # ifndef BOOST_FUNCTION_30 162 252 # define BOOST_FUNCTION_30 253 # define BOOST_FUNCTION_BE_SAFE 163 254 # include <boost/function/function_template.hpp> 255 # undef BOOST_FUNCTION_BE_SAFE 256 # include <boost/function/function_template.hpp> 164 257 # endif 165 258 #elif BOOST_FUNCTION_NUM_ARGS == 31 166 259 # ifndef BOOST_FUNCTION_31 167 260 # define BOOST_FUNCTION_31 261 # define BOOST_FUNCTION_BE_SAFE 168 262 # include <boost/function/function_template.hpp> 263 # undef BOOST_FUNCTION_BE_SAFE 264 # include <boost/function/function_template.hpp> 169 265 # endif 170 266 #elif BOOST_FUNCTION_NUM_ARGS == 32 171 267 # ifndef BOOST_FUNCTION_32 172 268 # define BOOST_FUNCTION_32 269 # define BOOST_FUNCTION_BE_SAFE 173 270 # include <boost/function/function_template.hpp> 271 # undef BOOST_FUNCTION_BE_SAFE 272 # include <boost/function/function_template.hpp> 174 273 # endif 175 274 #elif BOOST_FUNCTION_NUM_ARGS == 33 176 275 # ifndef BOOST_FUNCTION_33 177 276 # define BOOST_FUNCTION_33 277 # define BOOST_FUNCTION_BE_SAFE 178 278 # include <boost/function/function_template.hpp> 279 # undef BOOST_FUNCTION_BE_SAFE 280 # include <boost/function/function_template.hpp> 179 281 # endif 180 282 #elif BOOST_FUNCTION_NUM_ARGS == 34 181 283 # ifndef BOOST_FUNCTION_34 182 284 # define BOOST_FUNCTION_34 285 # define BOOST_FUNCTION_BE_SAFE 183 286 # include <boost/function/function_template.hpp> 287 # undef BOOST_FUNCTION_BE_SAFE 288 # include <boost/function/function_template.hpp> 184 289 # endif 185 290 #elif BOOST_FUNCTION_NUM_ARGS == 35 186 291 # ifndef BOOST_FUNCTION_35 187 292 # define BOOST_FUNCTION_35 293 # define BOOST_FUNCTION_BE_SAFE 188 294 # include <boost/function/function_template.hpp> 295 # undef BOOST_FUNCTION_BE_SAFE 296 # include <boost/function/function_template.hpp> 189 297 # endif 190 298 #elif BOOST_FUNCTION_NUM_ARGS == 36 191 299 # ifndef BOOST_FUNCTION_36 192 300 # define BOOST_FUNCTION_36 301 # define BOOST_FUNCTION_BE_SAFE 193 302 # include <boost/function/function_template.hpp> 303 # undef BOOST_FUNCTION_BE_SAFE 304 # include <boost/function/function_template.hpp> 194 305 # endif 195 306 #elif BOOST_FUNCTION_NUM_ARGS == 37 196 307 # ifndef BOOST_FUNCTION_37 197 308 # define BOOST_FUNCTION_37 309 # define BOOST_FUNCTION_BE_SAFE 198 310 # include <boost/function/function_template.hpp> 311 # undef BOOST_FUNCTION_BE_SAFE 312 # include <boost/function/function_template.hpp> 199 313 # endif 200 314 #elif BOOST_FUNCTION_NUM_ARGS == 38 201 315 # ifndef BOOST_FUNCTION_38 202 316 # define BOOST_FUNCTION_38 317 # define BOOST_FUNCTION_BE_SAFE 203 318 # include <boost/function/function_template.hpp> 319 # undef BOOST_FUNCTION_BE_SAFE 320 # include <boost/function/function_template.hpp> 204 321 # endif 205 322 #elif BOOST_FUNCTION_NUM_ARGS == 39 206 323 # ifndef BOOST_FUNCTION_39 207 324 # define BOOST_FUNCTION_39 325 # define BOOST_FUNCTION_BE_SAFE 208 326 # include <boost/function/function_template.hpp> 327 # undef BOOST_FUNCTION_BE_SAFE 328 # include <boost/function/function_template.hpp> 209 329 # endif 210 330 #elif BOOST_FUNCTION_NUM_ARGS == 40 211 331 # ifndef BOOST_FUNCTION_40 212 332 # define BOOST_FUNCTION_40 333 # define BOOST_FUNCTION_BE_SAFE 213 334 # include <boost/function/function_template.hpp> 335 # undef BOOST_FUNCTION_BE_SAFE 336 # include <boost/function/function_template.hpp> 214 337 # endif 215 338 #elif BOOST_FUNCTION_NUM_ARGS == 41 216 339 # ifndef BOOST_FUNCTION_41 217 340 # define BOOST_FUNCTION_41 341 # define BOOST_FUNCTION_BE_SAFE 218 342 # include <boost/function/function_template.hpp> 343 # undef BOOST_FUNCTION_BE_SAFE 344 # include <boost/function/function_template.hpp> 219 345 # endif 220 346 #elif BOOST_FUNCTION_NUM_ARGS == 42 221 347 # ifndef BOOST_FUNCTION_42 222 348 # define BOOST_FUNCTION_42 349 # define BOOST_FUNCTION_BE_SAFE 223 350 # include <boost/function/function_template.hpp> 351 # undef BOOST_FUNCTION_BE_SAFE 352 # include <boost/function/function_template.hpp> 224 353 # endif 225 354 #elif BOOST_FUNCTION_NUM_ARGS == 43 226 355 # ifndef BOOST_FUNCTION_43 227 356 # define BOOST_FUNCTION_43 357 # define BOOST_FUNCTION_BE_SAFE 228 358 # include <boost/function/function_template.hpp> 359 # undef BOOST_FUNCTION_BE_SAFE 360 # include <boost/function/function_template.hpp> 229 361 # endif 230 362 #elif BOOST_FUNCTION_NUM_ARGS == 44 231 363 # ifndef BOOST_FUNCTION_44 232 364 # define BOOST_FUNCTION_44 365 # define BOOST_FUNCTION_BE_SAFE 233 366 # include <boost/function/function_template.hpp> 367 # undef BOOST_FUNCTION_BE_SAFE 368 # include <boost/function/function_template.hpp> 234 369 # endif 235 370 #elif BOOST_FUNCTION_NUM_ARGS == 45 236 371 # ifndef BOOST_FUNCTION_45 237 372 # define BOOST_FUNCTION_45 373 # define BOOST_FUNCTION_BE_SAFE 238 374 # include <boost/function/function_template.hpp> 375 # undef BOOST_FUNCTION_BE_SAFE 376 # include <boost/function/function_template.hpp> 239 377 # endif 240 378 #elif BOOST_FUNCTION_NUM_ARGS == 46 241 379 # ifndef BOOST_FUNCTION_46 242 380 # define BOOST_FUNCTION_46 381 # define BOOST_FUNCTION_BE_SAFE 243 382 # include <boost/function/function_template.hpp> 383 # undef BOOST_FUNCTION_BE_SAFE 384 # include <boost/function/function_template.hpp> 244 385 # endif 245 386 #elif BOOST_FUNCTION_NUM_ARGS == 47 246 387 # ifndef BOOST_FUNCTION_47 247 388 # define BOOST_FUNCTION_47 389 # define BOOST_FUNCTION_BE_SAFE 248 390 # include <boost/function/function_template.hpp> 391 # undef BOOST_FUNCTION_BE_SAFE 392 # include <boost/function/function_template.hpp> 249 393 # endif 250 394 #elif BOOST_FUNCTION_NUM_ARGS == 48 251 395 # ifndef BOOST_FUNCTION_48 252 396 # define BOOST_FUNCTION_48 397 # define BOOST_FUNCTION_BE_SAFE 253 398 # include <boost/function/function_template.hpp> 399 # undef BOOST_FUNCTION_BE_SAFE 400 # include <boost/function/function_template.hpp> 254 401 # endif 255 402 #elif BOOST_FUNCTION_NUM_ARGS == 49 256 403 # ifndef BOOST_FUNCTION_49 257 404 # define BOOST_FUNCTION_49 405 # define BOOST_FUNCTION_BE_SAFE 258 406 # include <boost/function/function_template.hpp> 407 # undef BOOST_FUNCTION_BE_SAFE 408 # include <boost/function/function_template.hpp> 259 409 # endif 260 410 #elif BOOST_FUNCTION_NUM_ARGS == 50 261 411 # ifndef BOOST_FUNCTION_50 262 412 # define BOOST_FUNCTION_50 413 # define BOOST_FUNCTION_BE_SAFE 263 414 # include <boost/function/function_template.hpp> 415 # undef BOOST_FUNCTION_BE_SAFE 416 # include <boost/function/function_template.hpp> 264 417 # endif 265 418 #else 266 419 # error Cannot handle Boost.Function objects that accept more than 50 arguments! -
boost/function/function_template.hpp
41 41 #endif // BOOST_FUNCTION_NUM_ARGS > 0 42 42 43 43 // Class names used in this version of the code 44 #define BOOST_FUNCTION_FUNCTION BOOST_JOIN(function,BOOST_FUNCTION_NUM_ARGS) 44 #define BOOST_FUNCTION_SAFE_WRAPPER function 45 #define BOOST_FUNCTION_UNSAFE_WRAPPER unsafe_function 46 #define BOOST_FUNCTION_SAFE_FUNCTION BOOST_JOIN(BOOST_FUNCTION_SAFE_WRAPPER,BOOST_FUNCTION_NUM_ARGS) 47 #define BOOST_FUNCTION_UNSAFE_FUNCTION BOOST_JOIN(BOOST_FUNCTION_UNSAFE_WRAPPER,BOOST_FUNCTION_NUM_ARGS) 48 #if defined(BOOST_FUNCTION_BE_SAFE) 49 # define BOOST_FUNCTION_WRAPPER BOOST_FUNCTION_SAFE_WRAPPER 50 #else 51 # define BOOST_FUNCTION_WRAPPER BOOST_FUNCTION_UNSAFE_WRAPPER 52 #endif 53 #define BOOST_FUNCTION_FUNCTION BOOST_JOIN(BOOST_FUNCTION_WRAPPER,BOOST_FUNCTION_NUM_ARGS) 45 54 #define BOOST_FUNCTION_FUNCTION_INVOKER \ 46 55 BOOST_JOIN(function_invoker,BOOST_FUNCTION_NUM_ARGS) 47 56 #define BOOST_FUNCTION_VOID_FUNCTION_INVOKER \ … … 79 88 #endif 80 89 81 90 namespace boost { 91 #if defined(BOOST_FUNCTION_BE_SAFE) 82 92 namespace detail { 83 93 namespace function { 84 94 template< … … 645 655 } // end namespace function 646 656 } // end namespace detail 647 657 658 template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS> 659 class BOOST_FUNCTION_UNSAFE_FUNCTION; 660 #endif // BOOST_FUNCTION_BE_SAFE 661 648 662 template< 649 663 typename R BOOST_FUNCTION_COMMA 650 664 BOOST_FUNCTION_TEMPLATE_PARMS … … 749 763 this->assign_to_own(f); 750 764 } 751 765 766 BOOST_FUNCTION_FUNCTION( 767 #if defined(BOOST_FUNCTION_BE_SAFE) 768 const BOOST_FUNCTION_UNSAFE_FUNCTION<R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS>& f 769 #else 770 const BOOST_FUNCTION_SAFE_FUNCTION<R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS>& f 771 #endif 772 ) : function_base() 773 { 774 this->assign_to_own(f); 775 } 776 752 777 ~BOOST_FUNCTION_FUNCTION() { clear(); } 753 778 754 779 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) … … 756 781 // these definitions can become very costly. 757 782 result_type operator()(BOOST_FUNCTION_PARMS) const 758 783 { 784 #if defined(BOOST_FUNCTION_BE_SAFE) 759 785 if (this->empty()) 760 786 boost::throw_exception(bad_function_call()); 787 #endif 761 788 762 789 return get_vtable()->invoker 763 790 (this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS); … … 878 905 #endif 879 906 880 907 private: 881 void assign_to_own(const BOOST_FUNCTION_FUNCTION& f)908 void assign_to_own(const function_base& f) 882 909 { 883 910 if (!f.empty()) { 884 911 this->vtable = f.vtable; … … 1006 1033 BOOST_FUNCTION_FUNCTION<R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS> 1007 1034 ::operator()(BOOST_FUNCTION_PARMS) const 1008 1035 { 1036 #if defined(BOOST_FUNCTION_BE_SAFE) 1009 1037 if (this->empty()) 1010 1038 boost::throw_exception(bad_function_call()); 1039 #endif 1011 1040 1012 1041 return get_vtable()->invoker 1013 1042 (this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS); … … 1040 1069 1041 1070 template<typename R BOOST_FUNCTION_COMMA 1042 1071 BOOST_FUNCTION_TEMPLATE_PARMS> 1043 class function<BOOST_FUNCTION_PARTIAL_SPEC>1072 class BOOST_FUNCTION_WRAPPER<BOOST_FUNCTION_PARTIAL_SPEC> 1044 1073 : public BOOST_FUNCTION_FUNCTION<R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS> 1045 1074 { 1046 1075 typedef BOOST_FUNCTION_FUNCTION<R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS> base_type; 1047 typedef functionself_type;1076 typedef BOOST_FUNCTION_WRAPPER self_type; 1048 1077 1049 1078 struct clear_type {}; 1050 1079 1051 1080 public: 1052 1081 1053 function() : base_type() {}1082 BOOST_FUNCTION_WRAPPER() : base_type() {} 1054 1083 1055 1084 template<typename Functor> 1056 function(Functor f1085 BOOST_FUNCTION_WRAPPER(Functor f 1057 1086 #ifndef BOOST_NO_SFINAE 1058 1087 ,typename enable_if_c< 1059 1088 (boost::type_traits::ice_not< … … 1065 1094 { 1066 1095 } 1067 1096 template<typename Functor,typename Allocator> 1068 function(Functor f, Allocator a1097 BOOST_FUNCTION_WRAPPER(Functor f, Allocator a 1069 1098 #ifndef BOOST_NO_SFINAE 1070 1099 ,typename enable_if_c< 1071 1100 (boost::type_traits::ice_not< … … 1078 1107 } 1079 1108 1080 1109 #ifndef BOOST_NO_SFINAE 1081 function(clear_type*) : base_type() {}1110 BOOST_FUNCTION_WRAPPER(clear_type*) : base_type() {} 1082 1111 #endif 1083 1112 1084 function(const self_type& f) : base_type(static_cast<const base_type&>(f)){}1113 BOOST_FUNCTION_WRAPPER(const self_type& f) : base_type(static_cast<const base_type&>(f)){} 1085 1114 1086 function(const base_type& f) : base_type(static_cast<const base_type&>(f)){}1115 BOOST_FUNCTION_WRAPPER(const base_type& f) : base_type(static_cast<const base_type&>(f)){} 1087 1116 1117 #if defined(BOOST_FUNCTION_BE_SAFE) 1118 BOOST_FUNCTION_WRAPPER(const BOOST_FUNCTION_UNSAFE_WRAPPER<BOOST_FUNCTION_PARTIAL_SPEC>& f) 1119 : base_type( 1120 static_cast< 1121 const BOOST_FUNCTION_UNSAFE_FUNCTION<R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS>& 1122 >(f) 1123 ) {} 1124 #else 1125 BOOST_FUNCTION_WRAPPER(const BOOST_FUNCTION_SAFE_WRAPPER<BOOST_FUNCTION_PARTIAL_SPEC>& f) 1126 : base_type( 1127 static_cast< 1128 const BOOST_FUNCTION_SAFE_FUNCTION<R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS>& 1129 >(f) 1130 ) {} 1131 #endif 1132 1088 1133 self_type& operator=(const self_type& f) 1089 1134 { 1090 1135 self_type(f).swap(*this); … … 1119 1164 self_type(f).swap(*this); 1120 1165 return *this; 1121 1166 } 1167 1168 #if defined(BOOST_FUNCTION_BE_SAFE) 1169 self_type& operator=(const BOOST_FUNCTION_UNSAFE_WRAPPER<BOOST_FUNCTION_PARTIAL_SPEC>& f) 1170 #else 1171 self_type& operator=(const BOOST_FUNCTION_SAFE_WRAPPER<BOOST_FUNCTION_PARTIAL_SPEC>& f) 1172 #endif 1173 { 1174 self_type(f).swap(*this); 1175 return *this; 1176 } 1122 1177 }; 1123 1178 1124 1179 #undef BOOST_FUNCTION_PARTIAL_SPEC … … 1127 1182 } // end namespace boost 1128 1183 1129 1184 // Cleanup after ourselves... 1185 #undef BOOST_FUNCTION_SAFE_WRAPPER 1186 #undef BOOST_FUNCTION_UNSAFE_WRAPPER 1187 #undef BOOST_FUNCTION_SAFE_FUNCTION 1188 #undef BOOST_FUNCTION_UNSAFE_FUNCTION 1189 #undef BOOST_FUNCTION_WRAPPER 1130 1190 #undef BOOST_FUNCTION_VTABLE 1131 1191 #undef BOOST_FUNCTION_COMMA 1132 1192 #undef BOOST_FUNCTION_FUNCTION -
boost/function/function_fwd.hpp
37 37 { 38 38 f1.swap(f2); 39 39 } 40 41 template<typename Signature> class unsafe_function; 42 43 template<typename Signature> 44 inline void swap(unsafe_function<Signature>& f1, unsafe_function<Signature>& f2) 45 { 46 f1.swap(f2); 47 } 48 49 template<typename Signature> 50 inline void swap(unsafe_function<Signature>& f1, function<Signature>& f2) 51 { 52 unsafe_function<Signature> tmp = f1; 53 f1 = f2; 54 f2 = tmp; 55 } 56 57 template<typename Signature> 58 inline void swap(function<Signature>& f1, unsafe_function<Signature>& f2) 59 { 60 swap(f2, f1); 61 } 40 62 #endif // have partial specialization 41 63 42 64 // Portable syntax -
libs/function/test/Jamfile.v2
62 62 [ run libs/function/test/nothrow_swap.cpp : : : : ] 63 63 64 64 [ compile libs/function/test/function_typeof_test.cpp ] 65 66 [ run libs/function/test/unsafe_function_cxx98.cpp : : : : ] 67 68 [ run libs/function/test/no_exceptions.cpp : : : : ] 65 69 ; 66 70 } 67 71 -
libs/function/test/no_exceptions.cpp
1 // Boost.Function library 2 // 3 // Copyright Daniel Walker 2010. Use, modification and distribution 4 // are subject to the Boost Software License, Version 1.0. (See 5 // accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 // 8 // For more information, see http://www.boost.org/libs/function 9 // 10 11 // Briefly check that boost::unsafe_function works out-of-the-box 12 // when Boost exceptions are not available. 13 14 #include <cassert> 15 16 #define BOOST_NO_EXCEPTIONS 17 #include <boost/function.hpp> 18 19 int f(int x) { return x; } 20 21 int main(int, char*[]) 22 { 23 boost::unsafe_function1<int, int> g = &f; 24 assert(g); 25 assert(g == &f); 26 assert(f(0xABCD) == 0xABCD); 27 assert(g(0xABCD) == 0xABCD); 28 return 0; 29 } -
libs/function/test/unsafe_function_cxx98.cpp
1 // Boost.Function library 2 // 3 // Copyright Daniel Walker 2010. Use, modification and distribution 4 // are subject to the Boost Software License, Version 1.0. (See 5 // accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 // 8 // For more information, see http://www.boost.org/libs/function 9 // 10 11 // Since the same preprocessor boilerplate is used to generate both 12 // boost::function and boost::unsafe_function, the API tests are 13 // performed on boost::function and are not duplicated for 14 // boost::unsafe_function. The only new methods specific to 15 // boost::unsafe_function are swap, construction and assignment 16 // with boost::function, which are tested below. 17 18 #include <boost/test/minimal.hpp> 19 20 #include <boost/function.hpp> 21 #include <boost/timer.hpp> 22 23 int f(int x) { return x; } 24 25 int test_main(int, char*[]) 26 { 27 // Sanity check: construction, assignment, comparison and 28 // call-operator. 29 { 30 boost::unsafe_function<int(int)> g(&f); 31 BOOST_REQUIRE(g); 32 BOOST_REQUIRE(g == &f); 33 boost::unsafe_function<int(int)> h; 34 BOOST_REQUIRE(!h); 35 h = &f; 36 BOOST_REQUIRE(h); 37 BOOST_REQUIRE(h == &f); 38 BOOST_REQUIRE(f(0xABCD) == 0xABCD); 39 BOOST_REQUIRE(h(0xABCD) == 0xABCD); 40 } 41 42 // Swap. 43 { 44 boost::unsafe_function<int(int)> g, h(&f); 45 boost::swap(g, h); 46 BOOST_REQUIRE(!h); 47 BOOST_REQUIRE(g); 48 BOOST_REQUIRE(g == &f); 49 } 50 51 // Construction from boost::function. 52 { 53 boost::function<int(int)> g = &f; 54 boost::unsafe_function<int(int)> h(g); 55 BOOST_REQUIRE(h == &f); 56 } 57 58 // Assignment from boost::function. 59 { 60 boost::function<int(int)> g = &f; 61 boost::unsafe_function<int(int)> h; 62 h = g; 63 BOOST_REQUIRE(h == &f); 64 } 65 66 // Construction from boost::unsafe_function. 67 { 68 boost::unsafe_function<int(int)> g = &f; 69 boost::function<int(int)> h(g); 70 BOOST_REQUIRE(h == &f); 71 } 72 73 // Assignment from boost::unsafe_function. 74 { 75 boost::unsafe_function<int(int)> g = &f; 76 boost::function<int(int)> h; 77 h = g; 78 BOOST_REQUIRE(h == &f); 79 } 80 81 // Swap with boost::function. 82 { 83 boost::function<int(int)> g; 84 boost::unsafe_function<int(int)> h(&f); 85 boost::swap(g, h); 86 BOOST_REQUIRE(!h); 87 BOOST_REQUIRE(g == &f); 88 boost::swap(h, g); 89 BOOST_REQUIRE(!g); 90 BOOST_REQUIRE(h == &f); 91 } 92 93 // In unoptimized object code, boost::unsafe_function should have 94 // less runtime cost than boost::function. 95 #ifndef NDEBUG 96 { 97 int n = INT_MAX/4; 98 boost::function<int(int)> g = &f; 99 boost::timer t; 100 for(int i = 0; i < n; ++i) 101 g(i); 102 const double function_cost = t.elapsed(); 103 104 boost::unsafe_function<int(int)> h = g; 105 t.restart(); 106 for(int i = 0; i < n; ++i) 107 h(i); 108 const double unsafe_function_cost = t.elapsed(); 109 BOOST_CHECK(unsafe_function_cost <= function_cost*1.1); 110 } 111 #endif 112 return 0; 113 } -
libs/function/doc/tutorial.xml
159 159 160 160 <para> Invoking a function object wrapper that does not actually 161 161 contain a function object is a precondition violation, much like 162 trying to call through a null function pointer, and will throw a <classname>bad_function_call</classname> exception). We can check for an 162 trying to call through a null function 163 pointer. <classname>boost::function</classname> will throw 164 a <classname>bad_function_call</classname> exception when invoked 165 with no target. 166 Alternatively, <classname alt="function">boost::unsafe_function</classname> 167 has no exception safety guarantee and puts the onus on the user to 168 check if it is empty prior to attempting a call. We can check for an 163 169 empty function object wrapper by using it in a boolean context (it evaluates <computeroutput>true</computeroutput> if the wrapper is not empty) or compare it against <computeroutput>0</computeroutput>. For instance: 164 170 <programlisting name="function.tutorial.check_empty">if (f) 165 171 std::cout << f(5, 3) << std::endl; … … 360 366 361 367 </section> 362 368 369 <section> 370 <title>Boost.Function exception safety</title> 371 <para>Boost.Function provides function object wrappers with two 372 levels of exception safety. A strong exception safety guarantee is 373 provided by <classname>boost::function</classname>, which will 374 either call the target function or 375 throw <classname>bad_function_call</classname> if it has no 376 target. <classname>boost::function</classname> 377 uses <functionname>boost::throw_exception</functionname> and can be 378 further configured via the 379 Boost <libraryname>Exception</libraryname> Library.</para> 380 381 <para>In circumstances where no exception safety guarantee is 382 desirable, such as some embedded 383 systems, <classname alt="function">boost::unsafe_function</classname> 384 may be used as a direct substitute 385 for <classname>boost::function</classname>, with the caveat that the 386 behavior 387 of <classname alt="function">boost::unsafe_function</classname> is 388 undefined when invoked with no target. For example, the following 389 demonstrates how to 390 handle <classname>boost::function</classname> 391 and <classname alt="function">boost::unsafe_function</classname> 392 when their preconditions are violated: 393 <informaltable> 394 <tgroup cols="2" align="left"> 395 <thead> 396 <row> 397 <entry>Preferred syntax</entry> 398 <entry>Portable syntax</entry> 399 </row> 400 </thead> 401 <tbody> 402 <row> 403 <entry> 404 <programlisting name="function.tutorial.unsafe.cxx98"><classname>boost::function</classname><void ()> f; 405 <classname alt="function">boost::unsafe_function</classname><void ()> g;</programlisting> 406 </entry> 407 <entry> 408 <programlisting name="function.tutorial.unsafe.portable"><classname alt="functionN">boost::function0</classname><void> f; 409 <classname alt="functionN">boost::unsafe_function0</classname><void> g;</programlisting> 410 </entry> 411 </row> 412 </tbody> 413 </tgroup> 414 </informaltable> 415 <programlisting name="function.tutorial.unsafe">try { 416 f(); // throws bad_function_call 417 } 418 catch(boost::bad_function_call e) { 419 std::cerr << e.what() << std::endl; 420 } 421 422 if(g) 423 g(); // undefined behavior 424 else 425 std::cerr << "boost::unsafe_function is empty" << std::endl;</programlisting></para> 426 427 <para>More information about exception safety guarantees in C++ may 428 be found <ulink url="http://www.boost.org/community/exception_safety.html">here</ulink>.</para> 363 429 </section> 364 430 431 </section> 432 -
libs/function/doc/faq.xml
153 153 standard function pointer, differences of order of 10% have been 154 154 noted to the benefit or disadvantage of using 155 155 <code>boost::function</code> to call a function that contains a 156 tight loop depending on your compilation circumstances. </para>156 tight loop depending on your compilation circumstances.*</para> 157 157 158 <para>[Answer provided by Matt Hurd. See <ulink url="http://article.gmane.org/gmane.comp.lib.boost.devel/33278"/>]</para> 158 <para>The difference in overhead 159 between <code>boost::unsafe_function</code> 160 and <code>boost::function</code> will vary according to the 161 optimization strategy of your compiler. For example, their 162 performance is almost the same (within a few hundred 163 picoseconds) using MSVC Release mode or <code>gcc 164 -O2</code>.</para> 165 166 <para>[*Answer provided by Matt Hurd. See <ulink url="http://article.gmane.org/gmane.comp.lib.boost.devel/33278"/>]</para> 159 167 </answer> 160 168 </qandaentry> 161 169 </qandaset> -
libs/function/doc/reference.xml
153 153 alt="functionN">function0</classname>, <classname 154 154 alt="functionN">function1</classname>, etc., up to some 155 155 implementation-defined maximum. In this context, <code>N</code> 156 refers to the number of parameters.</para> 156 refers to the number of parameters. The corresponding class 157 template <classname alt="functionN">unsafe_fuctionN</classname> 158 has no exception safety guarantee when invoked with no 159 target.</para> 157 160 </description> 158 161 159 162 <typedef name="result_type"><type>R</type></typedef> … … 322 325 <parameter name="aN"><paramtype>argN_type</paramtype></parameter> 323 326 <effects><simpara><code>f(a1, a2, ..., aN)</code>, where <code>f</code> is the target of <code>*this</code>.</simpara></effects> 324 327 <returns><simpara>if <code>R</code> is <code>void</code>, nothing is returned; otherwise, the return value of the call to <code>f</code> is returned.</simpara></returns> 325 <throws><simpara><code><classname>bad_function_call</classname></code> if <code>this-><methodname>empty</methodname>()</code>. Otherwise, may through any exception thrown by the target function <code>f</code>. </simpara></throws>328 <throws><simpara><code><classname>bad_function_call</classname></code> if <code>this-><methodname>empty</methodname>()</code>. Otherwise, may through any exception thrown by the target function <code>f</code>. The behavior of <classname alt="functionN">unsafe_functionN</classname> is undefined if <code>this-><methodname>empty</methodname>()</code>.</simpara></throws> 326 329 </method> 327 330 </method-group> 328 331 … … 558 561 <classname>function</classname> are equivalent to that of the 559 562 underlying <classname>functionN</classname> object, although 560 563 additional member functions are required to allow proper copy 561 construction and copy assignment of function objects.</para> 564 construction and copy assignment of function objects. The 565 corresponding class 566 template <classname alt="function">unsafe_fuction</classname> 567 has no exception safety guarantee when invoked with no 568 target.</para> 562 569 </description> 563 570 564 571 <typedef name="result_type"><type>R</type></typedef> … … 742 749 <parameter name="aN"><paramtype>argN_type</paramtype></parameter> 743 750 <effects><simpara><code>f(a1, a2, ..., aN)</code>, where <code>f</code> is the target of <code>*this</code>.</simpara></effects> 744 751 <returns><simpara>if <code>R</code> is <code>void</code>, nothing is returned; otherwise, the return value of the call to <code>f</code> is returned.</simpara></returns> 745 <throws><simpara><code><classname>bad_function_call</classname></code> if <code>this-><methodname>empty</methodname>()</code>. Otherwise, may through any exception thrown by the target function <code>f</code>. </simpara></throws>752 <throws><simpara><code><classname>bad_function_call</classname></code> if <code>this-><methodname>empty</methodname>()</code>. Otherwise, may through any exception thrown by the target function <code>f</code>. The behavior of <classname alt="function">unsafe_function</classname> is undefined if <code>this-><methodname>empty</methodname>()</code>.</simpara></throws> 746 753 </method> 747 754 </method-group> 748 755 -
libs/function/example/exception_safety.cpp
1 // Boost.Function library example 2 // 3 // Copyright Daniel Walker 2010. Use, modification and distribution 4 // are subject to the Boost Software License, Version 1.0. (See 5 // accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 // 8 // For more information, see http://www.boost.org/libs/function 9 // 10 11 // This example demonstrates how to handle boost::function and 12 // boost::unsafe_function when their preconditions are violated. 13 14 #include <iostream> 15 #include <boost/function.hpp> 16 17 int main(int, char*[]) 18 { 19 boost::function<void ()> f; 20 boost::unsafe_function<void ()> g; 21 22 try { 23 f(); // throws bad_function_call 24 } 25 catch(boost::bad_function_call e) { 26 std::cerr << e.what() << std::endl; 27 } 28 29 if(g) 30 g(); // undefined behavior 31 else 32 std::cerr << "boost::unsafe_function is empty" << std::endl; 33 34 return 0; 35 }