xref: /freebsd-src/contrib/llvm-project/libcxx/include/__memory/uses_allocator.h (revision cb14a3fe5122c879eae1fb480ed7ce82a699ddb6)
1fe6060f1SDimitry Andric // -*- C++ -*-
2fe6060f1SDimitry Andric //===----------------------------------------------------------------------===//
3fe6060f1SDimitry Andric //
4fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
6fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7fe6060f1SDimitry Andric //
8fe6060f1SDimitry Andric //===----------------------------------------------------------------------===//
9fe6060f1SDimitry Andric 
10fe6060f1SDimitry Andric #ifndef _LIBCPP___MEMORY_USES_ALLOCATOR_H
11fe6060f1SDimitry Andric #define _LIBCPP___MEMORY_USES_ALLOCATOR_H
12fe6060f1SDimitry Andric 
13fe6060f1SDimitry Andric #include <__config>
14bdd1243dSDimitry Andric #include <__type_traits/is_convertible.h>
15fe6060f1SDimitry Andric #include <cstddef>
16fe6060f1SDimitry Andric 
17fe6060f1SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18fe6060f1SDimitry Andric #  pragma GCC system_header
19fe6060f1SDimitry Andric #endif
20fe6060f1SDimitry Andric 
21fe6060f1SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
22fe6060f1SDimitry Andric 
23fe6060f1SDimitry Andric template <class _Tp>
24*cb14a3feSDimitry Andric struct __has_allocator_type {
25fe6060f1SDimitry Andric private:
26*cb14a3feSDimitry Andric   template <class _Up>
27*cb14a3feSDimitry Andric   static false_type __test(...);
28*cb14a3feSDimitry Andric   template <class _Up>
29*cb14a3feSDimitry Andric   static true_type __test(typename _Up::allocator_type* = 0);
30*cb14a3feSDimitry Andric 
31fe6060f1SDimitry Andric public:
3281ad6265SDimitry Andric   static const bool value = decltype(__test<_Tp>(0))::value;
33fe6060f1SDimitry Andric };
34fe6060f1SDimitry Andric 
35fe6060f1SDimitry Andric template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
36*cb14a3feSDimitry Andric struct __uses_allocator : public integral_constant<bool, is_convertible<_Alloc, typename _Tp::allocator_type>::value> {
37fe6060f1SDimitry Andric };
38fe6060f1SDimitry Andric 
39fe6060f1SDimitry Andric template <class _Tp, class _Alloc>
40*cb14a3feSDimitry Andric struct __uses_allocator<_Tp, _Alloc, false> : public false_type {};
41fe6060f1SDimitry Andric 
42fe6060f1SDimitry Andric template <class _Tp, class _Alloc>
43*cb14a3feSDimitry Andric struct _LIBCPP_TEMPLATE_VIS uses_allocator : public __uses_allocator<_Tp, _Alloc> {};
44fe6060f1SDimitry Andric 
4506c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 17
46fe6060f1SDimitry Andric template <class _Tp, class _Alloc>
4706c3fb27SDimitry Andric inline constexpr bool uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;
48fe6060f1SDimitry Andric #endif
49fe6060f1SDimitry Andric 
50fe6060f1SDimitry Andric _LIBCPP_END_NAMESPACE_STD
51fe6060f1SDimitry Andric 
52fe6060f1SDimitry Andric #endif // _LIBCPP___MEMORY_USES_ALLOCATOR_H
53