2 //===----------------------------------------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_EXPERIMENTAL___MEMORY
12 #define _LIBCPP_EXPERIMENTAL___MEMORY
14 #include <experimental/__config>
15 #include <experimental/utility> // for erased_type
16 #include <__functional_base>
17 #include <type_traits>
19 _LIBCPP_BEGIN_NAMESPACE_LFTS
22 class _Tp, class _Alloc
23 , bool = uses_allocator<_Tp, _Alloc>::value
24 , bool = __has_allocator_type<_Tp>::value
26 struct __lfts_uses_allocator : public false_type {};
28 template <class _Tp, class _Alloc>
29 struct __lfts_uses_allocator<_Tp, _Alloc, false, false> : public false_type {};
31 template <class _Tp, class _Alloc, bool HasAlloc>
32 struct __lfts_uses_allocator<_Tp, _Alloc, true, HasAlloc> : public true_type {};
34 template <class _Tp, class _Alloc>
35 struct __lfts_uses_allocator<_Tp, _Alloc, false, true>
36 : public integral_constant<bool
37 , is_convertible<_Alloc, typename _Tp::allocator_type>::value
38 || is_same<erased_type, typename _Tp::allocator_type>::value
42 template <bool _UsesAlloc, class _Tp, class _Alloc, class ..._Args>
43 struct __lfts_uses_alloc_ctor_imp
45 static const int value = 0;
48 template <class _Tp, class _Alloc, class ..._Args>
49 struct __lfts_uses_alloc_ctor_imp<true, _Tp, _Alloc, _Args...>
51 static const bool __ic_first
52 = is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
54 static const bool __ic_second =
58 is_constructible<_Tp, _Args..., _Alloc>
61 static_assert(__ic_first || __ic_second,
62 "Request for uses allocator construction is ill-formed");
64 static const int value = __ic_first ? 1 : 2;
67 template <class _Tp, class _Alloc, class ..._Args>
68 struct __lfts_uses_alloc_ctor
69 : integral_constant<int,
70 __lfts_uses_alloc_ctor_imp<
71 __lfts_uses_allocator<_Tp, _Alloc>::value
72 , _Tp, _Alloc, _Args...
77 template <class _Tp, class _Alloc, class ..._Args>
78 inline _LIBCPP_INLINE_VISIBILITY
79 void __lfts_user_alloc_construct(
80 _Tp * __store, const _Alloc & __a, _Args &&... __args)
82 _VSTD::__user_alloc_construct_impl(
83 typename __lfts_uses_alloc_ctor<_Tp, _Alloc, _Args...>::type()
84 , __store, __a, _VSTD::forward<_Args>(__args)...
88 _LIBCPP_END_NAMESPACE_LFTS
90 #endif /* _LIBCPP_EXPERIMENTAL___MEMORY */