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 <__type_traits/integral_constant.h> 16 #include <__type_traits/is_constructible.h> 17 #include <__type_traits/remove_cvref.h> 18 #include <__utility/forward.h> 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 struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { 27 explicit allocator_arg_t() = default; 28 }; 29 30 #if _LIBCPP_STD_VER >= 17 31 inline constexpr allocator_arg_t allocator_arg = allocator_arg_t(); 32 #elif !defined(_LIBCPP_CXX03_LANG) 33 constexpr allocator_arg_t allocator_arg = allocator_arg_t(); 34 #endif 35 36 #ifndef _LIBCPP_CXX03_LANG 37 38 // allocator construction 39 40 template <class _Tp, class _Alloc, class... _Args> 41 struct __uses_alloc_ctor_imp { 42 typedef _LIBCPP_NODEBUG __remove_cvref_t<_Alloc> _RawAlloc; 43 static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value; 44 static const bool __ic = is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; 45 static const int value = __ua ? 2 - __ic : 0; 46 }; 47 48 template <class _Tp, class _Alloc, class... _Args> 49 struct __uses_alloc_ctor : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value> {}; 50 51 template <class _Tp, class _Allocator, class... _Args> 52 inline _LIBCPP_HIDE_FROM_ABI void 53 __user_alloc_construct_impl(integral_constant<int, 0>, _Tp* __storage, const _Allocator&, _Args&&... __args) { 54 new (__storage) _Tp(std::forward<_Args>(__args)...); 55 } 56 57 // FIXME: This should have a version which takes a non-const alloc. 58 template <class _Tp, class _Allocator, class... _Args> 59 inline _LIBCPP_HIDE_FROM_ABI void 60 __user_alloc_construct_impl(integral_constant<int, 1>, _Tp* __storage, const _Allocator& __a, _Args&&... __args) { 61 new (__storage) _Tp(allocator_arg, __a, std::forward<_Args>(__args)...); 62 } 63 64 // FIXME: This should have a version which takes a non-const alloc. 65 template <class _Tp, class _Allocator, class... _Args> 66 inline _LIBCPP_HIDE_FROM_ABI void 67 __user_alloc_construct_impl(integral_constant<int, 2>, _Tp* __storage, const _Allocator& __a, _Args&&... __args) { 68 new (__storage) _Tp(std::forward<_Args>(__args)..., __a); 69 } 70 71 #endif // _LIBCPP_CXX03_LANG 72 73 _LIBCPP_END_NAMESPACE_STD 74 75 #endif // _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H 76