No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

172 líneas
6.0KB

  1. // Allocator traits -*- C++ -*-
  2. // Copyright (C) 2011-2020 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. /** @file ext/alloc_traits.h
  21. * This file is a GNU extension to the Standard C++ Library.
  22. */
  23. #ifndef _EXT_ALLOC_TRAITS_H
  24. #define _EXT_ALLOC_TRAITS_H 1
  25. #pragma GCC system_header
  26. # include <bits/alloc_traits.h>
  27. #if __cplusplus < 201103L
  28. # include <bits/allocator.h> // for __alloc_swap
  29. #endif
  30. namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
  31. {
  32. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  33. /**
  34. * @brief Uniform interface to C++98 and C++11 allocators.
  35. * @ingroup allocators
  36. */
  37. template<typename _Alloc, typename = typename _Alloc::value_type>
  38. struct __alloc_traits
  39. #if __cplusplus >= 201103L
  40. : std::allocator_traits<_Alloc>
  41. #endif
  42. {
  43. typedef _Alloc allocator_type;
  44. #if __cplusplus >= 201103L
  45. typedef std::allocator_traits<_Alloc> _Base_type;
  46. typedef typename _Base_type::value_type value_type;
  47. typedef typename _Base_type::pointer pointer;
  48. typedef typename _Base_type::const_pointer const_pointer;
  49. typedef typename _Base_type::size_type size_type;
  50. typedef typename _Base_type::difference_type difference_type;
  51. // C++11 allocators do not define reference or const_reference
  52. typedef value_type& reference;
  53. typedef const value_type& const_reference;
  54. using _Base_type::allocate;
  55. using _Base_type::deallocate;
  56. using _Base_type::construct;
  57. using _Base_type::destroy;
  58. using _Base_type::max_size;
  59. private:
  60. template<typename _Ptr>
  61. using __is_custom_pointer
  62. = std::__and_<std::is_same<pointer, _Ptr>,
  63. std::__not_<std::is_pointer<_Ptr>>>;
  64. public:
  65. // overload construct for non-standard pointer types
  66. template<typename _Ptr, typename... _Args>
  67. static _GLIBCXX14_CONSTEXPR
  68. std::__enable_if_t<__is_custom_pointer<_Ptr>::value>
  69. construct(_Alloc& __a, _Ptr __p, _Args&&... __args)
  70. noexcept(noexcept(_Base_type::construct(__a, std::__to_address(__p),
  71. std::forward<_Args>(__args)...)))
  72. {
  73. _Base_type::construct(__a, std::__to_address(__p),
  74. std::forward<_Args>(__args)...);
  75. }
  76. // overload destroy for non-standard pointer types
  77. template<typename _Ptr>
  78. static _GLIBCXX14_CONSTEXPR
  79. std::__enable_if_t<__is_custom_pointer<_Ptr>::value>
  80. destroy(_Alloc& __a, _Ptr __p)
  81. noexcept(noexcept(_Base_type::destroy(__a, std::__to_address(__p))))
  82. { _Base_type::destroy(__a, std::__to_address(__p)); }
  83. static constexpr _Alloc _S_select_on_copy(const _Alloc& __a)
  84. { return _Base_type::select_on_container_copy_construction(__a); }
  85. static _GLIBCXX14_CONSTEXPR void _S_on_swap(_Alloc& __a, _Alloc& __b)
  86. { std::__alloc_on_swap(__a, __b); }
  87. static constexpr bool _S_propagate_on_copy_assign()
  88. { return _Base_type::propagate_on_container_copy_assignment::value; }
  89. static constexpr bool _S_propagate_on_move_assign()
  90. { return _Base_type::propagate_on_container_move_assignment::value; }
  91. static constexpr bool _S_propagate_on_swap()
  92. { return _Base_type::propagate_on_container_swap::value; }
  93. static constexpr bool _S_always_equal()
  94. { return _Base_type::is_always_equal::value; }
  95. static constexpr bool _S_nothrow_move()
  96. { return _S_propagate_on_move_assign() || _S_always_equal(); }
  97. template<typename _Tp>
  98. struct rebind
  99. { typedef typename _Base_type::template rebind_alloc<_Tp> other; };
  100. #else // ! C++11
  101. typedef typename _Alloc::pointer pointer;
  102. typedef typename _Alloc::const_pointer const_pointer;
  103. typedef typename _Alloc::value_type value_type;
  104. typedef typename _Alloc::reference reference;
  105. typedef typename _Alloc::const_reference const_reference;
  106. typedef typename _Alloc::size_type size_type;
  107. typedef typename _Alloc::difference_type difference_type;
  108. _GLIBCXX_NODISCARD static pointer
  109. allocate(_Alloc& __a, size_type __n)
  110. { return __a.allocate(__n); }
  111. template<typename _Hint>
  112. _GLIBCXX_NODISCARD static pointer
  113. allocate(_Alloc& __a, size_type __n, _Hint __hint)
  114. { return __a.allocate(__n, __hint); }
  115. static void deallocate(_Alloc& __a, pointer __p, size_type __n)
  116. { __a.deallocate(__p, __n); }
  117. template<typename _Tp>
  118. static void construct(_Alloc& __a, pointer __p, const _Tp& __arg)
  119. { __a.construct(__p, __arg); }
  120. static void destroy(_Alloc& __a, pointer __p)
  121. { __a.destroy(__p); }
  122. static size_type max_size(const _Alloc& __a)
  123. { return __a.max_size(); }
  124. static const _Alloc& _S_select_on_copy(const _Alloc& __a) { return __a; }
  125. static void _S_on_swap(_Alloc& __a, _Alloc& __b)
  126. {
  127. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  128. // 431. Swapping containers with unequal allocators.
  129. std::__alloc_swap<_Alloc>::_S_do_it(__a, __b);
  130. }
  131. template<typename _Tp>
  132. struct rebind
  133. { typedef typename _Alloc::template rebind<_Tp>::other other; };
  134. #endif // C++11
  135. };
  136. _GLIBCXX_END_NAMESPACE_VERSION
  137. } // namespace __gnu_cxx
  138. #endif