| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- | 
 | 2 | //===----------------------------------------------------------------------===// | 
 | 3 | // | 
| Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | //                     The LLVM Compiler Infrastructure | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // | 
 | 6 | // This file is distributed under the University of Illinois Open Source | 
 | 7 | // License. See LICENSE.TXT for details. | 
 | 8 | // | 
 | 9 | //===----------------------------------------------------------------------===// | 
 | 10 |  | 
 | 11 | #ifndef _LIBCPP_FUNCTIONAL_03 | 
 | 12 | #define _LIBCPP_FUNCTIONAL_03 | 
 | 13 |  | 
 | 14 | // manual variadic expansion for <functional> | 
 | 15 |  | 
 | 16 | #pragma GCC system_header | 
 | 17 |  | 
 | 18 | template <class _Tp> | 
 | 19 | class __mem_fn | 
 | 20 |     : public __weak_result_type<_Tp> | 
 | 21 | { | 
 | 22 | public: | 
 | 23 |     // types | 
 | 24 |     typedef _Tp type; | 
 | 25 | private: | 
 | 26 |     type __f_; | 
 | 27 |  | 
 | 28 | public: | 
 | 29 |     _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {} | 
 | 30 |  | 
 | 31 |     // invoke | 
 | 32 |  | 
 | 33 |     typename __invoke_return<type>::type | 
 | 34 |        operator() () | 
 | 35 |        { | 
 | 36 |            return __invoke(__f_); | 
 | 37 |        } | 
 | 38 |  | 
 | 39 |     template <class _A0> | 
 | 40 |        typename __invoke_return0<type, _A0>::type | 
 | 41 |           operator() (_A0& __a0) | 
 | 42 |           { | 
 | 43 |               return __invoke(__f_, __a0); | 
 | 44 |           } | 
 | 45 |  | 
 | 46 |     template <class _A0, class _A1> | 
 | 47 |        typename __invoke_return1<type, _A0, _A1>::type | 
 | 48 |           operator() (_A0& __a0, _A1& __a1) | 
 | 49 |           { | 
 | 50 |               return __invoke(__f_, __a0, __a1); | 
 | 51 |           } | 
 | 52 |  | 
 | 53 |     template <class _A0, class _A1, class _A2> | 
 | 54 |        typename __invoke_return2<type, _A0, _A1, _A2>::type | 
 | 55 |           operator() (_A0& __a0, _A1& __a1, _A2& __a2) | 
 | 56 |           { | 
 | 57 |               return __invoke(__f_, __a0, __a1, __a2); | 
 | 58 |           } | 
 | 59 | }; | 
 | 60 |  | 
 | 61 | template<class _R, class _T> | 
 | 62 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 63 | __mem_fn<_R _T::*> | 
 | 64 | mem_fn(_R _T::* __pm) | 
 | 65 | { | 
 | 66 |     return __mem_fn<_R _T::*>(__pm); | 
 | 67 | } | 
 | 68 |  | 
 | 69 | template<class _R, class _T> | 
 | 70 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 71 | __mem_fn<_R (_T::*)()> | 
 | 72 | mem_fn(_R (_T::* __pm)()) | 
 | 73 | { | 
 | 74 |     return __mem_fn<_R (_T::*)()>(__pm); | 
 | 75 | } | 
 | 76 |  | 
 | 77 | template<class _R, class _T, class _A0> | 
 | 78 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 79 | __mem_fn<_R (_T::*)(_A0)> | 
 | 80 | mem_fn(_R (_T::* __pm)(_A0)) | 
 | 81 | { | 
 | 82 |     return __mem_fn<_R (_T::*)(_A0)>(__pm); | 
 | 83 | } | 
 | 84 |  | 
 | 85 | template<class _R, class _T, class _A0, class _A1> | 
 | 86 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 87 | __mem_fn<_R (_T::*)(_A0, _A1)> | 
 | 88 | mem_fn(_R (_T::* __pm)(_A0, _A1)) | 
 | 89 | { | 
 | 90 |     return __mem_fn<_R (_T::*)(_A0, _A1)>(__pm); | 
 | 91 | } | 
 | 92 |  | 
 | 93 | template<class _R, class _T, class _A0, class _A1, class _A2> | 
 | 94 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 95 | __mem_fn<_R (_T::*)(_A0, _A1, _A2)> | 
 | 96 | mem_fn(_R (_T::* __pm)(_A0, _A1, _A2)) | 
 | 97 | { | 
 | 98 |     return __mem_fn<_R (_T::*)(_A0, _A1, _A2)>(__pm); | 
 | 99 | } | 
 | 100 |  | 
 | 101 | template<class _R, class _T> | 
 | 102 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 103 | __mem_fn<_R (_T::*)()> | 
 | 104 | mem_fn(_R (_T::* __pm)() const) | 
 | 105 | { | 
 | 106 |     return __mem_fn<_R (_T::*)()>(__pm); | 
 | 107 | } | 
 | 108 |  | 
 | 109 | template<class _R, class _T, class _A0> | 
 | 110 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 111 | __mem_fn<_R (_T::*)(_A0)> | 
 | 112 | mem_fn(_R (_T::* __pm)(_A0) const) | 
 | 113 | { | 
 | 114 |     return __mem_fn<_R (_T::*)(_A0)>(__pm); | 
 | 115 | } | 
 | 116 |  | 
 | 117 | template<class _R, class _T, class _A0, class _A1> | 
 | 118 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 119 | __mem_fn<_R (_T::*)(_A0, _A1)> | 
 | 120 | mem_fn(_R (_T::* __pm)(_A0, _A1) const) | 
 | 121 | { | 
 | 122 |     return __mem_fn<_R (_T::*)(_A0, _A1)>(__pm); | 
 | 123 | } | 
 | 124 |  | 
 | 125 | template<class _R, class _T, class _A0, class _A1, class _A2> | 
 | 126 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 127 | __mem_fn<_R (_T::*)(_A0, _A1, _A2)> | 
 | 128 | mem_fn(_R (_T::* __pm)(_A0, _A1, _A2) const) | 
 | 129 | { | 
 | 130 |     return __mem_fn<_R (_T::*)(_A0, _A1, _A2)>(__pm); | 
 | 131 | } | 
 | 132 |  | 
 | 133 | template<class _R, class _T> | 
 | 134 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 135 | __mem_fn<_R (_T::*)()> | 
 | 136 | mem_fn(_R (_T::* __pm)() volatile) | 
 | 137 | { | 
 | 138 |     return __mem_fn<_R (_T::*)()>(__pm); | 
 | 139 | } | 
 | 140 |  | 
 | 141 | template<class _R, class _T, class _A0> | 
 | 142 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 143 | __mem_fn<_R (_T::*)(_A0)> | 
 | 144 | mem_fn(_R (_T::* __pm)(_A0) volatile) | 
 | 145 | { | 
 | 146 |     return __mem_fn<_R (_T::*)(_A0)>(__pm); | 
 | 147 | } | 
 | 148 |  | 
 | 149 | template<class _R, class _T, class _A0, class _A1> | 
 | 150 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 151 | __mem_fn<_R (_T::*)(_A0, _A1)> | 
 | 152 | mem_fn(_R (_T::* __pm)(_A0, _A1) volatile) | 
 | 153 | { | 
 | 154 |     return __mem_fn<_R (_T::*)(_A0, _A1)>(__pm); | 
 | 155 | } | 
 | 156 |  | 
 | 157 | template<class _R, class _T, class _A0, class _A1, class _A2> | 
 | 158 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 159 | __mem_fn<_R (_T::*)(_A0, _A1, _A2)> | 
 | 160 | mem_fn(_R (_T::* __pm)(_A0, _A1, _A2) volatile) | 
 | 161 | { | 
 | 162 |     return __mem_fn<_R (_T::*)(_A0, _A1, _A2)>(__pm); | 
 | 163 | } | 
 | 164 |  | 
 | 165 | template<class _R, class _T> | 
 | 166 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 167 | __mem_fn<_R (_T::*)()> | 
 | 168 | mem_fn(_R (_T::* __pm)() const volatile) | 
 | 169 | { | 
 | 170 |     return __mem_fn<_R (_T::*)()>(__pm); | 
 | 171 | } | 
 | 172 |  | 
 | 173 | template<class _R, class _T, class _A0> | 
 | 174 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 175 | __mem_fn<_R (_T::*)(_A0)> | 
 | 176 | mem_fn(_R (_T::* __pm)(_A0) const volatile) | 
 | 177 | { | 
 | 178 |     return __mem_fn<_R (_T::*)(_A0)>(__pm); | 
 | 179 | } | 
 | 180 |  | 
 | 181 | template<class _R, class _T, class _A0, class _A1> | 
 | 182 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 183 | __mem_fn<_R (_T::*)(_A0, _A1)> | 
 | 184 | mem_fn(_R (_T::* __pm)(_A0, _A1) const volatile) | 
 | 185 | { | 
 | 186 |     return __mem_fn<_R (_T::*)(_A0, _A1)>(__pm); | 
 | 187 | } | 
 | 188 |  | 
 | 189 | template<class _R, class _T, class _A0, class _A1, class _A2> | 
 | 190 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 191 | __mem_fn<_R (_T::*)(_A0, _A1, _A2)> | 
 | 192 | mem_fn(_R (_T::* __pm)(_A0, _A1, _A2) const volatile) | 
 | 193 | { | 
 | 194 |     return __mem_fn<_R (_T::*)(_A0, _A1, _A2)>(__pm); | 
 | 195 | } | 
 | 196 |  | 
 | 197 | // bad_function_call | 
 | 198 |  | 
 | 199 | class bad_function_call | 
 | 200 |     : public exception | 
 | 201 | { | 
 | 202 | }; | 
 | 203 |  | 
 | 204 | template<class _Fp> class function; // undefined | 
 | 205 |  | 
 | 206 | namespace __function | 
 | 207 | { | 
 | 208 |  | 
 | 209 | template<class _F> | 
 | 210 | struct __maybe_derive_from_unary_function | 
 | 211 | { | 
 | 212 | }; | 
 | 213 |  | 
 | 214 | template<class _R, class _A1> | 
 | 215 | struct __maybe_derive_from_unary_function<_R(_A1)> | 
 | 216 |     : public unary_function<_A1, _R> | 
 | 217 | { | 
 | 218 | }; | 
 | 219 |  | 
 | 220 | template<class _F> | 
 | 221 | struct __maybe_derive_from_binary_function | 
 | 222 | { | 
 | 223 | }; | 
 | 224 |  | 
 | 225 | template<class _R, class _A1, class _A2> | 
 | 226 | struct __maybe_derive_from_binary_function<_R(_A1, _A2)> | 
 | 227 |     : public binary_function<_A1, _A2, _R> | 
 | 228 | { | 
 | 229 | }; | 
 | 230 |  | 
 | 231 | template<class _Fp> class __base; | 
 | 232 |  | 
 | 233 | template<class _R> | 
 | 234 | class __base<_R()> | 
 | 235 | { | 
 | 236 |     __base(const __base&); | 
 | 237 |     __base& operator=(const __base&); | 
 | 238 | public: | 
 | 239 |     __base() {} | 
 | 240 |     virtual ~__base() {} | 
 | 241 |     virtual __base* __clone() const = 0; | 
 | 242 |     virtual void __clone(__base*) const = 0; | 
 | 243 |     virtual void destroy() = 0; | 
 | 244 |     virtual void destroy_deallocate() = 0; | 
 | 245 |     virtual _R operator()() = 0; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 246 | #ifndef _LIBCPP_NO_RTTI | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 247 |     virtual const void* target(const type_info&) const = 0; | 
 | 248 |     virtual const std::type_info& target_type() const = 0; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 249 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 250 | }; | 
 | 251 |  | 
 | 252 | template<class _R, class _A0> | 
 | 253 | class __base<_R(_A0)> | 
 | 254 | { | 
 | 255 |     __base(const __base&); | 
 | 256 |     __base& operator=(const __base&); | 
 | 257 | public: | 
 | 258 |     __base() {} | 
 | 259 |     virtual ~__base() {} | 
 | 260 |     virtual __base* __clone() const = 0; | 
 | 261 |     virtual void __clone(__base*) const = 0; | 
 | 262 |     virtual void destroy() = 0; | 
 | 263 |     virtual void destroy_deallocate() = 0; | 
 | 264 |     virtual _R operator()(_A0) = 0; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 265 | #ifndef _LIBCPP_NO_RTTI | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 266 |     virtual const void* target(const type_info&) const = 0; | 
 | 267 |     virtual const std::type_info& target_type() const = 0; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 268 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 269 | }; | 
 | 270 |  | 
 | 271 | template<class _R, class _A0, class _A1> | 
 | 272 | class __base<_R(_A0, _A1)> | 
 | 273 | { | 
 | 274 |     __base(const __base&); | 
 | 275 |     __base& operator=(const __base&); | 
 | 276 | public: | 
 | 277 |     __base() {} | 
 | 278 |     virtual ~__base() {} | 
 | 279 |     virtual __base* __clone() const = 0; | 
 | 280 |     virtual void __clone(__base*) const = 0; | 
 | 281 |     virtual void destroy() = 0; | 
 | 282 |     virtual void destroy_deallocate() = 0; | 
 | 283 |     virtual _R operator()(_A0, _A1) = 0; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 284 | #ifndef _LIBCPP_NO_RTTI | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 285 |     virtual const void* target(const type_info&) const = 0; | 
 | 286 |     virtual const std::type_info& target_type() const = 0; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 287 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 288 | }; | 
 | 289 |  | 
 | 290 | template<class _R, class _A0, class _A1, class _A2> | 
 | 291 | class __base<_R(_A0, _A1, _A2)> | 
 | 292 | { | 
 | 293 |     __base(const __base&); | 
 | 294 |     __base& operator=(const __base&); | 
 | 295 | public: | 
 | 296 |     __base() {} | 
 | 297 |     virtual ~__base() {} | 
 | 298 |     virtual __base* __clone() const = 0; | 
 | 299 |     virtual void __clone(__base*) const = 0; | 
 | 300 |     virtual void destroy() = 0; | 
 | 301 |     virtual void destroy_deallocate() = 0; | 
 | 302 |     virtual _R operator()(_A0, _A1, _A2) = 0; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 303 | #ifndef _LIBCPP_NO_RTTI | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 304 |     virtual const void* target(const type_info&) const = 0; | 
 | 305 |     virtual const std::type_info& target_type() const = 0; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 306 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 307 | }; | 
 | 308 |  | 
 | 309 | template<class _FD, class _Alloc, class _FB> class __func; | 
 | 310 |  | 
 | 311 | template<class _F, class _Alloc, class _R> | 
 | 312 | class __func<_F, _Alloc, _R()> | 
 | 313 |     : public  __base<_R()> | 
 | 314 | { | 
 | 315 |     __compressed_pair<_F, _Alloc> __f_; | 
 | 316 | public: | 
 | 317 |     explicit __func(_F __f) : __f_(_STD::move(__f)) {} | 
 | 318 |     explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {} | 
 | 319 |     virtual __base<_R()>* __clone() const; | 
 | 320 |     virtual void __clone(__base<_R()>*) const; | 
 | 321 |     virtual void destroy(); | 
 | 322 |     virtual void destroy_deallocate(); | 
 | 323 |     virtual _R operator()(); | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 324 | #ifndef _LIBCPP_NO_RTTI | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 325 |     virtual const void* target(const type_info&) const; | 
 | 326 |     virtual const std::type_info& target_type() const; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 327 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 328 | }; | 
 | 329 |  | 
 | 330 | template<class _F, class _Alloc, class _R> | 
 | 331 | __base<_R()>* | 
 | 332 | __func<_F, _Alloc, _R()>::__clone() const | 
 | 333 | { | 
 | 334 |     typedef typename _Alloc::template rebind<__func>::other _A; | 
 | 335 |     _A __a(__f_.second()); | 
 | 336 |     typedef __allocator_destructor<_A> _D; | 
 | 337 |     unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1)); | 
 | 338 |     ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); | 
 | 339 |     return __hold.release(); | 
 | 340 | } | 
 | 341 |  | 
 | 342 | template<class _F, class _Alloc, class _R> | 
 | 343 | void | 
 | 344 | __func<_F, _Alloc, _R()>::__clone(__base<_R()>* __p) const | 
 | 345 | { | 
 | 346 |     ::new (__p) __func(__f_.first(), __f_.second()); | 
 | 347 | } | 
 | 348 |  | 
 | 349 | template<class _F, class _Alloc, class _R> | 
 | 350 | void | 
 | 351 | __func<_F, _Alloc, _R()>::destroy() | 
 | 352 | { | 
 | 353 |     __f_.~__compressed_pair<_F, _Alloc>(); | 
 | 354 | } | 
 | 355 |  | 
 | 356 | template<class _F, class _Alloc, class _R> | 
 | 357 | void | 
 | 358 | __func<_F, _Alloc, _R()>::destroy_deallocate() | 
 | 359 | { | 
 | 360 |     typedef typename _Alloc::template rebind<__func>::other _A; | 
 | 361 |     _A __a(__f_.second()); | 
 | 362 |     __f_.~__compressed_pair<_F, _Alloc>(); | 
 | 363 |     __a.deallocate(this, 1); | 
 | 364 | } | 
 | 365 |  | 
 | 366 | template<class _F, class _Alloc, class _R> | 
 | 367 | _R | 
 | 368 | __func<_F, _Alloc, _R()>::operator()() | 
 | 369 | { | 
 | 370 |     return __invoke<_R>(__f_.first()); | 
 | 371 | } | 
 | 372 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 373 | #ifndef _LIBCPP_NO_RTTI | 
 | 374 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 375 | template<class _F, class _Alloc, class _R> | 
 | 376 | const void* | 
 | 377 | __func<_F, _Alloc, _R()>::target(const type_info& __ti) const | 
 | 378 | { | 
 | 379 |     if (__ti == typeid(_F)) | 
 | 380 |         return &__f_.first(); | 
 | 381 |     return (const void*)0; | 
 | 382 | } | 
 | 383 |  | 
 | 384 | template<class _F, class _Alloc, class _R> | 
 | 385 | const std::type_info& | 
 | 386 | __func<_F, _Alloc, _R()>::target_type() const | 
 | 387 | { | 
 | 388 |     return typeid(_F); | 
 | 389 | } | 
 | 390 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 391 | #endif | 
 | 392 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 393 | template<class _F, class _Alloc, class _R, class _A0> | 
 | 394 | class __func<_F, _Alloc, _R(_A0)> | 
 | 395 |     : public  __base<_R(_A0)> | 
 | 396 | { | 
 | 397 |     __compressed_pair<_F, _Alloc> __f_; | 
 | 398 | public: | 
 | 399 |     explicit __func(_F __f) : __f_(_STD::move(__f)) {} | 
 | 400 |     explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {} | 
 | 401 |     virtual __base<_R(_A0)>* __clone() const; | 
 | 402 |     virtual void __clone(__base<_R(_A0)>*) const; | 
 | 403 |     virtual void destroy(); | 
 | 404 |     virtual void destroy_deallocate(); | 
 | 405 |     virtual _R operator()(_A0); | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 406 | #ifndef _LIBCPP_NO_RTTI | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 407 |     virtual const void* target(const type_info&) const; | 
 | 408 |     virtual const std::type_info& target_type() const; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 409 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 410 | }; | 
 | 411 |  | 
 | 412 | template<class _F, class _Alloc, class _R, class _A0> | 
 | 413 | __base<_R(_A0)>* | 
 | 414 | __func<_F, _Alloc, _R(_A0)>::__clone() const | 
 | 415 | { | 
 | 416 |     typedef typename _Alloc::template rebind<__func>::other _A; | 
 | 417 |     _A __a(__f_.second()); | 
 | 418 |     typedef __allocator_destructor<_A> _D; | 
 | 419 |     unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1)); | 
 | 420 |     ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); | 
 | 421 |     return __hold.release(); | 
 | 422 | } | 
 | 423 |  | 
 | 424 | template<class _F, class _Alloc, class _R, class _A0> | 
 | 425 | void | 
 | 426 | __func<_F, _Alloc, _R(_A0)>::__clone(__base<_R(_A0)>* __p) const | 
 | 427 | { | 
 | 428 |     ::new (__p) __func(__f_.first(), __f_.second()); | 
 | 429 | } | 
 | 430 |  | 
 | 431 | template<class _F, class _Alloc, class _R, class _A0> | 
 | 432 | void | 
 | 433 | __func<_F, _Alloc, _R(_A0)>::destroy() | 
 | 434 | { | 
 | 435 |     __f_.~__compressed_pair<_F, _Alloc>(); | 
 | 436 | } | 
 | 437 |  | 
 | 438 | template<class _F, class _Alloc, class _R, class _A0> | 
 | 439 | void | 
 | 440 | __func<_F, _Alloc, _R(_A0)>::destroy_deallocate() | 
 | 441 | { | 
 | 442 |     typedef typename _Alloc::template rebind<__func>::other _A; | 
 | 443 |     _A __a(__f_.second()); | 
 | 444 |     __f_.~__compressed_pair<_F, _Alloc>(); | 
 | 445 |     __a.deallocate(this, 1); | 
 | 446 | } | 
 | 447 |  | 
 | 448 | template<class _F, class _Alloc, class _R, class _A0> | 
 | 449 | _R | 
 | 450 | __func<_F, _Alloc, _R(_A0)>::operator()(_A0 __a0) | 
 | 451 | { | 
 | 452 |     return __invoke(__f_.first(), __a0); | 
 | 453 | } | 
 | 454 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 455 | #ifndef _LIBCPP_NO_RTTI | 
 | 456 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 457 | template<class _F, class _Alloc, class _R, class _A0> | 
 | 458 | const void* | 
 | 459 | __func<_F, _Alloc, _R(_A0)>::target(const type_info& __ti) const | 
 | 460 | { | 
 | 461 |     if (__ti == typeid(_F)) | 
 | 462 |         return &__f_.first(); | 
 | 463 |     return (const void*)0; | 
 | 464 | } | 
 | 465 |  | 
 | 466 | template<class _F, class _Alloc, class _R, class _A0> | 
 | 467 | const std::type_info& | 
 | 468 | __func<_F, _Alloc, _R(_A0)>::target_type() const | 
 | 469 | { | 
 | 470 |     return typeid(_F); | 
 | 471 | } | 
 | 472 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 473 | #endif | 
 | 474 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 475 | template<class _F, class _Alloc, class _R, class _A0, class _A1> | 
 | 476 | class __func<_F, _Alloc, _R(_A0, _A1)> | 
 | 477 |     : public  __base<_R(_A0, _A1)> | 
 | 478 | { | 
 | 479 |     __compressed_pair<_F, _Alloc> __f_; | 
 | 480 | public: | 
 | 481 |     explicit __func(_F __f) : __f_(_STD::move(__f)) {} | 
 | 482 |     explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {} | 
 | 483 |     virtual __base<_R(_A0, _A1)>* __clone() const; | 
 | 484 |     virtual void __clone(__base<_R(_A0, _A1)>*) const; | 
 | 485 |     virtual void destroy(); | 
 | 486 |     virtual void destroy_deallocate(); | 
 | 487 |     virtual _R operator()(_A0, _A1); | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 488 | #ifndef _LIBCPP_NO_RTTI | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 489 |     virtual const void* target(const type_info&) const; | 
 | 490 |     virtual const std::type_info& target_type() const; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 491 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 492 | }; | 
 | 493 |  | 
 | 494 | template<class _F, class _Alloc, class _R, class _A0, class _A1> | 
 | 495 | __base<_R(_A0, _A1)>* | 
 | 496 | __func<_F, _Alloc, _R(_A0, _A1)>::__clone() const | 
 | 497 | { | 
 | 498 |     typedef typename _Alloc::template rebind<__func>::other _A; | 
 | 499 |     _A __a(__f_.second()); | 
 | 500 |     typedef __allocator_destructor<_A> _D; | 
 | 501 |     unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1)); | 
 | 502 |     ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); | 
 | 503 |     return __hold.release(); | 
 | 504 | } | 
 | 505 |  | 
 | 506 | template<class _F, class _Alloc, class _R, class _A0, class _A1> | 
 | 507 | void | 
 | 508 | __func<_F, _Alloc, _R(_A0, _A1)>::__clone(__base<_R(_A0, _A1)>* __p) const | 
 | 509 | { | 
 | 510 |     ::new (__p) __func(__f_.first(), __f_.second()); | 
 | 511 | } | 
 | 512 |  | 
 | 513 | template<class _F, class _Alloc, class _R, class _A0, class _A1> | 
 | 514 | void | 
 | 515 | __func<_F, _Alloc, _R(_A0, _A1)>::destroy() | 
 | 516 | { | 
 | 517 |     __f_.~__compressed_pair<_F, _Alloc>(); | 
 | 518 | } | 
 | 519 |  | 
 | 520 | template<class _F, class _Alloc, class _R, class _A0, class _A1> | 
 | 521 | void | 
 | 522 | __func<_F, _Alloc, _R(_A0, _A1)>::destroy_deallocate() | 
 | 523 | { | 
 | 524 |     typedef typename _Alloc::template rebind<__func>::other _A; | 
 | 525 |     _A __a(__f_.second()); | 
 | 526 |     __f_.~__compressed_pair<_F, _Alloc>(); | 
 | 527 |     __a.deallocate(this, 1); | 
 | 528 | } | 
 | 529 |  | 
 | 530 | template<class _F, class _Alloc, class _R, class _A0, class _A1> | 
 | 531 | _R | 
 | 532 | __func<_F, _Alloc, _R(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) | 
 | 533 | { | 
 | 534 |     return __invoke(__f_.first(), __a0, __a1); | 
 | 535 | } | 
 | 536 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 537 | #ifndef _LIBCPP_NO_RTTI | 
 | 538 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 539 | template<class _F, class _Alloc, class _R, class _A0, class _A1> | 
 | 540 | const void* | 
 | 541 | __func<_F, _Alloc, _R(_A0, _A1)>::target(const type_info& __ti) const | 
 | 542 | { | 
 | 543 |     if (__ti == typeid(_F)) | 
 | 544 |         return &__f_.first(); | 
 | 545 |     return (const void*)0; | 
 | 546 | } | 
 | 547 |  | 
 | 548 | template<class _F, class _Alloc, class _R, class _A0, class _A1> | 
 | 549 | const std::type_info& | 
 | 550 | __func<_F, _Alloc, _R(_A0, _A1)>::target_type() const | 
 | 551 | { | 
 | 552 |     return typeid(_F); | 
 | 553 | } | 
 | 554 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 555 | #endif | 
 | 556 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 557 | template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2> | 
 | 558 | class __func<_F, _Alloc, _R(_A0, _A1, _A2)> | 
 | 559 |     : public  __base<_R(_A0, _A1, _A2)> | 
 | 560 | { | 
 | 561 |     __compressed_pair<_F, _Alloc> __f_; | 
 | 562 | public: | 
 | 563 |     explicit __func(_F __f) : __f_(_STD::move(__f)) {} | 
 | 564 |     explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {} | 
 | 565 |     virtual __base<_R(_A0, _A1, _A2)>* __clone() const; | 
 | 566 |     virtual void __clone(__base<_R(_A0, _A1, _A2)>*) const; | 
 | 567 |     virtual void destroy(); | 
 | 568 |     virtual void destroy_deallocate(); | 
 | 569 |     virtual _R operator()(_A0, _A1, _A2); | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 570 | #ifndef _LIBCPP_NO_RTTI | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 571 |     virtual const void* target(const type_info&) const; | 
 | 572 |     virtual const std::type_info& target_type() const; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 573 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 574 | }; | 
 | 575 |  | 
 | 576 | template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2> | 
 | 577 | __base<_R(_A0, _A1, _A2)>* | 
 | 578 | __func<_F, _Alloc, _R(_A0, _A1, _A2)>::__clone() const | 
 | 579 | { | 
 | 580 |     typedef typename _Alloc::template rebind<__func>::other _A; | 
 | 581 |     _A __a(__f_.second()); | 
 | 582 |     typedef __allocator_destructor<_A> _D; | 
 | 583 |     unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1)); | 
 | 584 |     ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); | 
 | 585 |     return __hold.release(); | 
 | 586 | } | 
 | 587 |  | 
 | 588 | template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2> | 
 | 589 | void | 
 | 590 | __func<_F, _Alloc, _R(_A0, _A1, _A2)>::__clone(__base<_R(_A0, _A1, _A2)>* __p) const | 
 | 591 | { | 
 | 592 |     ::new (__p) __func(__f_.first(), __f_.second()); | 
 | 593 | } | 
 | 594 |  | 
 | 595 | template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2> | 
 | 596 | void | 
 | 597 | __func<_F, _Alloc, _R(_A0, _A1, _A2)>::destroy() | 
 | 598 | { | 
 | 599 |     __f_.~__compressed_pair<_F, _Alloc>(); | 
 | 600 | } | 
 | 601 |  | 
 | 602 | template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2> | 
 | 603 | void | 
 | 604 | __func<_F, _Alloc, _R(_A0, _A1, _A2)>::destroy_deallocate() | 
 | 605 | { | 
 | 606 |     typedef typename _Alloc::template rebind<__func>::other _A; | 
 | 607 |     _A __a(__f_.second()); | 
 | 608 |     __f_.~__compressed_pair<_F, _Alloc>(); | 
 | 609 |     __a.deallocate(this, 1); | 
 | 610 | } | 
 | 611 |  | 
 | 612 | template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2> | 
 | 613 | _R | 
 | 614 | __func<_F, _Alloc, _R(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) | 
 | 615 | { | 
 | 616 |     return __invoke(__f_.first(), __a0, __a1, __a2); | 
 | 617 | } | 
 | 618 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 619 | #ifndef _LIBCPP_NO_RTTI | 
 | 620 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 621 | template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2> | 
 | 622 | const void* | 
 | 623 | __func<_F, _Alloc, _R(_A0, _A1, _A2)>::target(const type_info& __ti) const | 
 | 624 | { | 
 | 625 |     if (__ti == typeid(_F)) | 
 | 626 |         return &__f_.first(); | 
 | 627 |     return (const void*)0; | 
 | 628 | } | 
 | 629 |  | 
 | 630 | template<class _F, class _Alloc, class _R, class _A0, class _A1, class _A2> | 
 | 631 | const std::type_info& | 
 | 632 | __func<_F, _Alloc, _R(_A0, _A1, _A2)>::target_type() const | 
 | 633 | { | 
 | 634 |     return typeid(_F); | 
 | 635 | } | 
 | 636 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 637 | #endif | 
 | 638 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 639 | }  // __function | 
 | 640 |  | 
 | 641 | template<class _R> | 
 | 642 | class function<_R()> | 
 | 643 | { | 
 | 644 |     typedef __function::__base<_R()> __base; | 
 | 645 |     aligned_storage<3*sizeof(void*)>::type __buf_; | 
 | 646 |     __base* __f_; | 
 | 647 |  | 
 | 648 |     template <class _F> | 
 | 649 |         static bool __not_null(const _F&) {return true;} | 
 | 650 |     template <class _R2> | 
 | 651 |         static bool __not_null(const function<_R()>& __p) {return __p;} | 
 | 652 | public: | 
 | 653 |     typedef _R result_type; | 
 | 654 |  | 
 | 655 |     // 20.7.16.2.1, construct/copy/destroy: | 
 | 656 |     explicit function() : __f_(0) {} | 
 | 657 |     function(nullptr_t) : __f_(0) {} | 
 | 658 |     function(const function&); | 
 | 659 |     template<class _F> | 
 | 660 |       function(_F, | 
 | 661 |                typename enable_if<!is_integral<_F>::value>::type* = 0); | 
 | 662 |  | 
 | 663 | //     template<class _Alloc> | 
 | 664 | //       function(allocator_arg_t, const _Alloc&); | 
 | 665 | //     template<Allocator Alloc> | 
 | 666 | //       function(allocator_arg_t, const Alloc&, nullptr_t); | 
 | 667 | //     template<Allocator Alloc> | 
 | 668 | //       function(allocator_arg_t, const Alloc&, const function&); | 
 | 669 | //     template<Allocator Alloc> | 
 | 670 | //       function(allocator_arg_t, const Alloc&, function&&); | 
 | 671 | //     template<class F, Allocator Alloc> | 
 | 672 | //       function(allocator_arg_t, const Alloc&, F); | 
 | 673 |  | 
 | 674 |     function& operator=(const function&); | 
 | 675 |     function& operator=(nullptr_t); | 
 | 676 |     template<class _F> | 
 | 677 |       typename enable_if | 
 | 678 |       < | 
 | 679 |         !is_integral<_F>::value, | 
 | 680 |         function& | 
 | 681 |       >::type | 
 | 682 |       operator=(_F); | 
 | 683 |  | 
 | 684 |     ~function(); | 
 | 685 |  | 
 | 686 |     // 20.7.16.2.2, function modifiers: | 
 | 687 |     void swap(function&); | 
 | 688 | //     template<class _F, class _Alloc> | 
 | 689 | //       void assign(_F, const _Alloc&); | 
 | 690 |  | 
 | 691 |     // 20.7.16.2.3, function capacity: | 
 | 692 |     operator bool() const {return __f_;} | 
 | 693 |  | 
 | 694 | private: | 
 | 695 |     // deleted overloads close possible hole in the type system | 
 | 696 |     template<class _R2> | 
 | 697 |       bool operator==(const function<_R2()>&);// = delete; | 
 | 698 |     template<class _R2> | 
 | 699 |       bool operator!=(const function<_R2()>&);// = delete; | 
 | 700 | public: | 
 | 701 |     // 20.7.16.2.4, function invocation: | 
 | 702 |     _R operator()() const; | 
 | 703 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 704 | #ifndef _LIBCPP_NO_RTTI | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 705 |     // 20.7.16.2.5, function target access: | 
 | 706 |     const std::type_info& target_type() const; | 
 | 707 |     template <typename _T> _T* target(); | 
 | 708 |     template <typename _T> const _T* target() const; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 709 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 710 | }; | 
 | 711 |  | 
 | 712 | template<class _R> | 
 | 713 | function<_R()>::function(const function& __f) | 
 | 714 | { | 
 | 715 |     if (__f.__f_ == 0) | 
 | 716 |         __f_ = 0; | 
 | 717 |     else if (__f.__f_ == (const __base*)&__f.__buf_) | 
 | 718 |     { | 
 | 719 |         __f_ = (__base*)&__buf_; | 
 | 720 |         __f.__f_->__clone(__f_); | 
 | 721 |     } | 
 | 722 |     else | 
 | 723 |         __f_ = __f.__f_->__clone(); | 
 | 724 | } | 
 | 725 |  | 
 | 726 | template<class _R> | 
 | 727 | template <class _F> | 
 | 728 | function<_R()>::function(_F __f, | 
 | 729 |                                      typename enable_if<!is_integral<_F>::value>::type*) | 
 | 730 |     : __f_(0) | 
 | 731 | { | 
 | 732 |     if (__not_null(__f)) | 
 | 733 |     { | 
 | 734 |         typedef __function::__func<_F, allocator<_F>, _R()> _FF; | 
 | 735 |         if (sizeof(_FF) <= sizeof(__buf_)) | 
 | 736 |         { | 
 | 737 |             __f_ = (__base*)&__buf_; | 
 | 738 |             ::new (__f_) _FF(__f); | 
 | 739 |         } | 
 | 740 |         else | 
 | 741 |         { | 
 | 742 |             typedef allocator<_FF> _A; | 
 | 743 |             _A __a; | 
 | 744 |             typedef __allocator_destructor<_A> _D; | 
 | 745 |             unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); | 
 | 746 |             ::new (__hold.get()) _FF(__f, allocator<_F>(__a)); | 
 | 747 |             __f_ = __hold.release(); | 
 | 748 |         } | 
 | 749 |     } | 
 | 750 | } | 
 | 751 |  | 
 | 752 | template<class _R> | 
 | 753 | function<_R()>& | 
 | 754 | function<_R()>::operator=(const function& __f) | 
 | 755 | { | 
 | 756 |     function(__f).swap(*this); | 
 | 757 |     return *this; | 
 | 758 | } | 
 | 759 |  | 
 | 760 | template<class _R> | 
 | 761 | function<_R()>& | 
 | 762 | function<_R()>::operator=(nullptr_t) | 
 | 763 | { | 
 | 764 |     if (__f_ == (__base*)&__buf_) | 
 | 765 |         __f_->destroy(); | 
 | 766 |     else if (__f_) | 
 | 767 |         __f_->destroy_deallocate(); | 
 | 768 |     __f_ = 0; | 
 | 769 | } | 
 | 770 |  | 
 | 771 | template<class _R> | 
 | 772 | template <class _F> | 
 | 773 | typename enable_if | 
 | 774 | < | 
 | 775 |     !is_integral<_F>::value, | 
 | 776 |     function<_R()>& | 
 | 777 | >::type | 
 | 778 | function<_R()>::operator=(_F __f) | 
 | 779 | { | 
 | 780 |     function(_STD::move(__f)).swap(*this); | 
 | 781 |     return *this; | 
 | 782 | } | 
 | 783 |  | 
 | 784 | template<class _R> | 
 | 785 | function<_R()>::~function() | 
 | 786 | { | 
 | 787 |     if (__f_ == (__base*)&__buf_) | 
 | 788 |         __f_->destroy(); | 
 | 789 |     else if (__f_) | 
 | 790 |         __f_->destroy_deallocate(); | 
 | 791 | } | 
 | 792 |  | 
 | 793 | template<class _R> | 
 | 794 | void | 
 | 795 | function<_R()>::swap(function& __f) | 
 | 796 | { | 
 | 797 |     if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) | 
 | 798 |     { | 
 | 799 |         typename aligned_storage<sizeof(__buf_)>::type __tempbuf; | 
 | 800 |         __base* __t = (__base*)&__tempbuf; | 
 | 801 |         __f_->__clone(__t); | 
 | 802 |         __f_->destroy(); | 
 | 803 |         __f_ = 0; | 
 | 804 |         __f.__f_->__clone((__base*)&__buf_); | 
 | 805 |         __f.__f_->destroy(); | 
 | 806 |         __f.__f_ = 0; | 
 | 807 |         __f_ = (__base*)&__buf_; | 
 | 808 |         __t->__clone((__base*)&__f.__buf_); | 
 | 809 |         __t->destroy(); | 
 | 810 |         __f.__f_ = (__base*)&__f.__buf_; | 
 | 811 |     } | 
 | 812 |     else if (__f_ == (__base*)&__buf_) | 
 | 813 |     { | 
 | 814 |         __f_->__clone((__base*)&__f.__buf_); | 
 | 815 |         __f_->destroy(); | 
 | 816 |         __f_ = __f.__f_; | 
 | 817 |         __f.__f_ = (__base*)&__f.__buf_; | 
 | 818 |     } | 
 | 819 |     else if (__f.__f_ == (__base*)&__f.__buf_) | 
 | 820 |     { | 
 | 821 |         __f.__f_->__clone((__base*)&__buf_); | 
 | 822 |         __f.__f_->destroy(); | 
 | 823 |         __f.__f_ = __f_; | 
 | 824 |         __f_ = (__base*)&__buf_; | 
 | 825 |     } | 
 | 826 |     else | 
 | 827 |         _STD::swap(__f_, __f.__f_); | 
 | 828 | } | 
 | 829 |  | 
 | 830 | template<class _R> | 
 | 831 | _R | 
 | 832 | function<_R()>::operator()() const | 
 | 833 | { | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 834 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 835 |     if (__f_ == 0) | 
 | 836 |         throw bad_function_call(); | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 837 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 838 |     return (*__f_)(); | 
 | 839 | } | 
 | 840 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 841 | #ifndef _LIBCPP_NO_RTTI | 
 | 842 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 843 | template<class _R> | 
 | 844 | const std::type_info& | 
 | 845 | function<_R()>::target_type() const | 
 | 846 | { | 
 | 847 |     if (__f_ == 0) | 
 | 848 |         return typeid(void); | 
 | 849 |     return __f_->target_type(); | 
 | 850 | } | 
 | 851 |  | 
 | 852 | template<class _R> | 
 | 853 | template <typename _T> | 
 | 854 | _T* | 
 | 855 | function<_R()>::target() | 
 | 856 | { | 
 | 857 |     if (__f_ == 0) | 
 | 858 |         return (_T*)0; | 
 | 859 |     return (_T*)__f_->target(typeid(_T)); | 
 | 860 | } | 
 | 861 |  | 
 | 862 | template<class _R> | 
 | 863 | template <typename _T> | 
 | 864 | const _T* | 
 | 865 | function<_R()>::target() const | 
 | 866 | { | 
 | 867 |     if (__f_ == 0) | 
 | 868 |         return (const _T*)0; | 
 | 869 |     return (const _T*)__f_->target(typeid(_T)); | 
 | 870 | } | 
 | 871 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 872 | #endif | 
 | 873 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 874 | template<class _R, class _A0> | 
 | 875 | class function<_R(_A0)> | 
 | 876 |     : public unary_function<_A0, _R> | 
 | 877 | { | 
 | 878 |     typedef __function::__base<_R(_A0)> __base; | 
 | 879 |     aligned_storage<3*sizeof(void*)>::type __buf_; | 
 | 880 |     __base* __f_; | 
 | 881 |  | 
 | 882 |     template <class _F> | 
 | 883 |         static bool __not_null(const _F&) {return true;} | 
 | 884 |     template <class _R2, class _B0> | 
 | 885 |         static bool __not_null(_R2 (*__p)(_B0)) {return __p;} | 
 | 886 |     template <class _R2, class _C> | 
 | 887 |         static bool __not_null(_R2 (_C::*__p)()) {return __p;} | 
 | 888 |     template <class _R2, class _C> | 
 | 889 |         static bool __not_null(_R2 (_C::*__p)() const) {return __p;} | 
 | 890 |     template <class _R2, class _C> | 
 | 891 |         static bool __not_null(_R2 (_C::*__p)() volatile) {return __p;} | 
 | 892 |     template <class _R2, class _C> | 
 | 893 |         static bool __not_null(_R2 (_C::*__p)() const volatile) {return __p;} | 
 | 894 |     template <class _R2, class _B0> | 
 | 895 |         static bool __not_null(const function<_R(_B0)>& __p) {return __p;} | 
 | 896 | public: | 
 | 897 |     typedef _R result_type; | 
 | 898 |  | 
 | 899 |     // 20.7.16.2.1, construct/copy/destroy: | 
 | 900 |     explicit function() : __f_(0) {} | 
 | 901 |     function(nullptr_t) : __f_(0) {} | 
 | 902 |     function(const function&); | 
 | 903 |     template<class _F> | 
 | 904 |       function(_F, | 
 | 905 |                typename enable_if<!is_integral<_F>::value>::type* = 0); | 
 | 906 |  | 
 | 907 | //     template<class _Alloc> | 
 | 908 | //       function(allocator_arg_t, const _Alloc&); | 
 | 909 | //     template<Allocator Alloc> | 
 | 910 | //       function(allocator_arg_t, const Alloc&, nullptr_t); | 
 | 911 | //     template<Allocator Alloc> | 
 | 912 | //       function(allocator_arg_t, const Alloc&, const function&); | 
 | 913 | //     template<Allocator Alloc> | 
 | 914 | //       function(allocator_arg_t, const Alloc&, function&&); | 
 | 915 | //     template<class F, Allocator Alloc> | 
 | 916 | //       function(allocator_arg_t, const Alloc&, F); | 
 | 917 |  | 
 | 918 |     function& operator=(const function&); | 
 | 919 |     function& operator=(nullptr_t); | 
 | 920 |     template<class _F> | 
 | 921 |       typename enable_if | 
 | 922 |       < | 
 | 923 |         !is_integral<_F>::value, | 
 | 924 |         function& | 
 | 925 |       >::type | 
 | 926 |       operator=(_F); | 
 | 927 |  | 
 | 928 |     ~function(); | 
 | 929 |  | 
 | 930 |     // 20.7.16.2.2, function modifiers: | 
 | 931 |     void swap(function&); | 
 | 932 | //     template<class _F, class _Alloc> | 
 | 933 | //       void assign(_F, const _Alloc&); | 
 | 934 |  | 
 | 935 |     // 20.7.16.2.3, function capacity: | 
 | 936 |     operator bool() const {return __f_;} | 
 | 937 |  | 
 | 938 | private: | 
 | 939 |     // deleted overloads close possible hole in the type system | 
 | 940 |     template<class _R2, class _B0> | 
 | 941 |       bool operator==(const function<_R2(_B0)>&);// = delete; | 
 | 942 |     template<class _R2, class _B0> | 
 | 943 |       bool operator!=(const function<_R2(_B0)>&);// = delete; | 
 | 944 | public: | 
 | 945 |     // 20.7.16.2.4, function invocation: | 
 | 946 |     _R operator()(_A0) const; | 
 | 947 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 948 | #ifndef _LIBCPP_NO_RTTI | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 949 |     // 20.7.16.2.5, function target access: | 
 | 950 |     const std::type_info& target_type() const; | 
 | 951 |     template <typename _T> _T* target(); | 
 | 952 |     template <typename _T> const _T* target() const; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 953 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 954 | }; | 
 | 955 |  | 
 | 956 | template<class _R, class _A0> | 
 | 957 | function<_R(_A0)>::function(const function& __f) | 
 | 958 | { | 
 | 959 |     if (__f.__f_ == 0) | 
 | 960 |         __f_ = 0; | 
 | 961 |     else if (__f.__f_ == (const __base*)&__f.__buf_) | 
 | 962 |     { | 
 | 963 |         __f_ = (__base*)&__buf_; | 
 | 964 |         __f.__f_->__clone(__f_); | 
 | 965 |     } | 
 | 966 |     else | 
 | 967 |         __f_ = __f.__f_->__clone(); | 
 | 968 | } | 
 | 969 |  | 
 | 970 | template<class _R, class _A0> | 
 | 971 | template <class _F> | 
 | 972 | function<_R(_A0)>::function(_F __f, | 
 | 973 |                                      typename enable_if<!is_integral<_F>::value>::type*) | 
 | 974 |     : __f_(0) | 
 | 975 | { | 
 | 976 |     if (__not_null(__f)) | 
 | 977 |     { | 
 | 978 |         typedef __function::__func<_F, allocator<_F>, _R(_A0)> _FF; | 
 | 979 |         if (sizeof(_FF) <= sizeof(__buf_)) | 
 | 980 |         { | 
 | 981 |             __f_ = (__base*)&__buf_; | 
 | 982 |             ::new (__f_) _FF(__f); | 
 | 983 |         } | 
 | 984 |         else | 
 | 985 |         { | 
 | 986 |             typedef allocator<_FF> _A; | 
 | 987 |             _A __a; | 
 | 988 |             typedef __allocator_destructor<_A> _D; | 
 | 989 |             unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); | 
 | 990 |             ::new (__hold.get()) _FF(__f, allocator<_F>(__a)); | 
 | 991 |             __f_ = __hold.release(); | 
 | 992 |         } | 
 | 993 |     } | 
 | 994 | } | 
 | 995 |  | 
 | 996 | template<class _R, class _A0> | 
 | 997 | function<_R(_A0)>& | 
 | 998 | function<_R(_A0)>::operator=(const function& __f) | 
 | 999 | { | 
 | 1000 |     function(__f).swap(*this); | 
 | 1001 |     return *this; | 
 | 1002 | } | 
 | 1003 |  | 
 | 1004 | template<class _R, class _A0> | 
 | 1005 | function<_R(_A0)>& | 
 | 1006 | function<_R(_A0)>::operator=(nullptr_t) | 
 | 1007 | { | 
 | 1008 |     if (__f_ == (__base*)&__buf_) | 
 | 1009 |         __f_->destroy(); | 
 | 1010 |     else if (__f_) | 
 | 1011 |         __f_->destroy_deallocate(); | 
 | 1012 |     __f_ = 0; | 
 | 1013 | } | 
 | 1014 |  | 
 | 1015 | template<class _R, class _A0> | 
 | 1016 | template <class _F> | 
 | 1017 | typename enable_if | 
 | 1018 | < | 
 | 1019 |     !is_integral<_F>::value, | 
 | 1020 |     function<_R(_A0)>& | 
 | 1021 | >::type | 
 | 1022 | function<_R(_A0)>::operator=(_F __f) | 
 | 1023 | { | 
 | 1024 |     function(_STD::move(__f)).swap(*this); | 
 | 1025 |     return *this; | 
 | 1026 | } | 
 | 1027 |  | 
 | 1028 | template<class _R, class _A0> | 
 | 1029 | function<_R(_A0)>::~function() | 
 | 1030 | { | 
 | 1031 |     if (__f_ == (__base*)&__buf_) | 
 | 1032 |         __f_->destroy(); | 
 | 1033 |     else if (__f_) | 
 | 1034 |         __f_->destroy_deallocate(); | 
 | 1035 | } | 
 | 1036 |  | 
 | 1037 | template<class _R, class _A0> | 
 | 1038 | void | 
 | 1039 | function<_R(_A0)>::swap(function& __f) | 
 | 1040 | { | 
 | 1041 |     if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) | 
 | 1042 |     { | 
 | 1043 |         typename aligned_storage<sizeof(__buf_)>::type __tempbuf; | 
 | 1044 |         __base* __t = (__base*)&__tempbuf; | 
 | 1045 |         __f_->__clone(__t); | 
 | 1046 |         __f_->destroy(); | 
 | 1047 |         __f_ = 0; | 
 | 1048 |         __f.__f_->__clone((__base*)&__buf_); | 
 | 1049 |         __f.__f_->destroy(); | 
 | 1050 |         __f.__f_ = 0; | 
 | 1051 |         __f_ = (__base*)&__buf_; | 
 | 1052 |         __t->__clone((__base*)&__f.__buf_); | 
 | 1053 |         __t->destroy(); | 
 | 1054 |         __f.__f_ = (__base*)&__f.__buf_; | 
 | 1055 |     } | 
 | 1056 |     else if (__f_ == (__base*)&__buf_) | 
 | 1057 |     { | 
 | 1058 |         __f_->__clone((__base*)&__f.__buf_); | 
 | 1059 |         __f_->destroy(); | 
 | 1060 |         __f_ = __f.__f_; | 
 | 1061 |         __f.__f_ = (__base*)&__f.__buf_; | 
 | 1062 |     } | 
 | 1063 |     else if (__f.__f_ == (__base*)&__f.__buf_) | 
 | 1064 |     { | 
 | 1065 |         __f.__f_->__clone((__base*)&__buf_); | 
 | 1066 |         __f.__f_->destroy(); | 
 | 1067 |         __f.__f_ = __f_; | 
 | 1068 |         __f_ = (__base*)&__buf_; | 
 | 1069 |     } | 
 | 1070 |     else | 
 | 1071 |         _STD::swap(__f_, __f.__f_); | 
 | 1072 | } | 
 | 1073 |  | 
 | 1074 | template<class _R, class _A0> | 
 | 1075 | _R | 
 | 1076 | function<_R(_A0)>::operator()(_A0 __a0) const | 
 | 1077 | { | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1078 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1079 |     if (__f_ == 0) | 
 | 1080 |         throw bad_function_call(); | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1081 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1082 |     return (*__f_)(__a0); | 
 | 1083 | } | 
 | 1084 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1085 | #ifndef _LIBCPP_NO_RTTI | 
 | 1086 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1087 | template<class _R, class _A0> | 
 | 1088 | const std::type_info& | 
 | 1089 | function<_R(_A0)>::target_type() const | 
 | 1090 | { | 
 | 1091 |     if (__f_ == 0) | 
 | 1092 |         return typeid(void); | 
 | 1093 |     return __f_->target_type(); | 
 | 1094 | } | 
 | 1095 |  | 
 | 1096 | template<class _R, class _A0> | 
 | 1097 | template <typename _T> | 
 | 1098 | _T* | 
 | 1099 | function<_R(_A0)>::target() | 
 | 1100 | { | 
 | 1101 |     if (__f_ == 0) | 
 | 1102 |         return (_T*)0; | 
 | 1103 |     return (_T*)__f_->target(typeid(_T)); | 
 | 1104 | } | 
 | 1105 |  | 
 | 1106 | template<class _R, class _A0> | 
 | 1107 | template <typename _T> | 
 | 1108 | const _T* | 
 | 1109 | function<_R(_A0)>::target() const | 
 | 1110 | { | 
 | 1111 |     if (__f_ == 0) | 
 | 1112 |         return (const _T*)0; | 
 | 1113 |     return (const _T*)__f_->target(typeid(_T)); | 
 | 1114 | } | 
 | 1115 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1116 | #endif | 
 | 1117 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1118 | template<class _R, class _A0, class _A1> | 
 | 1119 | class function<_R(_A0, _A1)> | 
 | 1120 |     : public binary_function<_A0, _A1, _R> | 
 | 1121 | { | 
 | 1122 |     typedef __function::__base<_R(_A0, _A1)> __base; | 
 | 1123 |     aligned_storage<3*sizeof(void*)>::type __buf_; | 
 | 1124 |     __base* __f_; | 
 | 1125 |  | 
 | 1126 |     template <class _F> | 
 | 1127 |         static bool __not_null(const _F&) {return true;} | 
 | 1128 |     template <class _R2, class _B0, class _B1> | 
 | 1129 |         static bool __not_null(_R2 (*__p)(_B0, _B1)) {return __p;} | 
 | 1130 |     template <class _R2, class _C, class _B1> | 
 | 1131 |         static bool __not_null(_R2 (_C::*__p)(_B1)) {return __p;} | 
 | 1132 |     template <class _R2, class _C, class _B1> | 
 | 1133 |         static bool __not_null(_R2 (_C::*__p)(_B1) const) {return __p;} | 
 | 1134 |     template <class _R2, class _C, class _B1> | 
 | 1135 |         static bool __not_null(_R2 (_C::*__p)(_B1) volatile) {return __p;} | 
 | 1136 |     template <class _R2, class _C, class _B1> | 
 | 1137 |         static bool __not_null(_R2 (_C::*__p)(_B1) const volatile) {return __p;} | 
 | 1138 |     template <class _R2, class _B0, class _B1> | 
 | 1139 |         static bool __not_null(const function<_R(_B0, _B1)>& __p) {return __p;} | 
 | 1140 | public: | 
 | 1141 |     typedef _R result_type; | 
 | 1142 |  | 
 | 1143 |     // 20.7.16.2.1, construct/copy/destroy: | 
 | 1144 |     explicit function() : __f_(0) {} | 
 | 1145 |     function(nullptr_t) : __f_(0) {} | 
 | 1146 |     function(const function&); | 
 | 1147 |     template<class _F> | 
 | 1148 |       function(_F, | 
 | 1149 |                typename enable_if<!is_integral<_F>::value>::type* = 0); | 
 | 1150 |  | 
 | 1151 | //     template<class _Alloc> | 
 | 1152 | //       function(allocator_arg_t, const _Alloc&); | 
 | 1153 | //     template<Allocator Alloc> | 
 | 1154 | //       function(allocator_arg_t, const Alloc&, nullptr_t); | 
 | 1155 | //     template<Allocator Alloc> | 
 | 1156 | //       function(allocator_arg_t, const Alloc&, const function&); | 
 | 1157 | //     template<Allocator Alloc> | 
 | 1158 | //       function(allocator_arg_t, const Alloc&, function&&); | 
 | 1159 | //     template<class F, Allocator Alloc> | 
 | 1160 | //       function(allocator_arg_t, const Alloc&, F); | 
 | 1161 |  | 
 | 1162 |     function& operator=(const function&); | 
 | 1163 |     function& operator=(nullptr_t); | 
 | 1164 |     template<class _F> | 
 | 1165 |       typename enable_if | 
 | 1166 |       < | 
 | 1167 |         !is_integral<_F>::value, | 
 | 1168 |         function& | 
 | 1169 |       >::type | 
 | 1170 |       operator=(_F); | 
 | 1171 |  | 
 | 1172 |     ~function(); | 
 | 1173 |  | 
 | 1174 |     // 20.7.16.2.2, function modifiers: | 
 | 1175 |     void swap(function&); | 
 | 1176 | //     template<class _F, class _Alloc> | 
 | 1177 | //       void assign(_F, const _Alloc&); | 
 | 1178 |  | 
 | 1179 |     // 20.7.16.2.3, function capacity: | 
 | 1180 |     operator bool() const {return __f_;} | 
 | 1181 |  | 
 | 1182 | private: | 
 | 1183 |     // deleted overloads close possible hole in the type system | 
 | 1184 |     template<class _R2, class _B0, class _B1> | 
 | 1185 |       bool operator==(const function<_R2(_B0, _B1)>&);// = delete; | 
 | 1186 |     template<class _R2, class _B0, class _B1> | 
 | 1187 |       bool operator!=(const function<_R2(_B0, _B1)>&);// = delete; | 
 | 1188 | public: | 
 | 1189 |     // 20.7.16.2.4, function invocation: | 
 | 1190 |     _R operator()(_A0, _A1) const; | 
 | 1191 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1192 | #ifndef _LIBCPP_NO_RTTI | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1193 |     // 20.7.16.2.5, function target access: | 
 | 1194 |     const std::type_info& target_type() const; | 
 | 1195 |     template <typename _T> _T* target(); | 
 | 1196 |     template <typename _T> const _T* target() const; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1197 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1198 | }; | 
 | 1199 |  | 
 | 1200 | template<class _R, class _A0, class _A1> | 
 | 1201 | function<_R(_A0, _A1)>::function(const function& __f) | 
 | 1202 | { | 
 | 1203 |     if (__f.__f_ == 0) | 
 | 1204 |         __f_ = 0; | 
 | 1205 |     else if (__f.__f_ == (const __base*)&__f.__buf_) | 
 | 1206 |     { | 
 | 1207 |         __f_ = (__base*)&__buf_; | 
 | 1208 |         __f.__f_->__clone(__f_); | 
 | 1209 |     } | 
 | 1210 |     else | 
 | 1211 |         __f_ = __f.__f_->__clone(); | 
 | 1212 | } | 
 | 1213 |  | 
 | 1214 | template<class _R, class _A0, class _A1> | 
 | 1215 | template <class _F> | 
 | 1216 | function<_R(_A0, _A1)>::function(_F __f, | 
 | 1217 |                                      typename enable_if<!is_integral<_F>::value>::type*) | 
 | 1218 |     : __f_(0) | 
 | 1219 | { | 
 | 1220 |     if (__not_null(__f)) | 
 | 1221 |     { | 
 | 1222 |         typedef __function::__func<_F, allocator<_F>, _R(_A0, _A1)> _FF; | 
 | 1223 |         if (sizeof(_FF) <= sizeof(__buf_)) | 
 | 1224 |         { | 
 | 1225 |             __f_ = (__base*)&__buf_; | 
 | 1226 |             ::new (__f_) _FF(__f); | 
 | 1227 |         } | 
 | 1228 |         else | 
 | 1229 |         { | 
 | 1230 |             typedef allocator<_FF> _A; | 
 | 1231 |             _A __a; | 
 | 1232 |             typedef __allocator_destructor<_A> _D; | 
 | 1233 |             unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); | 
 | 1234 |             ::new (__hold.get()) _FF(__f, allocator<_F>(__a)); | 
 | 1235 |             __f_ = __hold.release(); | 
 | 1236 |         } | 
 | 1237 |     } | 
 | 1238 | } | 
 | 1239 |  | 
 | 1240 | template<class _R, class _A0, class _A1> | 
 | 1241 | function<_R(_A0, _A1)>& | 
 | 1242 | function<_R(_A0, _A1)>::operator=(const function& __f) | 
 | 1243 | { | 
 | 1244 |     function(__f).swap(*this); | 
 | 1245 |     return *this; | 
 | 1246 | } | 
 | 1247 |  | 
 | 1248 | template<class _R, class _A0, class _A1> | 
 | 1249 | function<_R(_A0, _A1)>& | 
 | 1250 | function<_R(_A0, _A1)>::operator=(nullptr_t) | 
 | 1251 | { | 
 | 1252 |     if (__f_ == (__base*)&__buf_) | 
 | 1253 |         __f_->destroy(); | 
 | 1254 |     else if (__f_) | 
 | 1255 |         __f_->destroy_deallocate(); | 
 | 1256 |     __f_ = 0; | 
 | 1257 | } | 
 | 1258 |  | 
 | 1259 | template<class _R, class _A0, class _A1> | 
 | 1260 | template <class _F> | 
 | 1261 | typename enable_if | 
 | 1262 | < | 
 | 1263 |     !is_integral<_F>::value, | 
 | 1264 |     function<_R(_A0, _A1)>& | 
 | 1265 | >::type | 
 | 1266 | function<_R(_A0, _A1)>::operator=(_F __f) | 
 | 1267 | { | 
 | 1268 |     function(_STD::move(__f)).swap(*this); | 
 | 1269 |     return *this; | 
 | 1270 | } | 
 | 1271 |  | 
 | 1272 | template<class _R, class _A0, class _A1> | 
 | 1273 | function<_R(_A0, _A1)>::~function() | 
 | 1274 | { | 
 | 1275 |     if (__f_ == (__base*)&__buf_) | 
 | 1276 |         __f_->destroy(); | 
 | 1277 |     else if (__f_) | 
 | 1278 |         __f_->destroy_deallocate(); | 
 | 1279 | } | 
 | 1280 |  | 
 | 1281 | template<class _R, class _A0, class _A1> | 
 | 1282 | void | 
 | 1283 | function<_R(_A0, _A1)>::swap(function& __f) | 
 | 1284 | { | 
 | 1285 |     if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) | 
 | 1286 |     { | 
 | 1287 |         typename aligned_storage<sizeof(__buf_)>::type __tempbuf; | 
 | 1288 |         __base* __t = (__base*)&__tempbuf; | 
 | 1289 |         __f_->__clone(__t); | 
 | 1290 |         __f_->destroy(); | 
 | 1291 |         __f_ = 0; | 
 | 1292 |         __f.__f_->__clone((__base*)&__buf_); | 
 | 1293 |         __f.__f_->destroy(); | 
 | 1294 |         __f.__f_ = 0; | 
 | 1295 |         __f_ = (__base*)&__buf_; | 
 | 1296 |         __t->__clone((__base*)&__f.__buf_); | 
 | 1297 |         __t->destroy(); | 
 | 1298 |         __f.__f_ = (__base*)&__f.__buf_; | 
 | 1299 |     } | 
 | 1300 |     else if (__f_ == (__base*)&__buf_) | 
 | 1301 |     { | 
 | 1302 |         __f_->__clone((__base*)&__f.__buf_); | 
 | 1303 |         __f_->destroy(); | 
 | 1304 |         __f_ = __f.__f_; | 
 | 1305 |         __f.__f_ = (__base*)&__f.__buf_; | 
 | 1306 |     } | 
 | 1307 |     else if (__f.__f_ == (__base*)&__f.__buf_) | 
 | 1308 |     { | 
 | 1309 |         __f.__f_->__clone((__base*)&__buf_); | 
 | 1310 |         __f.__f_->destroy(); | 
 | 1311 |         __f.__f_ = __f_; | 
 | 1312 |         __f_ = (__base*)&__buf_; | 
 | 1313 |     } | 
 | 1314 |     else | 
 | 1315 |         _STD::swap(__f_, __f.__f_); | 
 | 1316 | } | 
 | 1317 |  | 
 | 1318 | template<class _R, class _A0, class _A1> | 
 | 1319 | _R | 
 | 1320 | function<_R(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const | 
 | 1321 | { | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1322 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1323 |     if (__f_ == 0) | 
 | 1324 |         throw bad_function_call(); | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1325 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1326 |     return (*__f_)(__a0, __a1); | 
 | 1327 | } | 
 | 1328 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1329 | #ifndef _LIBCPP_NO_RTTI | 
 | 1330 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1331 | template<class _R, class _A0, class _A1> | 
 | 1332 | const std::type_info& | 
 | 1333 | function<_R(_A0, _A1)>::target_type() const | 
 | 1334 | { | 
 | 1335 |     if (__f_ == 0) | 
 | 1336 |         return typeid(void); | 
 | 1337 |     return __f_->target_type(); | 
 | 1338 | } | 
 | 1339 |  | 
 | 1340 | template<class _R, class _A0, class _A1> | 
 | 1341 | template <typename _T> | 
 | 1342 | _T* | 
 | 1343 | function<_R(_A0, _A1)>::target() | 
 | 1344 | { | 
 | 1345 |     if (__f_ == 0) | 
 | 1346 |         return (_T*)0; | 
 | 1347 |     return (_T*)__f_->target(typeid(_T)); | 
 | 1348 | } | 
 | 1349 |  | 
 | 1350 | template<class _R, class _A0, class _A1> | 
 | 1351 | template <typename _T> | 
 | 1352 | const _T* | 
 | 1353 | function<_R(_A0, _A1)>::target() const | 
 | 1354 | { | 
 | 1355 |     if (__f_ == 0) | 
 | 1356 |         return (const _T*)0; | 
 | 1357 |     return (const _T*)__f_->target(typeid(_T)); | 
 | 1358 | } | 
 | 1359 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1360 | #endif | 
 | 1361 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1362 | template<class _R, class _A0, class _A1, class _A2> | 
 | 1363 | class function<_R(_A0, _A1, _A2)> | 
 | 1364 | { | 
 | 1365 |     typedef __function::__base<_R(_A0, _A1, _A2)> __base; | 
 | 1366 |     aligned_storage<3*sizeof(void*)>::type __buf_; | 
 | 1367 |     __base* __f_; | 
 | 1368 |  | 
 | 1369 |     template <class _F> | 
 | 1370 |         static bool __not_null(const _F&) {return true;} | 
 | 1371 |     template <class _R2, class _B0, class _B1, class _B2> | 
 | 1372 |         static bool __not_null(_R2 (*__p)(_B0, _B1, _B2)) {return __p;} | 
 | 1373 |     template <class _R2, class _C, class _B1, class _B2> | 
 | 1374 |         static bool __not_null(_R2 (_C::*__p)(_B1, _B2)) {return __p;} | 
 | 1375 |     template <class _R2, class _C, class _B1, class _B2> | 
 | 1376 |         static bool __not_null(_R2 (_C::*__p)(_B1, _B2) const) {return __p;} | 
 | 1377 |     template <class _R2, class _C, class _B1, class _B2> | 
 | 1378 |         static bool __not_null(_R2 (_C::*__p)(_B1, _B2) volatile) {return __p;} | 
 | 1379 |     template <class _R2, class _C, class _B1, class _B2> | 
 | 1380 |         static bool __not_null(_R2 (_C::*__p)(_B1, _B2) const volatile) {return __p;} | 
 | 1381 |     template <class _R2, class _B0, class _B1, class _B2> | 
 | 1382 |         static bool __not_null(const function<_R(_B0, _B1, _B2)>& __p) {return __p;} | 
 | 1383 | public: | 
 | 1384 |     typedef _R result_type; | 
 | 1385 |  | 
 | 1386 |     // 20.7.16.2.1, construct/copy/destroy: | 
 | 1387 |     explicit function() : __f_(0) {} | 
 | 1388 |     function(nullptr_t) : __f_(0) {} | 
 | 1389 |     function(const function&); | 
 | 1390 |     template<class _F> | 
 | 1391 |       function(_F, | 
 | 1392 |                typename enable_if<!is_integral<_F>::value>::type* = 0); | 
 | 1393 |  | 
 | 1394 | //     template<class _Alloc> | 
 | 1395 | //       function(allocator_arg_t, const _Alloc&); | 
 | 1396 | //     template<Allocator Alloc> | 
 | 1397 | //       function(allocator_arg_t, const Alloc&, nullptr_t); | 
 | 1398 | //     template<Allocator Alloc> | 
 | 1399 | //       function(allocator_arg_t, const Alloc&, const function&); | 
 | 1400 | //     template<Allocator Alloc> | 
 | 1401 | //       function(allocator_arg_t, const Alloc&, function&&); | 
 | 1402 | //     template<class F, Allocator Alloc> | 
 | 1403 | //       function(allocator_arg_t, const Alloc&, F); | 
 | 1404 |  | 
 | 1405 |     function& operator=(const function&); | 
 | 1406 |     function& operator=(nullptr_t); | 
 | 1407 |     template<class _F> | 
 | 1408 |       typename enable_if | 
 | 1409 |       < | 
 | 1410 |         !is_integral<_F>::value, | 
 | 1411 |         function& | 
 | 1412 |       >::type | 
 | 1413 |       operator=(_F); | 
 | 1414 |  | 
 | 1415 |     ~function(); | 
 | 1416 |  | 
 | 1417 |     // 20.7.16.2.2, function modifiers: | 
 | 1418 |     void swap(function&); | 
 | 1419 | //     template<class _F, class _Alloc> | 
 | 1420 | //       void assign(_F, const _Alloc&); | 
 | 1421 |  | 
 | 1422 |     // 20.7.16.2.3, function capacity: | 
 | 1423 |     operator bool() const {return __f_;} | 
 | 1424 |  | 
 | 1425 | private: | 
 | 1426 |     // deleted overloads close possible hole in the type system | 
 | 1427 |     template<class _R2, class _B0, class _B1, class _B2> | 
 | 1428 |       bool operator==(const function<_R2(_B0, _B1, _B2)>&);// = delete; | 
 | 1429 |     template<class _R2, class _B0, class _B1, class _B2> | 
 | 1430 |       bool operator!=(const function<_R2(_B0, _B1, _B2)>&);// = delete; | 
 | 1431 | public: | 
 | 1432 |     // 20.7.16.2.4, function invocation: | 
 | 1433 |     _R operator()(_A0, _A1, _A2) const; | 
 | 1434 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1435 | #ifndef _LIBCPP_NO_RTTI | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1436 |     // 20.7.16.2.5, function target access: | 
 | 1437 |     const std::type_info& target_type() const; | 
 | 1438 |     template <typename _T> _T* target(); | 
 | 1439 |     template <typename _T> const _T* target() const; | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1440 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1441 | }; | 
 | 1442 |  | 
 | 1443 | template<class _R, class _A0, class _A1, class _A2> | 
 | 1444 | function<_R(_A0, _A1, _A2)>::function(const function& __f) | 
 | 1445 | { | 
 | 1446 |     if (__f.__f_ == 0) | 
 | 1447 |         __f_ = 0; | 
 | 1448 |     else if (__f.__f_ == (const __base*)&__f.__buf_) | 
 | 1449 |     { | 
 | 1450 |         __f_ = (__base*)&__buf_; | 
 | 1451 |         __f.__f_->__clone(__f_); | 
 | 1452 |     } | 
 | 1453 |     else | 
 | 1454 |         __f_ = __f.__f_->__clone(); | 
 | 1455 | } | 
 | 1456 |  | 
 | 1457 | template<class _R, class _A0, class _A1, class _A2> | 
 | 1458 | template <class _F> | 
 | 1459 | function<_R(_A0, _A1, _A2)>::function(_F __f, | 
 | 1460 |                                      typename enable_if<!is_integral<_F>::value>::type*) | 
 | 1461 |     : __f_(0) | 
 | 1462 | { | 
 | 1463 |     if (__not_null(__f)) | 
 | 1464 |     { | 
 | 1465 |         typedef __function::__func<_F, allocator<_F>, _R(_A0, _A1, _A2)> _FF; | 
 | 1466 |         if (sizeof(_FF) <= sizeof(__buf_)) | 
 | 1467 |         { | 
 | 1468 |             __f_ = (__base*)&__buf_; | 
 | 1469 |             ::new (__f_) _FF(__f); | 
 | 1470 |         } | 
 | 1471 |         else | 
 | 1472 |         { | 
 | 1473 |             typedef allocator<_FF> _A; | 
 | 1474 |             _A __a; | 
 | 1475 |             typedef __allocator_destructor<_A> _D; | 
 | 1476 |             unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1)); | 
 | 1477 |             ::new (__hold.get()) _FF(__f, allocator<_F>(__a)); | 
 | 1478 |             __f_ = __hold.release(); | 
 | 1479 |         } | 
 | 1480 |     } | 
 | 1481 | } | 
 | 1482 |  | 
 | 1483 | template<class _R, class _A0, class _A1, class _A2> | 
 | 1484 | function<_R(_A0, _A1, _A2)>& | 
 | 1485 | function<_R(_A0, _A1, _A2)>::operator=(const function& __f) | 
 | 1486 | { | 
 | 1487 |     function(__f).swap(*this); | 
 | 1488 |     return *this; | 
 | 1489 | } | 
 | 1490 |  | 
 | 1491 | template<class _R, class _A0, class _A1, class _A2> | 
 | 1492 | function<_R(_A0, _A1, _A2)>& | 
 | 1493 | function<_R(_A0, _A1, _A2)>::operator=(nullptr_t) | 
 | 1494 | { | 
 | 1495 |     if (__f_ == (__base*)&__buf_) | 
 | 1496 |         __f_->destroy(); | 
 | 1497 |     else if (__f_) | 
 | 1498 |         __f_->destroy_deallocate(); | 
 | 1499 |     __f_ = 0; | 
 | 1500 | } | 
 | 1501 |  | 
 | 1502 | template<class _R, class _A0, class _A1, class _A2> | 
 | 1503 | template <class _F> | 
 | 1504 | typename enable_if | 
 | 1505 | < | 
 | 1506 |     !is_integral<_F>::value, | 
 | 1507 |     function<_R(_A0, _A1, _A2)>& | 
 | 1508 | >::type | 
 | 1509 | function<_R(_A0, _A1, _A2)>::operator=(_F __f) | 
 | 1510 | { | 
 | 1511 |     function(_STD::move(__f)).swap(*this); | 
 | 1512 |     return *this; | 
 | 1513 | } | 
 | 1514 |  | 
 | 1515 | template<class _R, class _A0, class _A1, class _A2> | 
 | 1516 | function<_R(_A0, _A1, _A2)>::~function() | 
 | 1517 | { | 
 | 1518 |     if (__f_ == (__base*)&__buf_) | 
 | 1519 |         __f_->destroy(); | 
 | 1520 |     else if (__f_) | 
 | 1521 |         __f_->destroy_deallocate(); | 
 | 1522 | } | 
 | 1523 |  | 
 | 1524 | template<class _R, class _A0, class _A1, class _A2> | 
 | 1525 | void | 
 | 1526 | function<_R(_A0, _A1, _A2)>::swap(function& __f) | 
 | 1527 | { | 
 | 1528 |     if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) | 
 | 1529 |     { | 
 | 1530 |         typename aligned_storage<sizeof(__buf_)>::type __tempbuf; | 
 | 1531 |         __base* __t = (__base*)&__tempbuf; | 
 | 1532 |         __f_->__clone(__t); | 
 | 1533 |         __f_->destroy(); | 
 | 1534 |         __f_ = 0; | 
 | 1535 |         __f.__f_->__clone((__base*)&__buf_); | 
 | 1536 |         __f.__f_->destroy(); | 
 | 1537 |         __f.__f_ = 0; | 
 | 1538 |         __f_ = (__base*)&__buf_; | 
 | 1539 |         __t->__clone((__base*)&__f.__buf_); | 
 | 1540 |         __t->destroy(); | 
 | 1541 |         __f.__f_ = (__base*)&__f.__buf_; | 
 | 1542 |     } | 
 | 1543 |     else if (__f_ == (__base*)&__buf_) | 
 | 1544 |     { | 
 | 1545 |         __f_->__clone((__base*)&__f.__buf_); | 
 | 1546 |         __f_->destroy(); | 
 | 1547 |         __f_ = __f.__f_; | 
 | 1548 |         __f.__f_ = (__base*)&__f.__buf_; | 
 | 1549 |     } | 
 | 1550 |     else if (__f.__f_ == (__base*)&__f.__buf_) | 
 | 1551 |     { | 
 | 1552 |         __f.__f_->__clone((__base*)&__buf_); | 
 | 1553 |         __f.__f_->destroy(); | 
 | 1554 |         __f.__f_ = __f_; | 
 | 1555 |         __f_ = (__base*)&__buf_; | 
 | 1556 |     } | 
 | 1557 |     else | 
 | 1558 |         _STD::swap(__f_, __f.__f_); | 
 | 1559 | } | 
 | 1560 |  | 
 | 1561 | template<class _R, class _A0, class _A1, class _A2> | 
 | 1562 | _R | 
 | 1563 | function<_R(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const | 
 | 1564 | { | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1565 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1566 |     if (__f_ == 0) | 
 | 1567 |         throw bad_function_call(); | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1568 | #endif | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1569 |     return (*__f_)(__a0, __a1, __a2); | 
 | 1570 | } | 
 | 1571 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1572 | #ifndef _LIBCPP_NO_RTTI | 
 | 1573 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1574 | template<class _R, class _A0, class _A1, class _A2> | 
 | 1575 | const std::type_info& | 
 | 1576 | function<_R(_A0, _A1, _A2)>::target_type() const | 
 | 1577 | { | 
 | 1578 |     if (__f_ == 0) | 
 | 1579 |         return typeid(void); | 
 | 1580 |     return __f_->target_type(); | 
 | 1581 | } | 
 | 1582 |  | 
 | 1583 | template<class _R, class _A0, class _A1, class _A2> | 
 | 1584 | template <typename _T> | 
 | 1585 | _T* | 
 | 1586 | function<_R(_A0, _A1, _A2)>::target() | 
 | 1587 | { | 
 | 1588 |     if (__f_ == 0) | 
 | 1589 |         return (_T*)0; | 
 | 1590 |     return (_T*)__f_->target(typeid(_T)); | 
 | 1591 | } | 
 | 1592 |  | 
 | 1593 | template<class _R, class _A0, class _A1, class _A2> | 
 | 1594 | template <typename _T> | 
 | 1595 | const _T* | 
 | 1596 | function<_R(_A0, _A1, _A2)>::target() const | 
 | 1597 | { | 
 | 1598 |     if (__f_ == 0) | 
 | 1599 |         return (const _T*)0; | 
 | 1600 |     return (const _T*)__f_->target(typeid(_T)); | 
 | 1601 | } | 
 | 1602 |  | 
| Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame^] | 1603 | #endif | 
 | 1604 |  | 
| Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1605 | template <class _F>  | 
 | 1606 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1607 | bool | 
 | 1608 | operator==(const function<_F>& __f, nullptr_t) {return !__f;} | 
 | 1609 |  | 
 | 1610 | template <class _F>  | 
 | 1611 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1612 | bool | 
 | 1613 | operator==(nullptr_t, const function<_F>& __f) {return !__f;} | 
 | 1614 |  | 
 | 1615 | template <class _F>  | 
 | 1616 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1617 | bool | 
 | 1618 | operator!=(const function<_F>& __f, nullptr_t) {return (bool)__f;} | 
 | 1619 |  | 
 | 1620 | template <class _F>  | 
 | 1621 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1622 | bool | 
 | 1623 | operator!=(nullptr_t, const function<_F>& __f) {return (bool)__f;} | 
 | 1624 |  | 
 | 1625 | template <class _F>  | 
 | 1626 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1627 | void | 
 | 1628 | swap(function<_F>& __x, function<_F>& __y) | 
 | 1629 | {return __x.swap(__y);} | 
 | 1630 |  | 
 | 1631 | template<class _Tp> struct __is_bind_expression : public false_type {}; | 
 | 1632 | template<class _Tp> struct is_bind_expression | 
 | 1633 |     : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; | 
 | 1634 |  | 
 | 1635 | template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; | 
 | 1636 | template<class _Tp> struct is_placeholder | 
 | 1637 |     : public __is_placeholder<typename remove_cv<_Tp>::type> {}; | 
 | 1638 |  | 
 | 1639 | namespace placeholders | 
 | 1640 | { | 
 | 1641 |  | 
 | 1642 | template <int _N> struct __ph {}; | 
 | 1643 |  | 
 | 1644 | extern __ph<1>   _1; | 
 | 1645 | extern __ph<2>   _2; | 
 | 1646 | extern __ph<3>   _3; | 
 | 1647 | extern __ph<4>   _4; | 
 | 1648 | extern __ph<5>   _5; | 
 | 1649 | extern __ph<6>   _6; | 
 | 1650 | extern __ph<7>   _7; | 
 | 1651 | extern __ph<8>   _8; | 
 | 1652 | extern __ph<9>   _9; | 
 | 1653 | extern __ph<10> _10; | 
 | 1654 |  | 
 | 1655 | }  // placeholders | 
 | 1656 |  | 
 | 1657 | template<int _N> | 
 | 1658 | struct __is_placeholder<placeholders::__ph<_N> > | 
 | 1659 |     : public integral_constant<int, _N> {}; | 
 | 1660 |  | 
 | 1661 | template <class _Tp, class _Uj> | 
 | 1662 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1663 | _Tp& | 
 | 1664 | __mu(reference_wrapper<_Tp> __t, _Uj&) | 
 | 1665 | { | 
 | 1666 |     return __t.get(); | 
 | 1667 | } | 
 | 1668 | /* | 
 | 1669 | template <bool _IsBindExpr, class _Ti, class ..._Uj> | 
 | 1670 | struct __mu_return1 {}; | 
 | 1671 |  | 
 | 1672 | template <class _Ti, class ..._Uj> | 
 | 1673 | struct __mu_return1<true, _Ti, _Uj...> | 
 | 1674 | { | 
 | 1675 |     typedef typename result_of<_Ti(_Uj...)>::type type; | 
 | 1676 | }; | 
 | 1677 |  | 
 | 1678 |  | 
 | 1679 | template <class _Ti, class ..._Uj, size_t ..._Indx> | 
 | 1680 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1681 | typename __mu_return1<true, _Ti, _Uj...>::type | 
 | 1682 | __mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>) | 
 | 1683 | { | 
 | 1684 |     __ti(_STD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj))...); | 
 | 1685 | } | 
 | 1686 |  | 
 | 1687 | template <class _Ti, class ..._Uj> | 
 | 1688 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1689 | typename enable_if | 
 | 1690 | < | 
 | 1691 |     is_bind_expression<_Ti>::value, | 
 | 1692 |     typename __mu_return1<is_bind_expression<_Ti>::value, _Ti, _Uj...>::type | 
 | 1693 | >::type | 
 | 1694 | __mu(_Ti& __ti, tuple<_Uj...>& __uj) | 
 | 1695 | { | 
 | 1696 |     typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; | 
 | 1697 |     return  __mu_expand(__ti, __uj, __indices()); | 
 | 1698 | } | 
 | 1699 |  | 
 | 1700 | template <bool IsPh, class _Ti, class _Uj> | 
 | 1701 | struct __mu_return2 {}; | 
 | 1702 |  | 
 | 1703 | template <class _Ti, class _Uj> | 
 | 1704 | struct __mu_return2<true, _Ti, _Uj> | 
 | 1705 | { | 
 | 1706 |     typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; | 
 | 1707 | }; | 
 | 1708 |  | 
 | 1709 | template <class _Ti, class _Uj> | 
 | 1710 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1711 | typename enable_if | 
 | 1712 | < | 
 | 1713 |     0 < is_placeholder<_Ti>::value, | 
 | 1714 |     typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type | 
 | 1715 | >::type | 
 | 1716 | __mu(_Ti&, _Uj& __uj) | 
 | 1717 | { | 
 | 1718 |     const size_t _Indx = is_placeholder<_Ti>::value - 1; | 
 | 1719 |     // compiler bug workaround | 
 | 1720 |     typename tuple_element<_Indx, _Uj>::type __t = get<_Indx>(__uj); | 
 | 1721 |     return __t; | 
 | 1722 | //    return _STD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj)); | 
 | 1723 | } | 
 | 1724 |  | 
 | 1725 | template <class _Ti, class _Uj> | 
 | 1726 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1727 | typename enable_if | 
 | 1728 | < | 
 | 1729 |     !is_bind_expression<_Ti>::value && | 
 | 1730 |     is_placeholder<_Ti>::value == 0 && | 
 | 1731 |     !__is_reference_wrapper<_Ti>::value, | 
 | 1732 |     _Ti& | 
 | 1733 | >::type | 
 | 1734 | __mu(_Ti& __ti, _Uj& __uj) | 
 | 1735 | { | 
 | 1736 |     return __ti; | 
 | 1737 | } | 
 | 1738 |  | 
 | 1739 | template <class _Ti, bool IsBindEx, bool IsPh, class _TupleUj> | 
 | 1740 | struct ____mu_return; | 
 | 1741 |  | 
 | 1742 | template <class _Ti, class ..._Uj> | 
 | 1743 | struct ____mu_return<_Ti, true, false, tuple<_Uj...> > | 
 | 1744 | { | 
 | 1745 |     typedef typename result_of<_Ti(_Uj...)>::type type; | 
 | 1746 | }; | 
 | 1747 |  | 
 | 1748 | template <class _Ti, class _TupleUj> | 
 | 1749 | struct ____mu_return<_Ti, false, true, _TupleUj> | 
 | 1750 | { | 
 | 1751 |     typedef typename tuple_element<is_placeholder<_Ti>::value - 1, | 
 | 1752 |                                    _TupleUj>::type&& type; | 
 | 1753 | }; | 
 | 1754 |  | 
 | 1755 | template <class _Ti, class _TupleUj> | 
 | 1756 | struct ____mu_return<_Ti, false, false, _TupleUj> | 
 | 1757 | { | 
 | 1758 |     typedef _Ti& type; | 
 | 1759 | }; | 
 | 1760 |  | 
 | 1761 | template <class _Ti, class _TupleUj> | 
 | 1762 | struct __mu_return | 
 | 1763 |     : public ____mu_return<_Ti, | 
 | 1764 |                            is_bind_expression<_Ti>::value, | 
 | 1765 |                            0 < is_placeholder<_Ti>::value, | 
 | 1766 |                            _TupleUj> | 
 | 1767 | { | 
 | 1768 | }; | 
 | 1769 |  | 
 | 1770 | template <class _Ti, class _TupleUj> | 
 | 1771 | struct __mu_return<reference_wrapper<_Ti>, _TupleUj> | 
 | 1772 | { | 
 | 1773 |     typedef _Ti& type; | 
 | 1774 | }; | 
 | 1775 |  | 
 | 1776 | template <class _F, class _BoundArgs, class _TupleUj> | 
 | 1777 | struct __bind_return; | 
 | 1778 |  | 
 | 1779 | template <class _F, class ..._BoundArgs, class _TupleUj> | 
 | 1780 | struct __bind_return<_F, tuple<_BoundArgs...>, _TupleUj> | 
 | 1781 | { | 
 | 1782 |     typedef typename __ref_return | 
 | 1783 |     < | 
 | 1784 |         _F&, | 
 | 1785 |         typename __mu_return | 
 | 1786 |         < | 
 | 1787 |             _BoundArgs, | 
 | 1788 |             _TupleUj | 
 | 1789 |         >::type... | 
 | 1790 |     >::type type; | 
 | 1791 | }; | 
 | 1792 |  | 
 | 1793 | template <class _F, class ..._BoundArgs, class _TupleUj> | 
 | 1794 | struct __bind_return<_F, const tuple<_BoundArgs...>, _TupleUj> | 
 | 1795 | { | 
 | 1796 |     typedef typename __ref_return | 
 | 1797 |     < | 
 | 1798 |         _F&, | 
 | 1799 |         typename __mu_return | 
 | 1800 |         < | 
 | 1801 |             const _BoundArgs, | 
 | 1802 |             _TupleUj | 
 | 1803 |         >::type... | 
 | 1804 |     >::type type; | 
 | 1805 | }; | 
 | 1806 |  | 
 | 1807 | template <class _F, class _BoundArgs, size_t ..._Indx, class _Args> | 
 | 1808 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1809 | typename __bind_return<_F, _BoundArgs, _Args>::type | 
 | 1810 | __apply_functor(_F& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, | 
 | 1811 |                 _Args&& __args) | 
 | 1812 | { | 
 | 1813 |     return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...); | 
 | 1814 | } | 
 | 1815 |  | 
 | 1816 | template<class _F, class ..._BoundArgs>  | 
 | 1817 | class __bind | 
 | 1818 | { | 
 | 1819 |     _F __f_; | 
 | 1820 |     tuple<_BoundArgs...> __bound_args_; | 
 | 1821 |  | 
 | 1822 |     typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; | 
 | 1823 | public: | 
 | 1824 |     template <class _G, class ..._BA> | 
 | 1825 |       explicit __bind(_G&& __f, _BA&& ...__bound_args) | 
 | 1826 |         : __f_(_STD::forward<_G>(__f)), | 
 | 1827 |           __bound_args_(_STD::forward<_BA>(__bound_args)...) {} | 
 | 1828 |  | 
 | 1829 |     template <class ..._Args> | 
 | 1830 |         typename __bind_return<_F, tuple<_BoundArgs...>, tuple<_Args&&...> >::type | 
 | 1831 |         operator()(_Args&& ...__args) | 
 | 1832 |         { | 
 | 1833 |             // compiler bug workaround | 
 | 1834 |             return __apply_functor(__f_, __bound_args_, __indices(),  | 
 | 1835 |                                   tuple<_Args&&...>(__args...)); | 
 | 1836 |         } | 
 | 1837 |  | 
 | 1838 |     template <class ..._Args> | 
 | 1839 |         typename __bind_return<_F, tuple<_BoundArgs...>, tuple<_Args&&...> >::type | 
 | 1840 |         operator()(_Args&& ...__args) const | 
 | 1841 |         { | 
 | 1842 |             return __apply_functor(__f_, __bound_args_, __indices(),  | 
 | 1843 |                                    tuple<_Args&&...>(__args...)); | 
 | 1844 |         } | 
 | 1845 | }; | 
 | 1846 |  | 
 | 1847 | template<class _F, class ..._BoundArgs>  | 
 | 1848 | struct __is_bind_expression<__bind<_F, _BoundArgs...> > : public true_type {}; | 
 | 1849 |  | 
 | 1850 | template<class _R, class _F, class ..._BoundArgs>  | 
 | 1851 | class __bind_r | 
 | 1852 |     : public __bind<_F, _BoundArgs...> | 
 | 1853 | { | 
 | 1854 |     typedef __bind<_F, _BoundArgs...> base; | 
 | 1855 | public: | 
 | 1856 |     typedef _R result_type; | 
 | 1857 |  | 
 | 1858 |     template <class _G, class ..._BA> | 
 | 1859 |       explicit __bind_r(_G&& __f, _BA&& ...__bound_args) | 
 | 1860 |         : base(_STD::forward<_G>(__f), | 
 | 1861 |                _STD::forward<_BA>(__bound_args)...) {} | 
 | 1862 |  | 
 | 1863 |     template <class ..._Args> | 
 | 1864 |         result_type | 
 | 1865 |         operator()(_Args&& ...__args) | 
 | 1866 |         { | 
 | 1867 |             return base::operator()(_STD::forward<_Args>(__args)...); | 
 | 1868 |         } | 
 | 1869 |  | 
 | 1870 |     template <class ..._Args> | 
 | 1871 |         result_type | 
 | 1872 |         operator()(_Args&& ...__args) const | 
 | 1873 |         { | 
 | 1874 |             return base::operator()(_STD::forward<_Args>(__args)...); | 
 | 1875 |         } | 
 | 1876 | }; | 
 | 1877 |  | 
 | 1878 | template<class _R, class _F, class ..._BoundArgs>  | 
 | 1879 | struct __is_bind_expression<__bind_r<_R, _F, _BoundArgs...> > : public true_type {}; | 
 | 1880 |  | 
 | 1881 | template<class _F, class ..._BoundArgs>  | 
 | 1882 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1883 | __bind<typename decay<_F>::type, typename decay<_BoundArgs>::type...> | 
 | 1884 | bind(_F&& __f, _BoundArgs&&... __bound_args) | 
 | 1885 | { | 
 | 1886 |     typedef __bind<typename decay<_F>::type, typename decay<_BoundArgs>::type...> type; | 
 | 1887 |     return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...); | 
 | 1888 | } | 
 | 1889 |  | 
 | 1890 | template<class _R, class _F, class ..._BoundArgs>  | 
 | 1891 | inline _LIBCPP_INLINE_VISIBILITY | 
 | 1892 | __bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...> | 
 | 1893 | bind(_F&& __f, _BoundArgs&&... __bound_args) | 
 | 1894 | { | 
 | 1895 |     typedef __bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...> type; | 
 | 1896 |     return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...); | 
 | 1897 | } | 
 | 1898 | */ | 
 | 1899 |  | 
 | 1900 | #endif |