__memory 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_EXPERIMENTAL___MEMORY
  11. #define _LIBCPP_EXPERIMENTAL___MEMORY
  12. #include <experimental/__config>
  13. #include <experimental/utility> // for erased_type
  14. #include <__functional_base>
  15. #include <type_traits>
  16. _LIBCPP_BEGIN_NAMESPACE_LFTS
  17. template <
  18. class _Tp, class _Alloc
  19. , bool = uses_allocator<_Tp, _Alloc>::value
  20. , bool = __has_allocator_type<_Tp>::value
  21. >
  22. struct __lfts_uses_allocator : public false_type {};
  23. template <class _Tp, class _Alloc>
  24. struct __lfts_uses_allocator<_Tp, _Alloc, false, false> : public false_type {};
  25. template <class _Tp, class _Alloc, bool HasAlloc>
  26. struct __lfts_uses_allocator<_Tp, _Alloc, true, HasAlloc> : public true_type {};
  27. template <class _Tp, class _Alloc>
  28. struct __lfts_uses_allocator<_Tp, _Alloc, false, true>
  29. : public integral_constant<bool
  30. , is_convertible<_Alloc, typename _Tp::allocator_type>::value
  31. || is_same<erased_type, typename _Tp::allocator_type>::value
  32. >
  33. {};
  34. template <bool _UsesAlloc, class _Tp, class _Alloc, class ..._Args>
  35. struct __lfts_uses_alloc_ctor_imp
  36. {
  37. static const int value = 0;
  38. };
  39. template <class _Tp, class _Alloc, class ..._Args>
  40. struct __lfts_uses_alloc_ctor_imp<true, _Tp, _Alloc, _Args...>
  41. {
  42. static const bool __ic_first
  43. = is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
  44. static const bool __ic_second =
  45. conditional<
  46. __ic_first,
  47. false_type,
  48. is_constructible<_Tp, _Args..., _Alloc>
  49. >::type::value;
  50. static_assert(__ic_first || __ic_second,
  51. "Request for uses allocator construction is ill-formed");
  52. static const int value = __ic_first ? 1 : 2;
  53. };
  54. template <class _Tp, class _Alloc, class ..._Args>
  55. struct __lfts_uses_alloc_ctor
  56. : integral_constant<int,
  57. __lfts_uses_alloc_ctor_imp<
  58. __lfts_uses_allocator<_Tp, _Alloc>::value
  59. , _Tp, _Alloc, _Args...
  60. >::value
  61. >
  62. {};
  63. template <class _Tp, class _Alloc, class ..._Args>
  64. inline _LIBCPP_INLINE_VISIBILITY
  65. void __lfts_user_alloc_construct(
  66. _Tp * __store, const _Alloc & __a, _Args &&... __args)
  67. {
  68. _VSTD::__user_alloc_construct_impl(
  69. typename __lfts_uses_alloc_ctor<_Tp, _Alloc, _Args...>::type()
  70. , __store, __a, _VSTD::forward<_Args>(__args)...
  71. );
  72. }
  73. _LIBCPP_END_NAMESPACE_LFTS
  74. #endif /* _LIBCPP_EXPERIMENTAL___MEMORY */