]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libc++/include/__functional_base
Upgrade to Unbound 1.5.9.
[FreeBSD/FreeBSD.git] / contrib / libc++ / include / __functional_base
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef _LIBCPP_FUNCTIONAL_BASE
12 #define _LIBCPP_FUNCTIONAL_BASE
13
14 #include <__config>
15 #include <type_traits>
16 #include <typeinfo>
17 #include <exception>
18 #include <new>
19
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 #pragma GCC system_header
22 #endif
23
24 _LIBCPP_BEGIN_NAMESPACE_STD
25
26 template <class _Arg, class _Result>
27 struct _LIBCPP_TYPE_VIS_ONLY unary_function
28 {
29     typedef _Arg    argument_type;
30     typedef _Result result_type;
31 };
32
33 template <class _Arg1, class _Arg2, class _Result>
34 struct _LIBCPP_TYPE_VIS_ONLY binary_function
35 {
36     typedef _Arg1   first_argument_type;
37     typedef _Arg2   second_argument_type;
38     typedef _Result result_type;
39 };
40
41 template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash;
42
43 template <class _Tp>
44 struct __has_result_type
45 {
46 private:
47     struct __two {char __lx; char __lxx;};
48     template <class _Up> static __two __test(...);
49     template <class _Up> static char __test(typename _Up::result_type* = 0);
50 public:
51     static const bool value = sizeof(__test<_Tp>(0)) == 1;
52 };
53
54 #if _LIBCPP_STD_VER > 11
55 template <class _Tp = void>
56 #else
57 template <class _Tp>
58 #endif
59 struct _LIBCPP_TYPE_VIS_ONLY less : binary_function<_Tp, _Tp, bool>
60 {
61     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 
62     bool operator()(const _Tp& __x, const _Tp& __y) const
63         {return __x < __y;}
64 };
65
66 #if _LIBCPP_STD_VER > 11
67 template <>
68 struct _LIBCPP_TYPE_VIS_ONLY less<void>
69 {
70     template <class _T1, class _T2> 
71     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
72     auto operator()(_T1&& __t, _T2&& __u) const
73     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u)))
74     -> decltype        (_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u))
75         { return        _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); }
76     typedef void is_transparent;
77 };
78 #endif
79
80 // __weak_result_type
81
82 template <class _Tp>
83 struct __derives_from_unary_function
84 {
85 private:
86     struct __two {char __lx; char __lxx;};
87     static __two __test(...);
88     template <class _Ap, class _Rp>
89         static unary_function<_Ap, _Rp>
90         __test(const volatile unary_function<_Ap, _Rp>*);
91 public:
92     static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
93     typedef decltype(__test((_Tp*)0)) type;
94 };
95
96 template <class _Tp>
97 struct __derives_from_binary_function
98 {
99 private:
100     struct __two {char __lx; char __lxx;};
101     static __two __test(...);
102     template <class _A1, class _A2, class _Rp>
103         static binary_function<_A1, _A2, _Rp>
104         __test(const volatile binary_function<_A1, _A2, _Rp>*);
105 public:
106     static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
107     typedef decltype(__test((_Tp*)0)) type;
108 };
109
110 template <class _Tp, bool = __derives_from_unary_function<_Tp>::value>
111 struct __maybe_derive_from_unary_function  // bool is true
112     : public __derives_from_unary_function<_Tp>::type
113 {
114 };
115
116 template <class _Tp>
117 struct __maybe_derive_from_unary_function<_Tp, false>
118 {
119 };
120
121 template <class _Tp, bool = __derives_from_binary_function<_Tp>::value>
122 struct __maybe_derive_from_binary_function  // bool is true
123     : public __derives_from_binary_function<_Tp>::type
124 {
125 };
126
127 template <class _Tp>
128 struct __maybe_derive_from_binary_function<_Tp, false>
129 {
130 };
131
132 template <class _Tp, bool = __has_result_type<_Tp>::value>
133 struct __weak_result_type_imp // bool is true
134     : public __maybe_derive_from_unary_function<_Tp>,
135       public __maybe_derive_from_binary_function<_Tp>
136 {
137     typedef typename _Tp::result_type result_type;
138 };
139
140 template <class _Tp>
141 struct __weak_result_type_imp<_Tp, false>
142     : public __maybe_derive_from_unary_function<_Tp>,
143       public __maybe_derive_from_binary_function<_Tp>
144 {
145 };
146
147 template <class _Tp>
148 struct __weak_result_type
149     : public __weak_result_type_imp<_Tp>
150 {
151 };
152
153 // 0 argument case
154
155 template <class _Rp>
156 struct __weak_result_type<_Rp ()>
157 {
158     typedef _Rp result_type;
159 };
160
161 template <class _Rp>
162 struct __weak_result_type<_Rp (&)()>
163 {
164     typedef _Rp result_type;
165 };
166
167 template <class _Rp>
168 struct __weak_result_type<_Rp (*)()>
169 {
170     typedef _Rp result_type;
171 };
172
173 // 1 argument case
174
175 template <class _Rp, class _A1>
176 struct __weak_result_type<_Rp (_A1)>
177     : public unary_function<_A1, _Rp>
178 {
179 };
180
181 template <class _Rp, class _A1>
182 struct __weak_result_type<_Rp (&)(_A1)>
183     : public unary_function<_A1, _Rp>
184 {
185 };
186
187 template <class _Rp, class _A1>
188 struct __weak_result_type<_Rp (*)(_A1)>
189     : public unary_function<_A1, _Rp>
190 {
191 };
192
193 template <class _Rp, class _Cp>
194 struct __weak_result_type<_Rp (_Cp::*)()>
195     : public unary_function<_Cp*, _Rp>
196 {
197 };
198
199 template <class _Rp, class _Cp>
200 struct __weak_result_type<_Rp (_Cp::*)() const>
201     : public unary_function<const _Cp*, _Rp>
202 {
203 };
204
205 template <class _Rp, class _Cp>
206 struct __weak_result_type<_Rp (_Cp::*)() volatile>
207     : public unary_function<volatile _Cp*, _Rp>
208 {
209 };
210
211 template <class _Rp, class _Cp>
212 struct __weak_result_type<_Rp (_Cp::*)() const volatile>
213     : public unary_function<const volatile _Cp*, _Rp>
214 {
215 };
216
217 // 2 argument case
218
219 template <class _Rp, class _A1, class _A2>
220 struct __weak_result_type<_Rp (_A1, _A2)>
221     : public binary_function<_A1, _A2, _Rp>
222 {
223 };
224
225 template <class _Rp, class _A1, class _A2>
226 struct __weak_result_type<_Rp (*)(_A1, _A2)>
227     : public binary_function<_A1, _A2, _Rp>
228 {
229 };
230
231 template <class _Rp, class _A1, class _A2>
232 struct __weak_result_type<_Rp (&)(_A1, _A2)>
233     : public binary_function<_A1, _A2, _Rp>
234 {
235 };
236
237 template <class _Rp, class _Cp, class _A1>
238 struct __weak_result_type<_Rp (_Cp::*)(_A1)>
239     : public binary_function<_Cp*, _A1, _Rp>
240 {
241 };
242
243 template <class _Rp, class _Cp, class _A1>
244 struct __weak_result_type<_Rp (_Cp::*)(_A1) const>
245     : public binary_function<const _Cp*, _A1, _Rp>
246 {
247 };
248
249 template <class _Rp, class _Cp, class _A1>
250 struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile>
251     : public binary_function<volatile _Cp*, _A1, _Rp>
252 {
253 };
254
255 template <class _Rp, class _Cp, class _A1>
256 struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile>
257     : public binary_function<const volatile _Cp*, _A1, _Rp>
258 {
259 };
260
261
262 #ifndef _LIBCPP_HAS_NO_VARIADICS
263 // 3 or more arguments
264
265 template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
266 struct __weak_result_type<_Rp (_A1, _A2, _A3, _A4...)>
267 {
268     typedef _Rp result_type;
269 };
270
271 template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
272 struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)>
273 {
274     typedef _Rp result_type;
275 };
276
277 template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
278 struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)>
279 {
280     typedef _Rp result_type;
281 };
282
283 template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
284 struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)>
285 {
286     typedef _Rp result_type;
287 };
288
289 template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
290 struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const>
291 {
292     typedef _Rp result_type;
293 };
294
295 template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
296 struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile>
297 {
298     typedef _Rp result_type;
299 };
300
301 template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
302 struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile>
303 {
304     typedef _Rp result_type;
305 };
306
307 #endif // _LIBCPP_HAS_NO_VARIADICS
308
309 // __invoke
310
311 #ifndef _LIBCPP_HAS_NO_VARIADICS
312
313 // bullets 1 and 2
314
315 template <class _Fp, class _A0, class ..._Args,
316             class>
317 inline _LIBCPP_INLINE_VISIBILITY
318 auto
319 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
320     -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
321 {
322     return (_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...);
323 }
324
325 template <class _Fp, class _A0, class ..._Args,
326             class>
327 inline _LIBCPP_INLINE_VISIBILITY
328 auto
329 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
330     -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
331 {
332     return ((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...);
333 }
334
335 // bullets 3 and 4
336
337 template <class _Fp, class _A0,
338             class>
339 inline _LIBCPP_INLINE_VISIBILITY
340 auto
341 __invoke(_Fp&& __f, _A0&& __a0)
342     -> decltype(_VSTD::forward<_A0>(__a0).*__f)
343 {
344     return _VSTD::forward<_A0>(__a0).*__f;
345 }
346
347 template <class _Fp, class _A0,
348             class>
349 inline _LIBCPP_INLINE_VISIBILITY
350 auto
351 __invoke(_Fp&& __f, _A0&& __a0)
352     -> decltype((*_VSTD::forward<_A0>(__a0)).*__f)
353 {
354     return (*_VSTD::forward<_A0>(__a0)).*__f;
355 }
356
357 // bullet 5
358
359 template <class _Fp, class ..._Args>
360 inline _LIBCPP_INLINE_VISIBILITY
361 auto
362 __invoke(_Fp&& __f, _Args&& ...__args)
363     -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
364 {
365     return _VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...);
366 }
367 template <class _Tp, class ..._Args>
368 struct __invoke_return
369 {
370     typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type;
371 };
372
373 #else // _LIBCPP_HAS_NO_VARIADICS
374
375 #include <__functional_base_03>
376
377 #endif  // _LIBCPP_HAS_NO_VARIADICS
378
379
380 template <class _Ret>
381 struct __invoke_void_return_wrapper
382 {
383 #ifndef _LIBCPP_HAS_NO_VARIADICS
384     template <class ..._Args>
385     static _Ret __call(_Args&&... __args) {
386         return __invoke(_VSTD::forward<_Args>(__args)...);
387     }
388 #else
389     template <class _Fn>
390     static _Ret __call(_Fn __f) {
391         return __invoke(__f);
392     }
393
394     template <class _Fn, class _A0>
395     static _Ret __call(_Fn __f, _A0& __a0) {
396         return __invoke(__f, __a0);
397     }
398
399     template <class _Fn, class _A0, class _A1>
400     static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1) {
401         return __invoke(__f, __a0, __a1);
402     }
403
404     template <class _Fn, class _A0, class _A1, class _A2>
405     static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2){
406         return __invoke(__f, __a0, __a1, __a2);
407     }
408 #endif
409 };
410
411 template <>
412 struct __invoke_void_return_wrapper<void>
413 {
414 #ifndef _LIBCPP_HAS_NO_VARIADICS
415     template <class ..._Args>
416     static void __call(_Args&&... __args) {
417         __invoke(_VSTD::forward<_Args>(__args)...);
418     }
419 #else
420     template <class _Fn>
421     static void __call(_Fn __f) {
422         __invoke(__f);
423     }
424
425     template <class _Fn, class _A0>
426     static void __call(_Fn __f, _A0& __a0) {
427         __invoke(__f, __a0);
428     }
429
430     template <class _Fn, class _A0, class _A1>
431     static void __call(_Fn __f, _A0& __a0, _A1& __a1) {
432         __invoke(__f, __a0, __a1);
433     }
434
435     template <class _Fn, class _A0, class _A1, class _A2>
436     static void __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2) {
437         __invoke(__f, __a0, __a1, __a2);
438     }
439 #endif
440 };
441
442 template <class _Tp>
443 class _LIBCPP_TYPE_VIS_ONLY reference_wrapper
444     : public __weak_result_type<_Tp>
445 {
446 public:
447     // types
448     typedef _Tp type;
449 private:
450     type* __f_;
451
452 public:
453     // construct/copy/destroy
454     _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT
455         : __f_(_VSTD::addressof(__f)) {}
456 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
457     private: reference_wrapper(type&&); public: // = delete; // do not bind to temps
458 #endif
459
460     // access
461     _LIBCPP_INLINE_VISIBILITY operator type&    () const _NOEXCEPT {return *__f_;}
462     _LIBCPP_INLINE_VISIBILITY          type& get() const _NOEXCEPT {return *__f_;}
463
464 #ifndef _LIBCPP_HAS_NO_VARIADICS
465     // invoke
466     template <class... _ArgTypes>
467     _LIBCPP_INLINE_VISIBILITY
468     typename __invoke_of<type&, _ArgTypes...>::type
469     operator() (_ArgTypes&&... __args) const {
470         return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...);
471     }
472 #else
473
474     _LIBCPP_INLINE_VISIBILITY
475     typename __invoke_return<type>::type
476     operator() () const {
477         return __invoke(get());
478     }
479
480     template <class _A0>
481     _LIBCPP_INLINE_VISIBILITY
482     typename __invoke_return0<type, _A0>::type
483     operator() (_A0& __a0) const {
484         return __invoke(get(), __a0);
485     }
486
487     template <class _A0>
488     _LIBCPP_INLINE_VISIBILITY
489     typename __invoke_return0<type, _A0 const>::type
490     operator() (_A0 const& __a0) const {
491         return __invoke(get(), __a0);
492     }
493
494     template <class _A0, class _A1>
495     _LIBCPP_INLINE_VISIBILITY
496     typename __invoke_return1<type, _A0, _A1>::type
497     operator() (_A0& __a0, _A1& __a1) const {
498         return __invoke(get(), __a0, __a1);
499     }
500
501     template <class _A0, class _A1>
502     _LIBCPP_INLINE_VISIBILITY
503     typename __invoke_return1<type, _A0 const, _A1>::type
504     operator() (_A0 const& __a0, _A1& __a1) const {
505         return __invoke(get(), __a0, __a1);
506     }
507
508     template <class _A0, class _A1>
509     _LIBCPP_INLINE_VISIBILITY
510     typename __invoke_return1<type, _A0, _A1 const>::type
511     operator() (_A0& __a0, _A1 const& __a1) const {
512         return __invoke(get(), __a0, __a1);
513     }
514
515     template <class _A0, class _A1>
516     _LIBCPP_INLINE_VISIBILITY
517     typename __invoke_return1<type, _A0 const, _A1 const>::type
518     operator() (_A0 const& __a0, _A1 const& __a1) const {
519         return __invoke(get(), __a0, __a1);
520     }
521
522     template <class _A0, class _A1, class _A2>
523     _LIBCPP_INLINE_VISIBILITY
524     typename __invoke_return2<type, _A0, _A1, _A2>::type
525     operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
526         return __invoke(get(), __a0, __a1, __a2);
527     }
528
529     template <class _A0, class _A1, class _A2>
530     _LIBCPP_INLINE_VISIBILITY
531     typename __invoke_return2<type, _A0 const, _A1, _A2>::type
532     operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
533         return __invoke(get(), __a0, __a1, __a2);
534     }
535
536     template <class _A0, class _A1, class _A2>
537     _LIBCPP_INLINE_VISIBILITY
538     typename __invoke_return2<type, _A0, _A1 const, _A2>::type
539     operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
540         return __invoke(get(), __a0, __a1, __a2);
541     }
542
543     template <class _A0, class _A1, class _A2>
544     _LIBCPP_INLINE_VISIBILITY
545     typename __invoke_return2<type, _A0, _A1, _A2 const>::type
546     operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
547         return __invoke(get(), __a0, __a1, __a2);
548     }
549
550     template <class _A0, class _A1, class _A2>
551     _LIBCPP_INLINE_VISIBILITY
552     typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
553     operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
554         return __invoke(get(), __a0, __a1, __a2);
555     }
556
557     template <class _A0, class _A1, class _A2>
558     _LIBCPP_INLINE_VISIBILITY
559     typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
560     operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
561         return __invoke(get(), __a0, __a1, __a2);
562     }
563
564     template <class _A0, class _A1, class _A2>
565     _LIBCPP_INLINE_VISIBILITY
566     typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
567     operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
568         return __invoke(get(), __a0, __a1, __a2);
569     }
570
571     template <class _A0, class _A1, class _A2>
572     _LIBCPP_INLINE_VISIBILITY
573     typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
574     operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
575         return __invoke(get(), __a0, __a1, __a2);
576     }
577 #endif // _LIBCPP_HAS_NO_VARIADICS
578 };
579
580 template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
581 template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
582 template <class _Tp> struct __is_reference_wrapper
583     : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
584
585 template <class _Tp>
586 inline _LIBCPP_INLINE_VISIBILITY
587 reference_wrapper<_Tp>
588 ref(_Tp& __t) _NOEXCEPT
589 {
590     return reference_wrapper<_Tp>(__t);
591 }
592
593 template <class _Tp>
594 inline _LIBCPP_INLINE_VISIBILITY
595 reference_wrapper<_Tp>
596 ref(reference_wrapper<_Tp> __t) _NOEXCEPT
597 {
598     return ref(__t.get());
599 }
600
601 template <class _Tp>
602 inline _LIBCPP_INLINE_VISIBILITY
603 reference_wrapper<const _Tp>
604 cref(const _Tp& __t) _NOEXCEPT
605 {
606     return reference_wrapper<const _Tp>(__t);
607 }
608
609 template <class _Tp>
610 inline _LIBCPP_INLINE_VISIBILITY
611 reference_wrapper<const _Tp>
612 cref(reference_wrapper<_Tp> __t) _NOEXCEPT
613 {
614     return cref(__t.get());
615 }
616
617 #ifndef _LIBCPP_HAS_NO_VARIADICS
618 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
619 #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
620
621 template <class _Tp> void ref(const _Tp&&) = delete;
622 template <class _Tp> void cref(const _Tp&&) = delete;
623
624 #else  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
625
626 template <class _Tp> void ref(const _Tp&&);// = delete;
627 template <class _Tp> void cref(const _Tp&&);// = delete;
628
629 #endif  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
630
631 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
632
633 #endif  // _LIBCPP_HAS_NO_VARIADICS
634
635 #if _LIBCPP_STD_VER > 11
636 template <class _Tp1, class _Tp2 = void>
637 struct __is_transparent
638 {
639 private:
640     struct __two {char __lx; char __lxx;};
641     template <class _Up> static __two __test(...);
642     template <class _Up> static char __test(typename _Up::is_transparent* = 0);
643 public:
644     static const bool value = sizeof(__test<_Tp1>(0)) == 1;
645 };
646 #endif
647
648 // allocator_arg_t
649
650 struct _LIBCPP_TYPE_VIS_ONLY allocator_arg_t { };
651
652 #if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MEMORY)
653 extern const allocator_arg_t allocator_arg;
654 #else
655 constexpr allocator_arg_t allocator_arg = allocator_arg_t();
656 #endif
657
658 // uses_allocator
659
660 template <class _Tp>
661 struct __has_allocator_type
662 {
663 private:
664     struct __two {char __lx; char __lxx;};
665     template <class _Up> static __two __test(...);
666     template <class _Up> static char __test(typename _Up::allocator_type* = 0);
667 public:
668     static const bool value = sizeof(__test<_Tp>(0)) == 1;
669 };
670
671 template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
672 struct __uses_allocator
673     : public integral_constant<bool,
674         is_convertible<_Alloc, typename _Tp::allocator_type>::value>
675 {
676 };
677
678 template <class _Tp, class _Alloc>
679 struct __uses_allocator<_Tp, _Alloc, false>
680     : public false_type
681 {
682 };
683
684 template <class _Tp, class _Alloc>
685 struct _LIBCPP_TYPE_VIS_ONLY uses_allocator
686     : public __uses_allocator<_Tp, _Alloc>
687 {
688 };
689
690 #ifndef _LIBCPP_HAS_NO_VARIADICS
691
692 // allocator construction
693
694 template <class _Tp, class _Alloc, class ..._Args>
695 struct __uses_alloc_ctor_imp
696 {
697     static const bool __ua = uses_allocator<_Tp, _Alloc>::value;
698     static const bool __ic =
699         is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
700     static const int value = __ua ? 2 - __ic : 0;
701 };
702
703 template <class _Tp, class _Alloc, class ..._Args>
704 struct __uses_alloc_ctor
705     : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value>
706     {};
707
708 template <class _Tp, class _Allocator, class... _Args>
709 inline _LIBCPP_INLINE_VISIBILITY
710 void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args )
711 {
712     new (__storage) _Tp (_VSTD::forward<_Args>(__args)...);
713 }
714
715 template <class _Tp, class _Allocator, class... _Args>
716 inline _LIBCPP_INLINE_VISIBILITY
717 void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
718 {
719     new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...);
720 }
721
722 template <class _Tp, class _Allocator, class... _Args>
723 inline _LIBCPP_INLINE_VISIBILITY
724 void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
725 {
726     new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a);
727 }
728
729 template <class _Tp, class _Allocator, class... _Args>
730 inline _LIBCPP_INLINE_VISIBILITY
731 void __user_alloc_construct (_Tp *__storage, const _Allocator &__a, _Args &&... __args)
732
733     __user_alloc_construct_impl( 
734              __uses_alloc_ctor<_Tp, _Allocator>(), 
735              __storage, __a, _VSTD::forward<_Args>(__args)...
736         );
737 }
738 #endif  // _LIBCPP_HAS_NO_VARIADICS
739
740 _LIBCPP_END_NAMESPACE_STD
741
742 #endif  // _LIBCPP_FUNCTIONAL_BASE