]>
Commit | Line | Data |
---|---|---|
1 | // Uses-allocator Construction -*- C++ -*- | |
2 | ||
3 | // Copyright (C) 2010-2014 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 | /// [allocator.tag] | |
39 | struct allocator_arg_t { }; | |
40 | ||
41 | constexpr allocator_arg_t allocator_arg = allocator_arg_t(); | |
42 | ||
43 | _GLIBCXX_HAS_NESTED_TYPE(allocator_type) | |
44 | ||
45 | template<typename _Tp, typename _Alloc, | |
46 | bool = __has_allocator_type<_Tp>::value> | |
47 | struct __uses_allocator_helper | |
48 | : public false_type { }; | |
49 | ||
50 | template<typename _Tp, typename _Alloc> | |
51 | struct __uses_allocator_helper<_Tp, _Alloc, true> | |
52 | : public integral_constant<bool, is_convertible<_Alloc, | |
53 | typename _Tp::allocator_type>::value> | |
54 | { }; | |
55 | ||
56 | /// [allocator.uses.trait] | |
57 | template<typename _Tp, typename _Alloc> | |
58 | struct uses_allocator | |
59 | : public integral_constant<bool, | |
60 | __uses_allocator_helper<_Tp, _Alloc>::value> | |
61 | { }; | |
62 | ||
63 | template<typename _Tp, typename _Alloc, typename... _Args> | |
64 | struct __uses_allocator_arg | |
65 | : is_constructible<_Tp, _Alloc, _Args...> | |
66 | { static_assert( uses_allocator<_Tp, _Alloc>::value, "uses allocator" ); }; | |
67 | ||
68 | struct __uses_alloc_base { }; | |
69 | struct __uses_alloc0 : __uses_alloc_base | |
70 | { struct _Anything { _Anything(...) { } } _M_a; }; | |
71 | template<typename _Alloc> | |
72 | struct __uses_alloc1 : __uses_alloc_base { const _Alloc* _M_a; }; | |
73 | template<typename _Alloc> | |
74 | struct __uses_alloc2 : __uses_alloc_base { const _Alloc* _M_a; }; | |
75 | ||
76 | template<bool, typename _Alloc, typename... _Args> | |
77 | struct __uses_alloc; | |
78 | ||
79 | template<typename _Tp, typename _Alloc, typename... _Args> | |
80 | struct __uses_alloc<true, _Tp, _Alloc, _Args...> | |
81 | : conditional< | |
82 | is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value, | |
83 | __uses_alloc1<_Alloc>, | |
84 | __uses_alloc2<_Alloc>>::type | |
85 | { }; | |
86 | ||
87 | template<typename _Tp, typename _Alloc, typename... _Args> | |
88 | struct __uses_alloc<false, _Tp, _Alloc, _Args...> | |
89 | : __uses_alloc0 { }; | |
90 | ||
91 | template<typename _Tp, typename _Alloc, typename... _Args> | |
92 | struct __uses_alloc_impl | |
93 | : __uses_alloc<uses_allocator<_Tp, _Alloc>::value, _Tp, _Alloc, _Args...> | |
94 | { }; | |
95 | ||
96 | template<typename _Tp, typename _Alloc, typename... _Args> | |
97 | __uses_alloc_impl<_Tp, _Alloc, _Args...> | |
98 | __use_alloc(const _Alloc& __a) | |
99 | { | |
100 | __uses_alloc_impl<_Tp, _Alloc, _Args...> __ret; | |
101 | __ret._M_a = &__a; | |
102 | return __ret; | |
103 | } | |
104 | ||
105 | _GLIBCXX_END_NAMESPACE_VERSION | |
106 | } // namespace std | |
107 | ||
108 | #endif | |
109 | #endif |