]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/src/c++11/compatibility-c++0x.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / src / c++11 / compatibility-c++0x.cc
CommitLineData
4a85780b 1// Compatibility symbols for previous versions, C++0x bits -*- C++ -*-
9adfc73c 2
a945c346 3// Copyright (C) 2009-2024 Free Software Foundation, Inc.
9adfc73c
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
9adfc73c
BK
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
748086b7
JJ
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.
9adfc73c 19
748086b7
JJ
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/>.
9adfc73c 24
15d81a3c 25#define _GLIBCXX_COMPATIBILITY_CXX0X
34a2b755
JW
26#define _GLIBCXX_USE_CXX11_ABI 0
27#define error_category error_categoryxx
28#define system_category system_categoryxx
29#define generic_category generic_categoryxx
30#define _V2 _V2xx
a00e3769 31#include <string>
9adfc73c 32#include <system_error>
34a2b755
JW
33#include <cstring>
34#undef error_category
35#undef system_category
36#undef generic_category
37#undef _V2
9adfc73c 38
734f5023 39#if __cplusplus < 201103L
4a85780b 40# error "compatibility-c++0x.cc must be compiled with -std=gnu++0x"
a00e3769
BK
41#endif
42
357d6fcd
JW
43#if _GLIBCXX_INLINE_VERSION
44# error "compatibility-thread-c++0x.cc is not needed for gnu-versioned-namespace"
45#endif
46
ac6d1200 47#ifdef _GLIBCXX_SHARED
0b284728 48
12ffa228 49namespace std _GLIBCXX_VISIBILITY(default)
9adfc73c 50{
4a15d842
FD
51_GLIBCXX_BEGIN_NAMESPACE_VERSION
52
afd88205
BK
53 // gcc-4.4.0
54 // <mutex> exported std::lock_error
55#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
56 class lock_error : public exception
57 {
58 public:
59 virtual const char*
60 _GLIBCXX_CONST what() const throw();
61 };
62
63 const char*
64 lock_error::what() const throw()
65 { return "std::lock_error"; }
66#endif
67
4a85780b
PC
68 // We need these due to the symbols exported since GLIBCXX_3.4.10.
69 // See libstdc++/41662 for details.
3d68714e 70
2dd3121f
PC
71#ifndef _GLIBCXX_LONG_DOUBLE_COMPAT_IMPL
72 template<>
92637e93
PC
73 struct hash<string>
74 {
75 size_t operator()(string) const;
76 };
77
78 size_t
79 hash<string>::operator()(string __s) const
80 { return _Hash_impl::hash(__s.data(), __s.length()); }
2dd3121f
PC
81
82 template<>
92637e93
PC
83 struct hash<const string&>
84 {
85 size_t operator()(const string&) const;
86 };
87
88 size_t
89 hash<const string&>::operator()(const string& __s) const
90 { return _Hash_impl::hash(__s.data(), __s.length()); }
2dd3121f
PC
91
92#ifdef _GLIBCXX_USE_WCHAR_T
93 template<>
92637e93 94 struct hash<wstring>
f92ab29f 95 {
92637e93
PC
96 size_t operator()(wstring) const;
97 };
98
99 size_t
100 hash<wstring>::operator()(wstring __s) const
101 { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); }
2dd3121f
PC
102
103 template<>
92637e93
PC
104 struct hash<const wstring&>
105 {
106 size_t operator()(const wstring&) const;
107 };
108
109 size_t
110 hash<const wstring&>::operator()(const wstring& __s) const
111 { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); }
2dd3121f
PC
112#endif
113#endif
a00e3769 114
9adfc73c 115 template<>
92637e93 116 struct hash<error_code>
5c8db18a 117 {
92637e93
PC
118 size_t operator()(error_code) const;
119 };
1b97ec17 120
92637e93
PC
121 size_t
122 hash<error_code>::operator()(error_code __e) const
123 {
fe6fb0d1
JW
124 const size_t __tmp = std::_Hash_impl::hash(__e.value());
125 return std::_Hash_impl::__hash_combine(&__e.category(), __tmp);
92637e93 126 }
1b97ec17
BK
127
128 // gcc-4.7.0
129 // <chrono> changes is_monotonic to is_steady.
130 namespace chrono
131 {
132 struct system_clock
133 {
134 static constexpr bool is_monotonic = false;
135 };
136 constexpr bool system_clock::is_monotonic;
137 } // namespace chrono
f891e5d1 138
34a2b755
JW
139 // gcc-5 replaces this with _V2::error_category
140 class error_category
141 {
142 public:
143 error_category() noexcept;
144
145 virtual ~error_category();
146
147 error_category(const error_category&) = delete;
148 error_category& operator=(const error_category&) = delete;
149
150 virtual const char*
151 name() const noexcept = 0;
152
153 virtual string
154 message(int) const = 0;
155
156 virtual error_condition
157 default_error_condition(int __i) const noexcept;
158
159 virtual bool
160 equivalent(int __i, const error_condition& __cond) const noexcept;
161
162 virtual bool
163 equivalent(const error_code& __code, int __i) const noexcept;
164
165 bool
166 operator<(const error_category& __other) const noexcept
167 { return less<const error_category*>()(this, &__other); }
168
169 bool
170 operator==(const error_category& __other) const noexcept
171 { return this == &__other; }
172
173 bool
174 operator!=(const error_category& __other) const noexcept
175 { return this != &__other; }
176 };
177
f891e5d1
JW
178 // gcc-4.9.0
179 // LWG 2145 changes this constructor to constexpr i.e. inline
180 error_category::error_category() noexcept = default;
1b97ec17 181
34a2b755
JW
182 error_category::~error_category() noexcept = default;
183
184 namespace
185 {
186 using std::string;
187
188 struct generic_error_category : public std::error_category
189 {
190 virtual const char*
191 name() const noexcept
192 { return "generic"; }
193
194 virtual string
195 message(int i) const
196 {
197 // XXX locale issues: how does one get or set loc.
198 // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc)
199 return string(strerror(i));
200 }
201 };
202
203 struct system_error_category : public std::error_category
204 {
205 virtual const char*
206 name() const noexcept
207 { return "system"; }
208
209 virtual string
210 message(int i) const
211 {
212 // XXX locale issues: how does one get or set loc.
213 // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc)
214 return string(strerror(i));
215 }
216 };
217
218 const generic_error_category generic_category_instance{};
219 const system_error_category system_category_instance{};
220 }
221
222 const error_category&
223 system_category() noexcept { return system_category_instance; }
224
225 const error_category&
226 generic_category() noexcept { return generic_category_instance; }
227
228 namespace _V2
229 {
230 _GLIBCXX_CONST const error_categoryxx& system_category() noexcept;
231 _GLIBCXX_CONST const error_categoryxx& generic_category() noexcept;
232 }
233
234 error_condition
235 error_category::default_error_condition(int __i) const noexcept
236 {
237 if (*this == system_category())
238 return error_condition(__i, _V2::system_category());
239 return error_condition(__i, _V2::generic_category());
240 }
241
242 bool
243 error_category::equivalent(int __i,
244 const error_condition& __cond) const noexcept
245 { return default_error_condition(__i) == __cond; }
246
247 bool
248 error_category::equivalent(const error_code& __code, int __i) const noexcept
249 {
250 if (*this == system_category()
251 && __code.category() == _V2::system_category())
252 return __code.value() == __i;
253 if (*this == generic_category()
254 && __code.category() == _V2::generic_category())
255 return __code.value() == __i;
256 return false;
257 }
258
4a15d842 259_GLIBCXX_END_NAMESPACE_VERSION
34a2b755 260}
0b284728 261#endif