summaryrefslogtreecommitdiff
path: root/data/iphoneos-sdk/v1/experimental/__memory
blob: 229fea605bfd33ad6f7c4491fab72f0b82356181 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP_EXPERIMENTAL___MEMORY
#define _LIBCPP_EXPERIMENTAL___MEMORY

#include <experimental/__config>
#include <experimental/utility> // for erased_type
#include <__functional_base>
#include <type_traits>

_LIBCPP_BEGIN_NAMESPACE_LFTS

template <
    class _Tp, class _Alloc
  , bool = uses_allocator<_Tp, _Alloc>::value
  , bool = __has_allocator_type<_Tp>::value
  >
struct __lfts_uses_allocator : public false_type {};

template <class _Tp, class _Alloc>
struct __lfts_uses_allocator<_Tp, _Alloc, false, false> : public false_type {};

template <class _Tp, class _Alloc, bool HasAlloc>
struct __lfts_uses_allocator<_Tp, _Alloc, true, HasAlloc> : public true_type {};

template <class _Tp, class _Alloc>
struct __lfts_uses_allocator<_Tp, _Alloc, false, true>
  : public integral_constant<bool
    , is_convertible<_Alloc, typename _Tp::allocator_type>::value
      || is_same<erased_type, typename _Tp::allocator_type>::value
    >
{};

template <bool _UsesAlloc, class _Tp, class _Alloc, class ..._Args>
struct __lfts_uses_alloc_ctor_imp
{
    static const int value = 0;
};

template <class _Tp, class _Alloc, class ..._Args>
struct __lfts_uses_alloc_ctor_imp<true, _Tp, _Alloc, _Args...>
{
    static const bool __ic_first
        = is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;

    static const bool __ic_second =
        conditional<
            __ic_first,
            false_type,
            is_constructible<_Tp, _Args..., _Alloc>
        >::type::value;

    static_assert(__ic_first || __ic_second,
                  "Request for uses allocator construction is ill-formed");

    static const int value = __ic_first ? 1 : 2;
};

template <class _Tp, class _Alloc, class ..._Args>
struct __lfts_uses_alloc_ctor
  : integral_constant<int,
        __lfts_uses_alloc_ctor_imp<
            __lfts_uses_allocator<_Tp, _Alloc>::value
          , _Tp, _Alloc, _Args...
        >::value
    >
{};

template <class _Tp, class _Alloc, class ..._Args>
inline _LIBCPP_INLINE_VISIBILITY
void __lfts_user_alloc_construct(
    _Tp * __store, const _Alloc & __a, _Args &&... __args)
{
    _VSTD::__user_alloc_construct_impl(
        typename __lfts_uses_alloc_ctor<_Tp, _Alloc, _Args...>::type()
       , __store, __a, _VSTD::forward<_Args>(__args)...
       );
}

_LIBCPP_END_NAMESPACE_LFTS

#endif /* _LIBCPP_EXPERIMENTAL___MEMORY */