]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/uses_allocator.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / uses_allocator.h
1 // Uses-allocator Construction -*- C++ -*-
2
3 // Copyright (C) 2010-2016 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24
25 #ifndef _USES_ALLOCATOR_H
26 #define _USES_ALLOCATOR_H 1
27
28 #if __cplusplus < 201103L
29 # include <bits/c++0x_warning.h>
30 #else
31
32 #include <type_traits>
33
34 namespace std _GLIBCXX_VISIBILITY(default)
35 {
36 _GLIBCXX_BEGIN_NAMESPACE_VERSION
37
38 struct __erased_type { };
39
40 template<typename _Alloc, typename _Tp>
41 using __is_erased_or_convertible
42 = __or_<is_same<_Tp, __erased_type>, is_convertible<_Alloc, _Tp>>;
43
44 /// [allocator.tag]
45 struct allocator_arg_t { explicit allocator_arg_t() = default; };
46
47 constexpr allocator_arg_t allocator_arg = allocator_arg_t();
48
49 template<typename _Tp, typename _Alloc, typename = __void_t<>>
50 struct __uses_allocator_helper
51 : false_type { };
52
53 template<typename _Tp, typename _Alloc>
54 struct __uses_allocator_helper<_Tp, _Alloc,
55 __void_t<typename _Tp::allocator_type>>
56 : __is_erased_or_convertible<_Alloc, typename _Tp::allocator_type>::type
57 { };
58
59 /// [allocator.uses.trait]
60 template<typename _Tp, typename _Alloc>
61 struct uses_allocator
62 : __uses_allocator_helper<_Tp, _Alloc>::type
63 { };
64
65 struct __uses_alloc_base { };
66
67 struct __uses_alloc0 : __uses_alloc_base
68 {
69 struct _Sink { void operator=(const void*) { } } _M_a;
70 };
71
72 template<typename _Alloc>
73 struct __uses_alloc1 : __uses_alloc_base { const _Alloc* _M_a; };
74
75 template<typename _Alloc>
76 struct __uses_alloc2 : __uses_alloc_base { const _Alloc* _M_a; };
77
78 template<bool, typename _Tp, typename _Alloc, typename... _Args>
79 struct __uses_alloc;
80
81 template<typename _Tp, typename _Alloc, typename... _Args>
82 struct __uses_alloc<true, _Tp, _Alloc, _Args...>
83 : conditional<
84 is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value,
85 __uses_alloc1<_Alloc>,
86 __uses_alloc2<_Alloc>>::type
87 { };
88
89 template<typename _Tp, typename _Alloc, typename... _Args>
90 struct __uses_alloc<false, _Tp, _Alloc, _Args...>
91 : __uses_alloc0 { };
92
93 template<typename _Tp, typename _Alloc, typename... _Args>
94 using __uses_alloc_t =
95 __uses_alloc<uses_allocator<_Tp, _Alloc>::value, _Tp, _Alloc, _Args...>;
96
97 template<typename _Tp, typename _Alloc, typename... _Args>
98 inline __uses_alloc_t<_Tp, _Alloc, _Args...>
99 __use_alloc(const _Alloc& __a)
100 {
101 __uses_alloc_t<_Tp, _Alloc, _Args...> __ret;
102 __ret._M_a = &__a;
103 return __ret;
104 }
105
106 _GLIBCXX_END_NAMESPACE_VERSION
107 } // namespace std
108
109 #endif
110 #endif