1 1.1 joerg // -*- C++ -*- 2 1.1 joerg //===----------------------------------------------------------------------===// 3 1.1 joerg // 4 1.1 joerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 1.1 joerg // See https://llvm.org/LICENSE.txt for license information. 6 1.1 joerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 1.1 joerg // 8 1.1 joerg //===----------------------------------------------------------------------===// 9 1.1 joerg 10 1.1 joerg #ifndef _LIBCPP_EXPERIMENTAL___MEMORY 11 1.1 joerg #define _LIBCPP_EXPERIMENTAL___MEMORY 12 1.1 joerg 13 1.1 joerg #include <experimental/__config> 14 1.1 joerg #include <experimental/utility> // for erased_type 15 1.1 joerg #include <__functional_base> 16 1.1 joerg #include <type_traits> 17 1.1 joerg 18 1.1 joerg _LIBCPP_BEGIN_NAMESPACE_LFTS 19 1.1 joerg 20 1.1 joerg template < 21 1.1 joerg class _Tp, class _Alloc 22 1.1 joerg , bool = uses_allocator<_Tp, _Alloc>::value 23 1.1 joerg , bool = __has_allocator_type<_Tp>::value 24 1.1 joerg > 25 1.1 joerg struct __lfts_uses_allocator : public false_type {}; 26 1.1 joerg 27 1.1 joerg template <class _Tp, class _Alloc> 28 1.1 joerg struct __lfts_uses_allocator<_Tp, _Alloc, false, false> : public false_type {}; 29 1.1 joerg 30 1.1 joerg template <class _Tp, class _Alloc, bool HasAlloc> 31 1.1 joerg struct __lfts_uses_allocator<_Tp, _Alloc, true, HasAlloc> : public true_type {}; 32 1.1 joerg 33 1.1 joerg template <class _Tp, class _Alloc> 34 1.1 joerg struct __lfts_uses_allocator<_Tp, _Alloc, false, true> 35 1.1 joerg : public integral_constant<bool 36 1.1 joerg , is_convertible<_Alloc, typename _Tp::allocator_type>::value 37 1.1 joerg || is_same<erased_type, typename _Tp::allocator_type>::value 38 1.1 joerg > 39 1.1 joerg {}; 40 1.1 joerg 41 1.1 joerg template <bool _UsesAlloc, class _Tp, class _Alloc, class ..._Args> 42 1.1 joerg struct __lfts_uses_alloc_ctor_imp 43 1.1 joerg { 44 1.1 joerg static const int value = 0; 45 1.1 joerg }; 46 1.1 joerg 47 1.1 joerg template <class _Tp, class _Alloc, class ..._Args> 48 1.1 joerg struct __lfts_uses_alloc_ctor_imp<true, _Tp, _Alloc, _Args...> 49 1.1 joerg { 50 1.1 joerg static const bool __ic_first 51 1.1 joerg = is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; 52 1.1 joerg 53 1.1 joerg static const bool __ic_second = 54 1.1 joerg conditional< 55 1.1 joerg __ic_first, 56 1.1 joerg false_type, 57 1.1 joerg is_constructible<_Tp, _Args..., _Alloc> 58 1.1 joerg >::type::value; 59 1.1 joerg 60 1.1 joerg static_assert(__ic_first || __ic_second, 61 1.1 joerg "Request for uses allocator construction is ill-formed"); 62 1.1 joerg 63 1.1 joerg static const int value = __ic_first ? 1 : 2; 64 1.1 joerg }; 65 1.1 joerg 66 1.1 joerg template <class _Tp, class _Alloc, class ..._Args> 67 1.1 joerg struct __lfts_uses_alloc_ctor 68 1.1 joerg : integral_constant<int, 69 1.1 joerg __lfts_uses_alloc_ctor_imp< 70 1.1 joerg __lfts_uses_allocator<_Tp, _Alloc>::value 71 1.1 joerg , _Tp, _Alloc, _Args... 72 1.1 joerg >::value 73 1.1 joerg > 74 1.1 joerg {}; 75 1.1 joerg 76 1.1 joerg template <class _Tp, class _Alloc, class ..._Args> 77 1.1 joerg inline _LIBCPP_INLINE_VISIBILITY 78 1.1 joerg void __lfts_user_alloc_construct( 79 1.1 joerg _Tp * __store, const _Alloc & __a, _Args &&... __args) 80 1.1 joerg { 81 1.1 joerg _VSTD::__user_alloc_construct_impl( 82 1.1 joerg typename __lfts_uses_alloc_ctor<_Tp, _Alloc, _Args...>::type() 83 1.1 joerg , __store, __a, _VSTD::forward<_Args>(__args)... 84 1.1 joerg ); 85 1.1 joerg } 86 1.1 joerg 87 1.1 joerg _LIBCPP_END_NAMESPACE_LFTS 88 1.1 joerg 89 1.1 joerg #endif /* _LIBCPP_EXPERIMENTAL___MEMORY */ 90