codekingpro/portable-devtools
114k
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCUDACXX_FUNCTIONAL_BASE11#define _LIBCUDACXX_FUNCTIONAL_BASE12 13#ifndef __cuda_std__14#include <__config>15#include <typeinfo>16#include <exception>17#include <new>18#endif // __cuda_std__19 20#include "__functional/binary_function.h"21#include "__functional/operations.h"22#include "__functional/reference_wrapper.h"23#include "__functional/unary_function.h"24#include "__functional/weak_result_type.h"25#include "__type_traits/integral_constant.h"26#include "__type_traits/is_constructible.h"27#include "__type_traits/is_convertible.h"28#include "__type_traits/remove_cvref.h"29#include "__utility/forward.h"30 31#ifndef __cuda_std__32#include <__pragma_push>33#endif // __cuda_std__34 35#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)36# pragma GCC system_header37#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)38# pragma clang system_header39#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)40# pragma system_header41#endif // no system header42 43_LIBCUDACXX_BEGIN_NAMESPACE_STD44 45// allocator_arg_t46 47struct _LIBCUDACXX_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = default; };48 49#if defined(_LIBCUDACXX_BUILDING_LIBRARY)50extern _LIBCUDACXX_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg;51#else52/* _LIBCUDACXX_INLINE_VAR */ constexpr allocator_arg_t allocator_arg = allocator_arg_t();53#endif54 55// uses_allocator56 57template <class _Tp>58struct __has_allocator_type59{60private:61 struct __two {char __lx; char __lxx;};62 template <class _Up> _LIBCUDACXX_INLINE_VISIBILITY static __two __test(...);63 template <class _Up> _LIBCUDACXX_INLINE_VISIBILITY static char __test(typename _Up::allocator_type* = 0);64public:65 static const bool value = sizeof(__test<_Tp>(0)) == 1;66};67 68template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>69struct __uses_allocator70 : public integral_constant<bool,71 is_convertible<_Alloc, typename _Tp::allocator_type>::value>72{73};74 75template <class _Tp, class _Alloc>76struct __uses_allocator<_Tp, _Alloc, false>77 : public false_type78{79};80 81template <class _Tp, class _Alloc>82struct _LIBCUDACXX_TEMPLATE_VIS uses_allocator83 : public __uses_allocator<_Tp, _Alloc>84{85};86 87#if _LIBCUDACXX_STD_VER > 1488template <class _Tp, class _Alloc>89_LIBCUDACXX_INLINE_VAR constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;90#endif91 92// allocator construction93 94template <class _Tp, class _Alloc, class ..._Args>95struct __uses_alloc_ctor_imp96{97 typedef _LIBCUDACXX_NODEBUG_TYPE __remove_cvref_t<_Alloc> _RawAlloc;98 static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value;99 static const bool __ic =100 is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;101 static const int value = __ua ? 2 - __ic : 0;102};103 104template <class _Tp, class _Alloc, class ..._Args>105struct __uses_alloc_ctor106 : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value>107 {};108 109template <class _Tp, class _Allocator, class... _Args>110inline _LIBCUDACXX_INLINE_VISIBILITY111void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args )112{113 new (__storage) _Tp (_CUDA_VSTD::forward<_Args>(__args)...);114}115 116// FIXME: This should have a version which takes a non-const alloc.117template <class _Tp, class _Allocator, class... _Args>118inline _LIBCUDACXX_INLINE_VISIBILITY119void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )120{121 new (__storage) _Tp (allocator_arg, __a, _CUDA_VSTD::forward<_Args>(__args)...);122}123 124// FIXME: This should have a version which takes a non-const alloc.125template <class _Tp, class _Allocator, class... _Args>126inline _LIBCUDACXX_INLINE_VISIBILITY127void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )128{129 new (__storage) _Tp (_CUDA_VSTD::forward<_Args>(__args)..., __a);130}131 132_LIBCUDACXX_END_NAMESPACE_STD133 134#ifndef __cuda_std__135#include <__pragma_pop>136#endif // __cuda_std__137 138#endif // _LIBCUDACXX_FUNCTIONAL_BASE139 