| 1 |
// PR c++/57102 |
| 2 |
// { dg-options "-O2 -fno-inline -fdump-final-insns -Wno-return-type" } |
| 3 |
// { dg-do compile { target c++11 } } |
| 4 |
// { dg-final cleanup-final-insns-dump } |
| 5 |
|
| 6 |
namespace std |
| 7 |
{ |
| 8 |
typedef __SIZE_TYPE__ size_t; |
| 9 |
typedef __PTRDIFF_TYPE__ ptrdiff_t; |
| 10 |
} |
| 11 |
extern "C++" { |
| 12 |
void* operator new(std::size_t, void* __p) noexcept; |
| 13 |
} |
| 14 |
namespace std __attribute__ ((__visibility__ ("default"))) |
| 15 |
{ |
| 16 |
template<typename _Tp, _Tp __v> |
| 17 |
struct integral_constant |
| 18 |
{ |
| 19 |
static constexpr _Tp value = __v; |
| 20 |
typedef integral_constant<_Tp, __v> type; |
| 21 |
}; |
| 22 |
typedef integral_constant<bool, true> true_type; |
| 23 |
typedef integral_constant<bool, false> false_type; |
| 24 |
template<bool, typename, typename> |
| 25 |
struct conditional; |
| 26 |
template<typename...> |
| 27 |
struct __or_; |
| 28 |
template<typename _B1, typename _B2> |
| 29 |
struct __or_<_B1, _B2> |
| 30 |
: public conditional<_B1::value, _B1, _B2>::type |
| 31 |
{}; |
| 32 |
template<typename _B1, typename _B2, typename _B3, typename... _Bn> |
| 33 |
struct __or_<_B1, _B2, _B3, _Bn...> |
| 34 |
: public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type |
| 35 |
{}; |
| 36 |
template<typename...> |
| 37 |
struct __and_; |
| 38 |
template<typename _B1, typename _B2> |
| 39 |
struct __and_<_B1, _B2> |
| 40 |
: public conditional<_B1::value, _B2, _B1>::type |
| 41 |
{}; |
| 42 |
template<typename _Pp> |
| 43 |
struct __not_ |
| 44 |
: public integral_constant<bool, !_Pp::value> |
| 45 |
{}; |
| 46 |
template<typename _Tp> |
| 47 |
struct __success_type |
| 48 |
{ typedef _Tp type; }; |
| 49 |
template<typename> |
| 50 |
struct remove_cv; |
| 51 |
template<typename> |
| 52 |
struct __is_void_helper |
| 53 |
: public false_type {}; |
| 54 |
template<typename _Tp> |
| 55 |
struct is_void |
| 56 |
: public __is_void_helper<typename remove_cv<_Tp>::type>::type |
| 57 |
{}; |
| 58 |
template<typename> |
| 59 |
struct __is_integral_helper |
| 60 |
: public true_type {}; |
| 61 |
template<typename _Tp> |
| 62 |
struct is_integral |
| 63 |
: public __is_integral_helper<typename remove_cv<_Tp>::type>::type |
| 64 |
{}; |
| 65 |
template<typename> |
| 66 |
struct is_array |
| 67 |
: public false_type {}; |
| 68 |
template<typename> |
| 69 |
struct is_lvalue_reference |
| 70 |
: public false_type {}; |
| 71 |
template<typename> |
| 72 |
struct is_rvalue_reference |
| 73 |
: public false_type {}; |
| 74 |
template<typename> |
| 75 |
struct __is_member_object_pointer_helper |
| 76 |
: public false_type {}; |
| 77 |
template<typename _Tp> |
| 78 |
struct is_member_object_pointer |
| 79 |
: public __is_member_object_pointer_helper< |
| 80 |
typename remove_cv<_Tp>::type>::type |
| 81 |
{}; |
| 82 |
template<typename> |
| 83 |
struct __is_member_function_pointer_helper |
| 84 |
: public false_type {}; |
| 85 |
template<typename _Tp> |
| 86 |
struct is_member_function_pointer |
| 87 |
: public __is_member_function_pointer_helper< |
| 88 |
typename remove_cv<_Tp>::type>::type |
| 89 |
{}; |
| 90 |
template<typename _Tp> |
| 91 |
struct is_enum |
| 92 |
: public integral_constant<bool, __is_enum(_Tp)> |
| 93 |
{}; |
| 94 |
template<typename> |
| 95 |
struct is_function |
| 96 |
: public false_type {}; |
| 97 |
template<typename _Tp> |
| 98 |
struct is_reference |
| 99 |
: public __or_<is_lvalue_reference<_Tp>, |
| 100 |
is_rvalue_reference<_Tp>>::type |
| 101 |
{}; |
| 102 |
template<typename _Tp> |
| 103 |
struct __is_member_pointer_helper |
| 104 |
: public false_type {}; |
| 105 |
template<typename _Tp> |
| 106 |
struct is_member_pointer |
| 107 |
: public __is_member_pointer_helper<typename remove_cv<_Tp>::type>::type |
| 108 |
{}; |
| 109 |
template<typename> |
| 110 |
struct is_const |
| 111 |
: public false_type {}; |
| 112 |
template<typename> |
| 113 |
struct is_volatile |
| 114 |
: public false_type {}; |
| 115 |
template<typename> |
| 116 |
struct add_rvalue_reference; |
| 117 |
template<typename _Tp> |
| 118 |
typename add_rvalue_reference<_Tp>::type declval() noexcept; |
| 119 |
struct __do_is_nary_constructible_impl |
| 120 |
{ |
| 121 |
template<typename _Tp, typename... _Args, typename |
| 122 |
= decltype(_Tp(declval<_Args>()...))> |
| 123 |
static true_type __test(int); |
| 124 |
}; |
| 125 |
template<typename _Tp, typename... _Args> |
| 126 |
struct __is_nary_constructible_impl |
| 127 |
: public __do_is_nary_constructible_impl |
| 128 |
{ |
| 129 |
typedef decltype(__test<_Tp, _Args...>(0)) type; |
| 130 |
}; |
| 131 |
template<typename _Tp, typename... _Args> |
| 132 |
struct __is_nary_constructible |
| 133 |
: public __is_nary_constructible_impl<_Tp, _Args...>::type |
| 134 |
{}; |
| 135 |
template<typename _Tp, typename... _Args> |
| 136 |
struct __is_constructible_impl |
| 137 |
: public __is_nary_constructible<_Tp, _Args...> |
| 138 |
{}; |
| 139 |
template<typename _Tp, typename... _Args> |
| 140 |
struct is_constructible |
| 141 |
: public __is_constructible_impl<_Tp, _Args...>::type |
| 142 |
{}; |
| 143 |
template<typename, typename> |
| 144 |
struct is_same |
| 145 |
: public true_type {}; |
| 146 |
template<typename _From, typename _To, |
| 147 |
bool = __or_<is_void<_From>, is_function<_To>, |
| 148 |
is_array<_To>>::value> |
| 149 |
struct __is_convertible_helper |
| 150 |
{ |
| 151 |
template<typename _To1> |
| 152 |
static void __test_aux(_To1); |
| 153 |
template<typename _From1, typename _To1, |
| 154 |
typename = decltype(__test_aux<_To1>(std::declval<_From1>()))> |
| 155 |
static true_type |
| 156 |
__test(int); |
| 157 |
typedef decltype(__test<_From, _To>(0)) type; |
| 158 |
}; |
| 159 |
template<typename _From, typename _To> |
| 160 |
struct is_convertible |
| 161 |
: public __is_convertible_helper<_From, _To>::type |
| 162 |
{}; |
| 163 |
template<typename _Tp> |
| 164 |
struct remove_const |
| 165 |
{ typedef _Tp type; }; |
| 166 |
template<typename _Tp> |
| 167 |
struct remove_volatile |
| 168 |
{ typedef _Tp type; }; |
| 169 |
template<typename _Tp> |
| 170 |
struct remove_cv |
| 171 |
{ |
| 172 |
typedef typename |
| 173 |
remove_const<typename remove_volatile<_Tp>::type>::type type; |
| 174 |
}; |
| 175 |
template<typename _Tp> |
| 176 |
struct remove_reference |
| 177 |
{ typedef _Tp type; }; |
| 178 |
template<typename _Tp> |
| 179 |
struct remove_reference<_Tp&> |
| 180 |
{ typedef _Tp type; }; |
| 181 |
template<typename _Tp, |
| 182 |
bool = __and_<__not_<is_reference<_Tp>>, |
| 183 |
__not_<is_void<_Tp>>>::value> |
| 184 |
struct __add_rvalue_reference_helper |
| 185 |
{ typedef _Tp type; }; |
| 186 |
template<typename _Tp> |
| 187 |
struct add_rvalue_reference |
| 188 |
: public __add_rvalue_reference_helper<_Tp> |
| 189 |
{}; |
| 190 |
template<typename _Unqualified, bool _IsConst, bool _IsVol> |
| 191 |
struct __cv_selector; |
| 192 |
template<typename _Unqualified> |
| 193 |
struct __cv_selector<_Unqualified, false, false> |
| 194 |
{ typedef _Unqualified __type; }; |
| 195 |
template<typename _Qualified, typename _Unqualified, |
| 196 |
bool _IsConst = is_const<_Qualified>::value, |
| 197 |
bool _IsVol = is_volatile<_Qualified>::value> |
| 198 |
class __match_cv_qualifiers |
| 199 |
{ |
| 200 |
typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match; |
| 201 |
public: |
| 202 |
typedef typename __match::__type __type; |
| 203 |
}; |
| 204 |
template<typename _Tp> |
| 205 |
struct __make_unsigned |
| 206 |
{ typedef _Tp __type; }; |
| 207 |
template<typename _Tp, |
| 208 |
bool _IsInt = is_integral<_Tp>::value, |
| 209 |
bool _IsEnum = is_enum<_Tp>::value> |
| 210 |
class __make_unsigned_selector; |
| 211 |
template<typename _Tp> |
| 212 |
class __make_unsigned_selector<_Tp, true, false> |
| 213 |
{ |
| 214 |
typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt; |
| 215 |
typedef typename __unsignedt::__type __unsigned_type; |
| 216 |
typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned; |
| 217 |
public: |
| 218 |
typedef typename __cv_unsigned::__type __type; |
| 219 |
}; |
| 220 |
template<typename _Tp> |
| 221 |
struct make_unsigned |
| 222 |
{ typedef typename __make_unsigned_selector<_Tp>::__type type; }; |
| 223 |
template<typename _Tp, typename> |
| 224 |
struct __remove_pointer_helper |
| 225 |
{ typedef _Tp type; }; |
| 226 |
template<typename _Tp> |
| 227 |
struct remove_pointer |
| 228 |
: public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type> |
| 229 |
{}; |
| 230 |
template<typename _Up, |
| 231 |
bool _IsArray = is_array<_Up>::value, |
| 232 |
bool _IsFunction = is_function<_Up>::value> |
| 233 |
struct __decay_selector; |
| 234 |
template<typename _Up> |
| 235 |
struct __decay_selector<_Up, false, false> |
| 236 |
{ typedef typename remove_cv<_Up>::type __type; }; |
| 237 |
template<typename _Tp> |
| 238 |
class decay |
| 239 |
{ |
| 240 |
typedef typename remove_reference<_Tp>::type __remove_type; |
| 241 |
public: |
| 242 |
typedef typename __decay_selector<__remove_type>::__type type; |
| 243 |
}; |
| 244 |
template<bool, typename _Tp = void> |
| 245 |
struct enable_if |
| 246 |
{ typedef _Tp type; }; |
| 247 |
template<typename... _Cond> |
| 248 |
using _Require = typename enable_if<__and_<_Cond...>::value>::type; |
| 249 |
template<bool _Cond, typename _Iftrue, typename _Iffalse> |
| 250 |
struct conditional |
| 251 |
{ typedef _Iftrue type; }; |
| 252 |
template<typename _Signature> |
| 253 |
class result_of; |
| 254 |
template<bool, bool, typename _Functor, typename... _ArgTypes> |
| 255 |
struct __result_of_impl |
| 256 |
; |
| 257 |
struct __result_of_other_impl |
| 258 |
{ |
| 259 |
template<typename _Fn, typename... _Args> |
| 260 |
static __success_type<decltype( |
| 261 |
std::declval<_Fn>()(std::declval<_Args>()...) |
| 262 |
)> _S_test(int); |
| 263 |
}; |
| 264 |
template<typename _Functor, typename... _ArgTypes> |
| 265 |
struct __result_of_impl<false, false, _Functor, _ArgTypes...> |
| 266 |
: private __result_of_other_impl |
| 267 |
{ |
| 268 |
typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type; |
| 269 |
}; |
| 270 |
template<typename _Functor, typename... _ArgTypes> |
| 271 |
struct result_of<_Functor(_ArgTypes...)> |
| 272 |
: public __result_of_impl< |
| 273 |
is_member_object_pointer< |
| 274 |
typename remove_reference<_Functor>::type |
| 275 |
>::value, |
| 276 |
is_member_function_pointer< |
| 277 |
typename remove_reference<_Functor>::type |
| 278 |
>::value, |
| 279 |
_Functor, _ArgTypes... |
| 280 |
>::type |
| 281 |
{}; |
| 282 |
template<typename _Tp> |
| 283 |
constexpr _Tp&& |
| 284 |
forward(typename std::remove_reference<_Tp>::type& __t) noexcept |
| 285 |
{ return static_cast<_Tp&&>(__t); } |
| 286 |
template<typename _Tp> |
| 287 |
constexpr typename std::remove_reference<_Tp>::type&& |
| 288 |
move(_Tp&& __t) noexcept |
| 289 |
{ return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); } |
| 290 |
template<std::size_t _Int, class _Tp> |
| 291 |
class tuple_element; |
| 292 |
struct allocator_arg_t {}; |
| 293 |
constexpr allocator_arg_t allocator_arg = allocator_arg_t(); |
| 294 |
template<typename _Tp> |
| 295 |
struct __add_ref |
| 296 |
{ typedef _Tp& type; }; |
| 297 |
template<std::size_t _Idx, typename... _Elements> |
| 298 |
struct _Tuple_impl; |
| 299 |
template<std::size_t _Idx, typename _Head, typename... _Tail> |
| 300 |
struct _Tuple_impl<_Idx, _Head, _Tail...> |
| 301 |
{}; |
| 302 |
template<typename... _Elements> |
| 303 |
class tuple : public _Tuple_impl<0, _Elements...> |
| 304 |
{}; |
| 305 |
template<typename _Head, typename... _Tail> |
| 306 |
struct tuple_element<0, tuple<_Head, _Tail...> > |
| 307 |
{ |
| 308 |
typedef _Head type; |
| 309 |
}; |
| 310 |
template<std::size_t __i, typename... _Elements> |
| 311 |
typename __add_ref< |
| 312 |
typename tuple_element<__i, tuple<_Elements...>>::type |
| 313 |
>::type |
| 314 |
get(tuple<_Elements...>& __t) noexcept; |
| 315 |
template<std::size_t... _Indexes> |
| 316 |
struct _Index_tuple |
| 317 |
{}; |
| 318 |
template<std::size_t _Num> |
| 319 |
struct _Build_index_tuple |
| 320 |
{ |
| 321 |
typedef _Index_tuple<> __type; |
| 322 |
}; |
| 323 |
template<typename _Functor, typename... _Args> |
| 324 |
typename enable_if< |
| 325 |
(!is_member_pointer<_Functor>::value |
| 326 |
&& !is_function<typename remove_pointer<_Functor>::type>::value), |
| 327 |
typename result_of<_Functor(_Args&&...)>::type |
| 328 |
>::type |
| 329 |
__invoke(_Functor& __f, _Args&&... __args) |
| 330 |
{ |
| 331 |
return __f(std::forward<_Args>(__args)...); |
| 332 |
} |
| 333 |
|
| 334 |
template<typename _Tp> |
| 335 |
class reference_wrapper |
| 336 |
{ |
| 337 |
public: |
| 338 |
_Tp& |
| 339 |
get() const noexcept |
| 340 |
{} |
| 341 |
template<typename... _Args> |
| 342 |
typename result_of<_Tp&(_Args&&...)>::type |
| 343 |
operator()(_Args&&... __args) const |
| 344 |
{ |
| 345 |
return __invoke(get(), std::forward<_Args>(__args)...); |
| 346 |
} |
| 347 |
}; |
| 348 |
template<typename _Tp> |
| 349 |
inline reference_wrapper<_Tp> |
| 350 |
ref(_Tp& __t) noexcept |
| 351 |
{ return reference_wrapper<_Tp>(); } |
| 352 |
template<typename _Tp> |
| 353 |
struct _Maybe_wrap_member_pointer |
| 354 |
{ |
| 355 |
typedef _Tp type; |
| 356 |
}; |
| 357 |
template<typename _Signature> |
| 358 |
struct _Bind_simple; |
| 359 |
template<typename _Callable, typename... _Args> |
| 360 |
struct _Bind_simple<_Callable(_Args...)> |
| 361 |
{ |
| 362 |
typedef typename result_of<_Callable(_Args...)>::type result_type; |
| 363 |
result_type |
| 364 |
operator()() |
| 365 |
{ |
| 366 |
typedef typename _Build_index_tuple<sizeof...(_Args)>::__type _Indices; |
| 367 |
return _M_invoke(_Indices()); |
| 368 |
} |
| 369 |
template<std::size_t... _Indices> |
| 370 |
typename result_of<_Callable(_Args...)>::type |
| 371 |
_M_invoke(_Index_tuple<_Indices...>) |
| 372 |
{ |
| 373 |
return std::forward<_Callable>(std::get<0>(_M_bound))( |
| 374 |
std::forward<_Args>(std::get<_Indices+1>(_M_bound))...); |
| 375 |
} |
| 376 |
std::tuple<_Callable, _Args...> _M_bound; |
| 377 |
}; |
| 378 |
template<typename _Func, typename... _BoundArgs> |
| 379 |
struct _Bind_simple_helper |
| 380 |
{ |
| 381 |
typedef _Maybe_wrap_member_pointer<typename decay<_Func>::type> |
| 382 |
__maybe_type; |
| 383 |
typedef typename __maybe_type::type __func_type; |
| 384 |
typedef _Bind_simple<__func_type(typename decay<_BoundArgs>::type...)> |
| 385 |
__type; |
| 386 |
}; |
| 387 |
template<typename _Callable, typename... _Args> |
| 388 |
typename _Bind_simple_helper<_Callable, _Args...>::__type |
| 389 |
__bind_simple(_Callable&& __callable, _Args&&... __args) |
| 390 |
; |
| 391 |
union _Any_data |
| 392 |
; |
| 393 |
template<typename _Functor> |
| 394 |
inline _Functor& |
| 395 |
__callable_functor(_Functor& __f) |
| 396 |
; |
| 397 |
template<typename _Signature> |
| 398 |
class function; |
| 399 |
struct _Function_base |
| 400 |
{ |
| 401 |
template<typename _Functor> |
| 402 |
class _Base_manager |
| 403 |
{ |
| 404 |
protected: |
| 405 |
static _Functor* |
| 406 |
_M_get_pointer(const _Any_data& __source) |
| 407 |
; |
| 408 |
}; |
| 409 |
}; |
| 410 |
template<typename _Signature, typename _Functor> |
| 411 |
class _Function_handler; |
| 412 |
template<typename _Res, typename _Functor, typename... _ArgTypes> |
| 413 |
class _Function_handler<_Res(_ArgTypes...), _Functor> |
| 414 |
: public _Function_base::_Base_manager<_Functor> |
| 415 |
{ |
| 416 |
typedef _Function_base::_Base_manager<_Functor> _Base; |
| 417 |
public: |
| 418 |
static _Res |
| 419 |
_M_invoke(const _Any_data& __functor, _ArgTypes... __args) |
| 420 |
{ |
| 421 |
return (*_Base::_M_get_pointer(__functor))( |
| 422 |
std::forward<_ArgTypes>(__args)...); |
| 423 |
} |
| 424 |
}; |
| 425 |
template<typename _Res, typename... _ArgTypes> |
| 426 |
class function<_Res(_ArgTypes...)> |
| 427 |
{ |
| 428 |
typedef _Res _Signature_type(_ArgTypes...); |
| 429 |
template<typename _Functor> |
| 430 |
using _Invoke = decltype(__callable_functor(std::declval<_Functor&>()) |
| 431 |
(std::declval<_ArgTypes>()...) ); |
| 432 |
template<typename _CallRes, typename _Res1> |
| 433 |
struct _CheckResult |
| 434 |
: is_convertible<_CallRes, _Res1> {}; |
| 435 |
template<typename _Functor> |
| 436 |
using _Callable = _CheckResult<_Invoke<_Functor>, _Res>; |
| 437 |
template<typename _Cond, typename _Tp> |
| 438 |
using _Requires = typename enable_if<_Cond::value, _Tp>::type; |
| 439 |
public: |
| 440 |
template<typename _Functor, |
| 441 |
typename = _Requires<_Callable<_Functor>, void>> |
| 442 |
function(_Functor); |
| 443 |
typedef _Res (*_Invoker_type)(const _Any_data&, _ArgTypes...); |
| 444 |
_Invoker_type _M_invoker; |
| 445 |
}; |
| 446 |
template<typename _Res, typename... _ArgTypes> |
| 447 |
template<typename _Functor, typename> |
| 448 |
function<_Res(_ArgTypes...)>:: |
| 449 |
function(_Functor __f) |
| 450 |
{ |
| 451 |
typedef _Function_handler<_Signature_type, _Functor> _My_handler; |
| 452 |
{ |
| 453 |
_M_invoker = &_My_handler::_M_invoke; |
| 454 |
} |
| 455 |
} |
| 456 |
template<typename _Ptr> |
| 457 |
class __ptrtr_pointer_to |
| 458 |
; |
| 459 |
template<typename _Ptr> |
| 460 |
struct pointer_traits : __ptrtr_pointer_to<_Ptr> |
| 461 |
{}; |
| 462 |
template<typename _Tp> |
| 463 |
struct pointer_traits<_Tp*> |
| 464 |
{ |
| 465 |
typedef ptrdiff_t difference_type; |
| 466 |
}; |
| 467 |
template<typename _Alloc, typename _Tp> |
| 468 |
class __alloctr_rebind_helper |
| 469 |
{ |
| 470 |
template<typename, typename> |
| 471 |
static constexpr bool |
| 472 |
_S_chk(...) |
| 473 |
{ return false; } |
| 474 |
public: |
| 475 |
static const bool __value = _S_chk<_Alloc, _Tp>(nullptr); |
| 476 |
}; |
| 477 |
template<typename _Alloc, typename _Tp, |
| 478 |
bool = __alloctr_rebind_helper<_Alloc, _Tp>::__value> |
| 479 |
struct __alloctr_rebind; |
| 480 |
template<template<typename, typename...> class _Alloc, typename _Tp, |
| 481 |
typename _Up, typename... _Args> |
| 482 |
struct __alloctr_rebind<_Alloc<_Up, _Args...>, _Tp, false> |
| 483 |
{ |
| 484 |
typedef _Alloc<_Tp, _Args...> __type; |
| 485 |
}; |
| 486 |
template<typename _Alloc> |
| 487 |
struct allocator_traits |
| 488 |
{ |
| 489 |
typedef _Alloc allocator_type; |
| 490 |
typedef typename _Alloc::value_type value_type; static value_type* _S_pointer_helper(...); typedef decltype(_S_pointer_helper((_Alloc*)0)) __pointer; public: |
| 491 |
typedef __pointer pointer; static typename pointer_traits<pointer>::difference_type _S_difference_type_helper(...); typedef decltype(_S_difference_type_helper((_Alloc*)0)) __difference_type; public: |
| 492 |
typedef __difference_type difference_type; static typename make_unsigned<difference_type>::type _S_size_type_helper(...); typedef decltype(_S_size_type_helper((_Alloc*)0)) __size_type; public: |
| 493 |
typedef __size_type size_type; public: |
| 494 |
template<typename _Tp> |
| 495 |
using rebind_alloc = typename __alloctr_rebind<_Alloc, _Tp>::__type; |
| 496 |
template<typename _Tp> |
| 497 |
using rebind_traits = allocator_traits<rebind_alloc<_Tp>>; |
| 498 |
template<typename _Tp, typename... _Args> |
| 499 |
struct __construct_helper |
| 500 |
{ |
| 501 |
template<typename> |
| 502 |
static false_type __test(...); |
| 503 |
typedef decltype(__test<_Alloc>(0)) type; |
| 504 |
static const bool value = type::value; |
| 505 |
}; |
| 506 |
template<typename _Tp, typename... _Args> |
| 507 |
static typename |
| 508 |
enable_if<__and_<__not_<__construct_helper<_Tp, _Args...>>, |
| 509 |
is_constructible<_Tp, _Args...>>::value, void>::type |
| 510 |
_S_construct(_Alloc&, _Tp* __p, _Args&&... __args) |
| 511 |
{ ::new((void*)__p) _Tp(std::forward<_Args>(__args)...); } |
| 512 |
static pointer |
| 513 |
allocate(_Alloc& __a, size_type __n) |
| 514 |
; |
| 515 |
template<typename _Tp, typename... _Args> |
| 516 |
static auto construct(_Alloc& __a, _Tp* __p, _Args&&... __args) |
| 517 |
-> decltype(_S_construct(__a, __p, std::forward<_Args>(__args)...)) |
| 518 |
{ _S_construct(__a, __p, std::forward<_Args>(__args)...); } |
| 519 |
}; |
| 520 |
} |
| 521 |
namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) |
| 522 |
{ |
| 523 |
enum _Lock_policy { _S_single, _S_mutex, _S_atomic }; |
| 524 |
static const _Lock_policy __default_lock_policy = |
| 525 |
_S_atomic; |
| 526 |
} |
| 527 |
namespace std __attribute__ ((__visibility__ ("default"))) |
| 528 |
{ |
| 529 |
template<typename _Tp> |
| 530 |
struct default_delete |
| 531 |
; |
| 532 |
template <typename _Tp, typename _Dp = default_delete<_Tp> > |
| 533 |
class unique_ptr |
| 534 |
{ |
| 535 |
class _Pointer |
| 536 |
{ |
| 537 |
template<typename _Up> |
| 538 |
static _Tp* __test(...); |
| 539 |
typedef typename remove_reference<_Dp>::type _Del; |
| 540 |
public: |
| 541 |
typedef decltype(__test<_Del>(0)) type; |
| 542 |
}; |
| 543 |
public: |
| 544 |
typedef typename _Pointer::type pointer; |
| 545 |
typedef _Tp element_type; |
| 546 |
template<typename _Up, typename _Ep, typename = _Require< |
| 547 |
is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>, |
| 548 |
typename conditional<is_reference<_Dp>::value, |
| 549 |
is_same<_Ep, _Dp>, |
| 550 |
is_convertible<_Ep, _Dp>>::type>> |
| 551 |
unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept |
| 552 |
; |
| 553 |
}; |
| 554 |
} |
| 555 |
namespace __gnu_cxx |
| 556 |
{ |
| 557 |
template<typename _Tp> |
| 558 |
struct __aligned_buffer |
| 559 |
{}; |
| 560 |
} |
| 561 |
namespace std __attribute__ ((__visibility__ ("default"))) |
| 562 |
{ |
| 563 |
using __gnu_cxx::_Lock_policy; |
| 564 |
using __gnu_cxx::__default_lock_policy; |
| 565 |
template<_Lock_policy _Lp = __default_lock_policy> |
| 566 |
class _Sp_counted_base |
| 567 |
{}; |
| 568 |
template<typename _Tp, _Lock_policy _Lp = __default_lock_policy> |
| 569 |
class __shared_ptr; |
| 570 |
struct _Sp_make_shared_tag {}; |
| 571 |
template<typename _Tp, typename _Alloc, _Lock_policy _Lp> |
| 572 |
class _Sp_counted_ptr_inplace final : public _Sp_counted_base<_Lp> |
| 573 |
{ |
| 574 |
struct _Impl |
| 575 |
: public _Alloc |
| 576 |
{ |
| 577 |
_Impl(_Alloc __a) : _Alloc(__a), _M_ptr() {} |
| 578 |
_Tp* _M_ptr; |
| 579 |
}; |
| 580 |
public: |
| 581 |
template<typename... _Args> |
| 582 |
_Sp_counted_ptr_inplace(_Alloc __a, _Args&&... __args) |
| 583 |
: _M_impl(__a), _M_storage() |
| 584 |
{ |
| 585 |
allocator_traits<_Alloc>::construct(__a, _M_impl._M_ptr, |
| 586 |
std::forward<_Args>(__args)...); |
| 587 |
} |
| 588 |
_Impl _M_impl; |
| 589 |
__gnu_cxx::__aligned_buffer<_Tp> _M_storage; |
| 590 |
}; |
| 591 |
template<_Lock_policy _Lp> |
| 592 |
class __shared_count |
| 593 |
{ |
| 594 |
public: |
| 595 |
template<typename _Tp, typename _Alloc, typename... _Args> |
| 596 |
__shared_count(_Sp_make_shared_tag, _Tp*, const _Alloc& __a, |
| 597 |
_Args&&... __args) |
| 598 |
{ |
| 599 |
typedef _Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp> _Sp_cp_type; |
| 600 |
typedef typename allocator_traits<_Alloc>::template |
| 601 |
rebind_traits<_Sp_cp_type> _Alloc_traits; |
| 602 |
typename _Alloc_traits::allocator_type __a2(__a); |
| 603 |
_Sp_cp_type* __mem = _Alloc_traits::allocate(__a2, 1); |
| 604 |
try |
| 605 |
{ |
| 606 |
_Alloc_traits::construct(__a2, __mem, std::move(__a), |
| 607 |
std::forward<_Args>(__args)...); |
| 608 |
} |
| 609 |
catch(...) |
| 610 |
{} |
| 611 |
} |
| 612 |
}; |
| 613 |
template<typename _Tp, _Lock_policy _Lp> |
| 614 |
class __shared_ptr |
| 615 |
{ |
| 616 |
public: |
| 617 |
template<typename _Tp1, typename = typename |
| 618 |
std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> |
| 619 |
__shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r) noexcept |
| 620 |
: _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) |
| 621 |
{} |
| 622 |
template<typename _Alloc, typename... _Args> |
| 623 |
__shared_ptr(_Sp_make_shared_tag __tag, const _Alloc& __a, |
| 624 |
_Args&&... __args) |
| 625 |
: _M_ptr(), _M_refcount(__tag, (_Tp*)0, __a, |
| 626 |
std::forward<_Args>(__args)...) |
| 627 |
{} |
| 628 |
_Tp* _M_ptr; |
| 629 |
__shared_count<_Lp> _M_refcount; |
| 630 |
}; |
| 631 |
template<typename _Tp> |
| 632 |
class shared_ptr : public __shared_ptr<_Tp> |
| 633 |
{ |
| 634 |
public: |
| 635 |
template<typename _Tp1, typename = typename |
| 636 |
std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> |
| 637 |
shared_ptr(const shared_ptr<_Tp1>& __r) noexcept |
| 638 |
: __shared_ptr<_Tp>(__r) {} |
| 639 |
template<typename _Alloc, typename... _Args> |
| 640 |
shared_ptr(_Sp_make_shared_tag __tag, const _Alloc& __a, |
| 641 |
_Args&&... __args) |
| 642 |
: __shared_ptr<_Tp>(__tag, __a, std::forward<_Args>(__args)...) |
| 643 |
{} |
| 644 |
}; |
| 645 |
template<typename _Tp, typename _Alloc, typename... _Args> |
| 646 |
inline shared_ptr<_Tp> |
| 647 |
allocate_shared(const _Alloc& __a, _Args&&... __args) |
| 648 |
{ |
| 649 |
return shared_ptr<_Tp>(_Sp_make_shared_tag(), __a, |
| 650 |
std::forward<_Args>(__args)...); |
| 651 |
} |
| 652 |
} |
| 653 |
namespace std __attribute__ ((__visibility__ ("default"))) |
| 654 |
{ |
| 655 |
template<typename _Signature> |
| 656 |
class packaged_task; |
| 657 |
struct __future_base |
| 658 |
{ |
| 659 |
struct _Result_base |
| 660 |
{ |
| 661 |
struct _Deleter |
| 662 |
; |
| 663 |
}; |
| 664 |
template<typename _Res> |
| 665 |
struct _Result : _Result_base |
| 666 |
{ |
| 667 |
typedef _Res result_type; |
| 668 |
}; |
| 669 |
template<typename _Res> |
| 670 |
using _Ptr = unique_ptr<_Res, _Result_base::_Deleter>; |
| 671 |
template<typename _Res, typename _Alloc> |
| 672 |
struct _Result_alloc final : _Result<_Res>, _Alloc |
| 673 |
{}; |
| 674 |
template<typename _Res, typename _Allocator> |
| 675 |
static _Ptr<_Result_alloc<_Res, _Allocator>> |
| 676 |
_S_allocate_result(const _Allocator& __a) |
| 677 |
; |
| 678 |
template<typename _Signature> |
| 679 |
class _Task_state_base; |
| 680 |
template<typename _Fn, typename _Alloc, typename _Signature> |
| 681 |
class _Task_state; |
| 682 |
template<typename _Res_ptr, |
| 683 |
typename _Res = typename _Res_ptr::element_type::result_type> |
| 684 |
struct _Task_setter; |
| 685 |
template<typename _Res_ptr, typename _BoundFn> |
| 686 |
static _Task_setter<_Res_ptr> |
| 687 |
_S_task_setter(_Res_ptr& __ptr, _BoundFn&& __call) |
| 688 |
{ |
| 689 |
return _Task_setter<_Res_ptr>{ __ptr, std::ref(__call) }; |
| 690 |
} |
| 691 |
}; |
| 692 |
template<typename _Ptr_type, typename _Res> |
| 693 |
struct __future_base::_Task_setter |
| 694 |
{ |
| 695 |
_Ptr_type& _M_result; |
| 696 |
std::function<_Res()> _M_fn; |
| 697 |
}; |
| 698 |
template<typename _Res, typename... _Args> |
| 699 |
struct __future_base::_Task_state_base<_Res(_Args...)> |
| 700 |
{ |
| 701 |
template<typename _Alloc> |
| 702 |
_Task_state_base(const _Alloc& __a) |
| 703 |
: _M_result(_S_allocate_result<_Res>(__a)) |
| 704 |
{} |
| 705 |
typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type; |
| 706 |
_Ptr_type _M_result; |
| 707 |
}; |
| 708 |
template<typename _Fn, typename _Alloc, typename _Res, typename... _Args> |
| 709 |
struct __future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)> final |
| 710 |
: __future_base::_Task_state_base<_Res(_Args...)> |
| 711 |
{ |
| 712 |
_Task_state(_Fn&& __fn, const _Alloc& __a) |
| 713 |
: _Task_state_base<_Res(_Args...)>(__a), _M_impl(std::move(__fn), __a) |
| 714 |
{} |
| 715 |
virtual void |
| 716 |
_M_run(_Args... __args) |
| 717 |
{ |
| 718 |
auto __boundfn = std::__bind_simple(std::ref(_M_impl._M_fn), |
| 719 |
_S_maybe_wrap_ref(std::forward<_Args>(__args))...); |
| 720 |
auto __setter = _S_task_setter(this->_M_result, std::move(__boundfn)); |
| 721 |
} |
| 722 |
struct _Impl : _Alloc |
| 723 |
{ |
| 724 |
_Impl(_Fn&& __fn, const _Alloc& __a) |
| 725 |
: _Alloc(__a), _M_fn(std::move(__fn)) {} |
| 726 |
_Fn _M_fn; |
| 727 |
} _M_impl; |
| 728 |
}; |
| 729 |
template<typename _Signature, typename _Fn, typename _Alloc> |
| 730 |
static shared_ptr<__future_base::_Task_state_base<_Signature>> |
| 731 |
__create_task_state(_Fn&& __fn, const _Alloc& __a) |
| 732 |
{ |
| 733 |
typedef __future_base::_Task_state<_Fn, _Alloc, _Signature> _State; |
| 734 |
return std::allocate_shared<_State>(__a, std::move(__fn), __a); |
| 735 |
} |
| 736 |
template<typename _Task, typename _Fn, bool |
| 737 |
= is_same<_Task, typename decay<_Fn>::type>::value> |
| 738 |
struct __constrain_pkgdtask |
| 739 |
{ typedef void __type; }; |
| 740 |
template<typename _Res, typename... _ArgTypes> |
| 741 |
class packaged_task<_Res(_ArgTypes...)> |
| 742 |
{ |
| 743 |
typedef __future_base::_Task_state_base<_Res(_ArgTypes...)> _State_type; |
| 744 |
shared_ptr<_State_type> _M_state; |
| 745 |
public: |
| 746 |
template<typename _Fn, typename _Alloc, typename = typename |
| 747 |
__constrain_pkgdtask<packaged_task, _Fn>::__type> |
| 748 |
packaged_task(allocator_arg_t, const _Alloc& __a, _Fn&& __fn) |
| 749 |
: _M_state(__create_task_state<_Res(_ArgTypes...)>( |
| 750 |
std::forward<_Fn>(__fn), __a)) |
| 751 |
{} |
| 752 |
}; |
| 753 |
} |
| 754 |
namespace __gnu_test |
| 755 |
{ |
| 756 |
template <class Tp> |
| 757 |
struct SimpleAllocator |
| 758 |
{ |
| 759 |
typedef Tp value_type; |
| 760 |
SimpleAllocator() ; |
| 761 |
template <class T> |
| 762 |
SimpleAllocator(const SimpleAllocator<T>& other) ; |
| 763 |
}; |
| 764 |
} |
| 765 |
using std::packaged_task; |
| 766 |
using std::allocator_arg; |
| 767 |
__gnu_test::SimpleAllocator<int> a; |
| 768 |
packaged_task<int()> p(allocator_arg, a, []() { return 1; }); |