1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H 11 #define _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H 12 13 #include <__config> 14 #include <__memory/uses_allocator.h> 15 #include <__utility/forward.h> 16 #include <type_traits> 17 18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 19 #pragma GCC system_header 20 #endif 21 22 _LIBCPP_BEGIN_NAMESPACE_STD 23 24 struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = default; }; 25 26 #if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) 27 extern _LIBCPP_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg; 28 #else 29 /* inline */ constexpr allocator_arg_t allocator_arg = allocator_arg_t(); 30 #endif 31 32 #ifndef _LIBCPP_CXX03_LANG 33 34 // allocator construction 35 36 template <class _Tp, class _Alloc, class ..._Args> 37 struct __uses_alloc_ctor_imp 38 { 39 typedef _LIBCPP_NODEBUG typename __uncvref<_Alloc>::type _RawAlloc; 40 static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value; 41 static const bool __ic = 42 is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; 43 static const int value = __ua ? 2 - __ic : 0; 44 }; 45 46 template <class _Tp, class _Alloc, class ..._Args> 47 struct __uses_alloc_ctor 48 : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value> 49 {}; 50 51 template <class _Tp, class _Allocator, class... _Args> 52 inline _LIBCPP_INLINE_VISIBILITY 53 void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args ) 54 { 55 new (__storage) _Tp (_VSTD::forward<_Args>(__args)...); 56 } 57 58 // FIXME: This should have a version which takes a non-const alloc. 59 template <class _Tp, class _Allocator, class... _Args> 60 inline _LIBCPP_INLINE_VISIBILITY 61 void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) 62 { 63 new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...); 64 } 65 66 // FIXME: This should have a version which takes a non-const alloc. 67 template <class _Tp, class _Allocator, class... _Args> 68 inline _LIBCPP_INLINE_VISIBILITY 69 void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args ) 70 { 71 new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a); 72 } 73 74 #endif // _LIBCPP_CXX03_LANG 75 76 _LIBCPP_END_NAMESPACE_STD 77 78 #endif // _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H 79