]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/ext/alloc_traits.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / ext / alloc_traits.h
CommitLineData
1dfc0951 1// Allocator traits -*- C++ -*-
2
fbd26352 3// Copyright (C) 2011-2019 Free Software Foundation, Inc.
1dfc0951 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/** @file ext/alloc_traits.h
26 * This file is a GNU extension to the Standard C++ Library.
27 */
28
29#ifndef _EXT_ALLOC_TRAITS_H
30#define _EXT_ALLOC_TRAITS_H 1
31
32#pragma GCC system_header
33
0c8766b1 34#if __cplusplus >= 201103L
d2c24105 35# include <bits/move.h>
1dfc0951 36# include <bits/alloc_traits.h>
37#else
38# include <bits/allocator.h> // for __alloc_swap
39#endif
40
41namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
42{
43_GLIBCXX_BEGIN_NAMESPACE_VERSION
44
3f506c52 45/**
141d9a97 46 * @brief Uniform interface to C++98 and C++11 allocators.
3f506c52 47 * @ingroup allocators
48*/
c2b91adc 49template<typename _Alloc, typename = typename _Alloc::value_type>
1dfc0951 50 struct __alloc_traits
0c8766b1 51#if __cplusplus >= 201103L
1dfc0951 52 : std::allocator_traits<_Alloc>
53#endif
54 {
55 typedef _Alloc allocator_type;
0c8766b1 56#if __cplusplus >= 201103L
1dfc0951 57 typedef std::allocator_traits<_Alloc> _Base_type;
58 typedef typename _Base_type::value_type value_type;
59 typedef typename _Base_type::pointer pointer;
60 typedef typename _Base_type::const_pointer const_pointer;
61 typedef typename _Base_type::size_type size_type;
3c64f134 62 typedef typename _Base_type::difference_type difference_type;
7deb91c7 63 // C++11 allocators do not define reference or const_reference
1dfc0951 64 typedef value_type& reference;
65 typedef const value_type& const_reference;
66 using _Base_type::allocate;
67 using _Base_type::deallocate;
68 using _Base_type::construct;
69 using _Base_type::destroy;
ebaf89b0 70 using _Base_type::max_size;
1dfc0951 71
3f506c52 72 private:
73 template<typename _Ptr>
7deb91c7 74 using __is_custom_pointer
75 = std::__and_<std::is_same<pointer, _Ptr>,
76 std::__not_<std::is_pointer<_Ptr>>>;
3f506c52 77
78 public:
ebaf89b0 79 // overload construct for non-standard pointer types
3f506c52 80 template<typename _Ptr, typename... _Args>
81 static typename std::enable_if<__is_custom_pointer<_Ptr>::value>::type
82 construct(_Alloc& __a, _Ptr __p, _Args&&... __args)
e9f84d4c 83 noexcept(noexcept(_Base_type::construct(__a, std::__to_address(__p),
84 std::forward<_Args>(__args)...)))
3f506c52 85 {
0fdf8c8d 86 _Base_type::construct(__a, std::__to_address(__p),
3f506c52 87 std::forward<_Args>(__args)...);
88 }
89
ebaf89b0 90 // overload destroy for non-standard pointer types
3f506c52 91 template<typename _Ptr>
92 static typename std::enable_if<__is_custom_pointer<_Ptr>::value>::type
93 destroy(_Alloc& __a, _Ptr __p)
e9f84d4c 94 noexcept(noexcept(_Base_type::destroy(__a, std::__to_address(__p))))
0fdf8c8d 95 { _Base_type::destroy(__a, std::__to_address(__p)); }
3f506c52 96
1dfc0951 97 static _Alloc _S_select_on_copy(const _Alloc& __a)
98 { return _Base_type::select_on_container_copy_construction(__a); }
99
100 static void _S_on_swap(_Alloc& __a, _Alloc& __b)
101 { std::__alloc_on_swap(__a, __b); }
102
103 static constexpr bool _S_propagate_on_copy_assign()
104 { return _Base_type::propagate_on_container_copy_assignment::value; }
105
106 static constexpr bool _S_propagate_on_move_assign()
107 { return _Base_type::propagate_on_container_move_assignment::value; }
108
109 static constexpr bool _S_propagate_on_swap()
110 { return _Base_type::propagate_on_container_swap::value; }
111
3f506c52 112 static constexpr bool _S_always_equal()
141d9a97 113 { return _Base_type::is_always_equal::value; }
3f506c52 114
115 static constexpr bool _S_nothrow_move()
116 { return _S_propagate_on_move_assign() || _S_always_equal(); }
117
ebaf89b0 118 template<typename _Tp>
119 struct rebind
e8564ee9 120 { typedef typename _Base_type::template rebind_alloc<_Tp> other; };
1dfc0951 121#else
122
123 typedef typename _Alloc::pointer pointer;
124 typedef typename _Alloc::const_pointer const_pointer;
125 typedef typename _Alloc::value_type value_type;
126 typedef typename _Alloc::reference reference;
127 typedef typename _Alloc::const_reference const_reference;
128 typedef typename _Alloc::size_type size_type;
3c64f134 129 typedef typename _Alloc::difference_type difference_type;
1dfc0951 130
131 static pointer
132 allocate(_Alloc& __a, size_type __n)
133 { return __a.allocate(__n); }
134
135 static void deallocate(_Alloc& __a, pointer __p, size_type __n)
136 { __a.deallocate(__p, __n); }
137
138 template<typename _Tp>
139 static void construct(_Alloc& __a, pointer __p, const _Tp& __arg)
140 { __a.construct(__p, __arg); }
141
142 static void destroy(_Alloc& __a, pointer __p)
143 { __a.destroy(__p); }
144
ebaf89b0 145 static size_type max_size(const _Alloc& __a)
146 { return __a.max_size(); }
147
1dfc0951 148 static const _Alloc& _S_select_on_copy(const _Alloc& __a) { return __a; }
149
150 static void _S_on_swap(_Alloc& __a, _Alloc& __b)
151 {
152 // _GLIBCXX_RESOLVE_LIB_DEFECTS
153 // 431. Swapping containers with unequal allocators.
154 std::__alloc_swap<_Alloc>::_S_do_it(__a, __b);
155 }
ebaf89b0 156
157 template<typename _Tp>
158 struct rebind
159 { typedef typename _Alloc::template rebind<_Tp>::other other; };
1dfc0951 160#endif
161 };
162
163_GLIBCXX_END_NAMESPACE_VERSION
f933d589 164} // namespace __gnu_cxx
1dfc0951 165
166#endif