| 1 |
// Compatibility symbols for previous versions, C++0x bits -*- C++ -*- |
| 2 |
|
| 3 |
// Copyright (C) 2009-2025 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 |
#define _GLIBCXX_COMPATIBILITY_CXX0X |
| 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 |
| 31 |
#include <string> |
| 32 |
#include <system_error> |
| 33 |
#include <cstring> |
| 34 |
#undef error_category |
| 35 |
#undef system_category |
| 36 |
#undef generic_category |
| 37 |
#undef _V2 |
| 38 |
|
| 39 |
#if __cplusplus < 201103L |
| 40 |
# error "compatibility-c++0x.cc must be compiled with -std=gnu++0x" |
| 41 |
#endif |
| 42 |
|
| 43 |
#if _GLIBCXX_INLINE_VERSION |
| 44 |
# error "compatibility-thread-c++0x.cc is not needed for gnu-versioned-namespace" |
| 45 |
#endif |
| 46 |
|
| 47 |
#ifdef _GLIBCXX_SHARED |
| 48 |
|
| 49 |
namespace std _GLIBCXX_VISIBILITY(default) |
| 50 |
{ |
| 51 |
_GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 52 |
|
| 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 |
|
| 68 |
// We need these due to the symbols exported since GLIBCXX_3.4.10. |
| 69 |
// See libstdc++/41662 for details. |
| 70 |
|
| 71 |
#ifndef _GLIBCXX_LONG_DOUBLE_COMPAT_IMPL |
| 72 |
template<> |
| 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()); } |
| 81 |
|
| 82 |
template<> |
| 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()); } |
| 91 |
|
| 92 |
#ifdef _GLIBCXX_USE_WCHAR_T |
| 93 |
template<> |
| 94 |
struct hash<wstring> |
| 95 |
{ |
| 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)); } |
| 102 |
|
| 103 |
template<> |
| 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)); } |
| 112 |
#endif |
| 113 |
#endif |
| 114 |
|
| 115 |
template<> |
| 116 |
struct hash<error_code> |
| 117 |
{ |
| 118 |
size_t operator()(error_code) const; |
| 119 |
}; |
| 120 |
|
| 121 |
size_t |
| 122 |
hash<error_code>::operator()(error_code __e) const |
| 123 |
{ |
| 124 |
const size_t __tmp = std::_Hash_impl::hash(__e.value()); |
| 125 |
return std::_Hash_impl::__hash_combine(&__e.category(), __tmp); |
| 126 |
} |
| 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 |
| 138 |
|
| 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 |
|
| 178 |
// gcc-4.9.0 |
| 179 |
// LWG 2145 changes this constructor to constexpr i.e. inline |
| 180 |
error_category::error_category() noexcept = default; |
| 181 |
|
| 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 |
|
| 259 |
_GLIBCXX_END_NAMESPACE_VERSION |
| 260 |
} |
| 261 |
#endif |