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___MEMORY_USES_ALLOCATOR_H
11 #define _LIBCPP___MEMORY_USES_ALLOCATOR_H
12 
13 #include <__config>
14 #include <cstddef>
15 #include <type_traits>
16 
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 #pragma GCC system_header
19 #endif
20 
21 _LIBCPP_BEGIN_NAMESPACE_STD
22 
23 template <class _Tp>
24 struct __has_allocator_type
25 {
26 private:
27     struct __two {char __lx; char __lxx;};
28     template <class _Up> static __two __test(...);
29     template <class _Up> static char __test(typename _Up::allocator_type* = 0);
30 public:
31     static const bool value = sizeof(__test<_Tp>(0)) == 1;
32 };
33 
34 template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
35 struct __uses_allocator
36     : public integral_constant<bool,
37         is_convertible<_Alloc, typename _Tp::allocator_type>::value>
38 {
39 };
40 
41 template <class _Tp, class _Alloc>
42 struct __uses_allocator<_Tp, _Alloc, false>
43     : public false_type
44 {
45 };
46 
47 template <class _Tp, class _Alloc>
48 struct _LIBCPP_TEMPLATE_VIS uses_allocator
49     : public __uses_allocator<_Tp, _Alloc>
50 {
51 };
52 
53 #if _LIBCPP_STD_VER > 14
54 template <class _Tp, class _Alloc>
55 _LIBCPP_INLINE_VAR constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;
56 #endif
57 
58 _LIBCPP_END_NAMESPACE_STD
59 
60 #endif // _LIBCPP___MEMORY_USES_ALLOCATOR_H
61