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