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