1// Compatibility symbols for previous versions, C++0x bits -*- C++ -*- 2 3// Copyright (C) 2009-2015 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#ifdef _GLIBCXX_SHARED 44 45namespace std _GLIBCXX_VISIBILITY(default) 46{ 47 // gcc-4.4.0 48 // <mutex> exported std::lock_error 49#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) 50 class lock_error : public exception 51 { 52 public: 53 virtual const char* 54 _GLIBCXX_CONST what() const throw(); 55 }; 56 57 const char* 58 lock_error::what() const throw() 59 { return "std::lock_error"; } 60#endif 61 62 // We need these due to the symbols exported since GLIBCXX_3.4.10. 63 // See libstdc++/41662 for details. 64 65#ifndef _GLIBCXX_LONG_DOUBLE_COMPAT_IMPL 66 template<> 67 struct hash<string> 68 { 69 size_t operator()(string) const; 70 }; 71 72 size_t 73 hash<string>::operator()(string __s) const 74 { return _Hash_impl::hash(__s.data(), __s.length()); } 75 76 template<> 77 struct hash<const string&> 78 { 79 size_t operator()(const string&) const; 80 }; 81 82 size_t 83 hash<const string&>::operator()(const string& __s) const 84 { return _Hash_impl::hash(__s.data(), __s.length()); } 85 86#ifdef _GLIBCXX_USE_WCHAR_T 87 template<> 88 struct hash<wstring> 89 { 90 size_t operator()(wstring) const; 91 }; 92 93 size_t 94 hash<wstring>::operator()(wstring __s) const 95 { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); } 96 97 template<> 98 struct hash<const wstring&> 99 { 100 size_t operator()(const wstring&) const; 101 }; 102 103 size_t 104 hash<const wstring&>::operator()(const wstring& __s) const 105 { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); } 106#endif 107#endif 108 109 template<> 110 struct hash<error_code> 111 { 112 size_t operator()(error_code) const; 113 }; 114 115 size_t 116 hash<error_code>::operator()(error_code __e) const 117 { 118 const size_t __tmp = std::_Hash_impl::hash(__e._M_value); 119 return std::_Hash_impl::__hash_combine(__e._M_cat, __tmp); 120 } 121 122 // gcc-4.7.0 123 // <chrono> changes is_monotonic to is_steady. 124 namespace chrono 125 { 126 struct system_clock 127 { 128 static constexpr bool is_monotonic = false; 129 }; 130 constexpr bool system_clock::is_monotonic; 131 } // namespace chrono 132 133_GLIBCXX_BEGIN_NAMESPACE_VERSION 134 // gcc-5 replaces this with _V2::error_category 135 class error_category 136 { 137 public: 138 error_category() noexcept; 139 140 virtual ~error_category(); 141 142 error_category(const error_category&) = delete; 143 error_category& operator=(const error_category&) = delete; 144 145 virtual const char* 146 name() const noexcept = 0; 147 148 virtual string 149 message(int) const = 0; 150 151 virtual error_condition 152 default_error_condition(int __i) const noexcept; 153 154 virtual bool 155 equivalent(int __i, const error_condition& __cond) const noexcept; 156 157 virtual bool 158 equivalent(const error_code& __code, int __i) const noexcept; 159 160 bool 161 operator<(const error_category& __other) const noexcept 162 { return less<const error_category*>()(this, &__other); } 163 164 bool 165 operator==(const error_category& __other) const noexcept 166 { return this == &__other; } 167 168 bool 169 operator!=(const error_category& __other) const noexcept 170 { return this != &__other; } 171 }; 172_GLIBCXX_END_NAMESPACE_VERSION 173 174 // gcc-4.9.0 175 // LWG 2145 changes this constructor to constexpr i.e. inline 176 error_category::error_category() noexcept = default; 177 178 error_category::~error_category() noexcept = default; 179 180 namespace 181 { 182 using std::string; 183 184 struct generic_error_category : public std::error_category 185 { 186 virtual const char* 187 name() const noexcept 188 { return "generic"; } 189 190 virtual string 191 message(int i) const 192 { 193 // XXX locale issues: how does one get or set loc. 194 // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc) 195 return string(strerror(i)); 196 } 197 }; 198 199 struct system_error_category : public std::error_category 200 { 201 virtual const char* 202 name() const noexcept 203 { return "system"; } 204 205 virtual string 206 message(int i) const 207 { 208 // XXX locale issues: how does one get or set loc. 209 // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc) 210 return string(strerror(i)); 211 } 212 }; 213 214 const generic_error_category generic_category_instance{}; 215 const system_error_category system_category_instance{}; 216 } 217 218_GLIBCXX_BEGIN_NAMESPACE_VERSION 219 const error_category& 220 system_category() noexcept { return system_category_instance; } 221 222 const error_category& 223 generic_category() noexcept { return generic_category_instance; } 224 225 namespace _V2 226 { 227 _GLIBCXX_CONST const error_categoryxx& system_category() noexcept; 228 _GLIBCXX_CONST const error_categoryxx& generic_category() noexcept; 229 } 230_GLIBCXX_END_NAMESPACE_VERSION 231 232 error_condition 233 error_category::default_error_condition(int __i) const noexcept 234 { 235 if (*this == system_category()) 236 return error_condition(__i, _V2::system_category()); 237 return error_condition(__i, _V2::generic_category()); 238 } 239 240 bool 241 error_category::equivalent(int __i, 242 const error_condition& __cond) const noexcept 243 { return default_error_condition(__i) == __cond; } 244 245 bool 246 error_category::equivalent(const error_code& __code, int __i) const noexcept 247 { 248 if (*this == system_category() 249 && __code.category() == _V2::system_category()) 250 return __code.value() == __i; 251 if (*this == generic_category() 252 && __code.category() == _V2::generic_category()) 253 return __code.value() == __i; 254 return false; 255 } 256 257} 258#endif 259