PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/contrib/gcc-5.0/libstdc++-v3/src/c++11/compatibility-c++0x.cc

https://gitlab.com/tlevine/DragonFlyBSD
C++ | 258 lines | 179 code | 47 blank | 32 comment | 16 complexity | 2c66f763695c6f4b1982c366a8d5eb86 MD5 | raw file
  1. // Compatibility symbols for previous versions, C++0x bits -*- C++ -*-
  2. // Copyright (C) 2009-2015 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. #define _GLIBCXX_COMPATIBILITY_CXX0X
  21. #define _GLIBCXX_USE_CXX11_ABI 0
  22. #define error_category error_categoryxx
  23. #define system_category system_categoryxx
  24. #define generic_category generic_categoryxx
  25. #define _V2 _V2xx
  26. #include <string>
  27. #include <system_error>
  28. #include <cstring>
  29. #undef error_category
  30. #undef system_category
  31. #undef generic_category
  32. #undef _V2
  33. #if __cplusplus < 201103L
  34. # error "compatibility-c++0x.cc must be compiled with -std=gnu++0x"
  35. #endif
  36. #ifdef _GLIBCXX_SHARED
  37. namespace std _GLIBCXX_VISIBILITY(default)
  38. {
  39. // gcc-4.4.0
  40. // <mutex> exported std::lock_error
  41. #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
  42. class lock_error : public exception
  43. {
  44. public:
  45. virtual const char*
  46. _GLIBCXX_CONST what() const throw();
  47. };
  48. const char*
  49. lock_error::what() const throw()
  50. { return "std::lock_error"; }
  51. #endif
  52. // We need these due to the symbols exported since GLIBCXX_3.4.10.
  53. // See libstdc++/41662 for details.
  54. #ifndef _GLIBCXX_LONG_DOUBLE_COMPAT_IMPL
  55. template<>
  56. struct hash<string>
  57. {
  58. size_t operator()(string) const;
  59. };
  60. size_t
  61. hash<string>::operator()(string __s) const
  62. { return _Hash_impl::hash(__s.data(), __s.length()); }
  63. template<>
  64. struct hash<const string&>
  65. {
  66. size_t operator()(const string&) const;
  67. };
  68. size_t
  69. hash<const string&>::operator()(const string& __s) const
  70. { return _Hash_impl::hash(__s.data(), __s.length()); }
  71. #ifdef _GLIBCXX_USE_WCHAR_T
  72. template<>
  73. struct hash<wstring>
  74. {
  75. size_t operator()(wstring) const;
  76. };
  77. size_t
  78. hash<wstring>::operator()(wstring __s) const
  79. { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); }
  80. template<>
  81. struct hash<const wstring&>
  82. {
  83. size_t operator()(const wstring&) const;
  84. };
  85. size_t
  86. hash<const wstring&>::operator()(const wstring& __s) const
  87. { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); }
  88. #endif
  89. #endif
  90. template<>
  91. struct hash<error_code>
  92. {
  93. size_t operator()(error_code) const;
  94. };
  95. size_t
  96. hash<error_code>::operator()(error_code __e) const
  97. {
  98. const size_t __tmp = std::_Hash_impl::hash(__e._M_value);
  99. return std::_Hash_impl::__hash_combine(__e._M_cat, __tmp);
  100. }
  101. // gcc-4.7.0
  102. // <chrono> changes is_monotonic to is_steady.
  103. namespace chrono
  104. {
  105. struct system_clock
  106. {
  107. static constexpr bool is_monotonic = false;
  108. };
  109. constexpr bool system_clock::is_monotonic;
  110. } // namespace chrono
  111. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  112. // gcc-5 replaces this with _V2::error_category
  113. class error_category
  114. {
  115. public:
  116. error_category() noexcept;
  117. virtual ~error_category();
  118. error_category(const error_category&) = delete;
  119. error_category& operator=(const error_category&) = delete;
  120. virtual const char*
  121. name() const noexcept = 0;
  122. virtual string
  123. message(int) const = 0;
  124. virtual error_condition
  125. default_error_condition(int __i) const noexcept;
  126. virtual bool
  127. equivalent(int __i, const error_condition& __cond) const noexcept;
  128. virtual bool
  129. equivalent(const error_code& __code, int __i) const noexcept;
  130. bool
  131. operator<(const error_category& __other) const noexcept
  132. { return less<const error_category*>()(this, &__other); }
  133. bool
  134. operator==(const error_category& __other) const noexcept
  135. { return this == &__other; }
  136. bool
  137. operator!=(const error_category& __other) const noexcept
  138. { return this != &__other; }
  139. };
  140. _GLIBCXX_END_NAMESPACE_VERSION
  141. // gcc-4.9.0
  142. // LWG 2145 changes this constructor to constexpr i.e. inline
  143. error_category::error_category() noexcept = default;
  144. error_category::~error_category() noexcept = default;
  145. namespace
  146. {
  147. using std::string;
  148. struct generic_error_category : public std::error_category
  149. {
  150. virtual const char*
  151. name() const noexcept
  152. { return "generic"; }
  153. virtual string
  154. message(int i) const
  155. {
  156. // XXX locale issues: how does one get or set loc.
  157. // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc)
  158. return string(strerror(i));
  159. }
  160. };
  161. struct system_error_category : public std::error_category
  162. {
  163. virtual const char*
  164. name() const noexcept
  165. { return "system"; }
  166. virtual string
  167. message(int i) const
  168. {
  169. // XXX locale issues: how does one get or set loc.
  170. // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc)
  171. return string(strerror(i));
  172. }
  173. };
  174. const generic_error_category generic_category_instance{};
  175. const system_error_category system_category_instance{};
  176. }
  177. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  178. const error_category&
  179. system_category() noexcept { return system_category_instance; }
  180. const error_category&
  181. generic_category() noexcept { return generic_category_instance; }
  182. namespace _V2
  183. {
  184. _GLIBCXX_CONST const error_categoryxx& system_category() noexcept;
  185. _GLIBCXX_CONST const error_categoryxx& generic_category() noexcept;
  186. }
  187. _GLIBCXX_END_NAMESPACE_VERSION
  188. error_condition
  189. error_category::default_error_condition(int __i) const noexcept
  190. {
  191. if (*this == system_category())
  192. return error_condition(__i, _V2::system_category());
  193. return error_condition(__i, _V2::generic_category());
  194. }
  195. bool
  196. error_category::equivalent(int __i,
  197. const error_condition& __cond) const noexcept
  198. { return default_error_condition(__i) == __cond; }
  199. bool
  200. error_category::equivalent(const error_code& __code, int __i) const noexcept
  201. {
  202. if (*this == system_category()
  203. && __code.category() == _V2::system_category())
  204. return __code.value() == __i;
  205. if (*this == generic_category()
  206. && __code.category() == _V2::generic_category())
  207. return __code.value() == __i;
  208. return false;
  209. }
  210. }
  211. #endif