ptr_map.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // Boost.Pointer Container
  3. //
  4. // Copyright Thorsten Ottosen 2003-2005. Use, modification and
  5. // distribution is subject to the Boost Software License, Version
  6. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // For more information, see http://www.boost.org/libs/ptr_container/
  10. //
  11. #ifndef BOOST_PTR_CONTAINER_PTR_MAP_HPP
  12. #define BOOST_PTR_CONTAINER_PTR_MAP_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif
  16. #include <map>
  17. #include <boost/ptr_container/ptr_map_adapter.hpp>
  18. #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
  19. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  20. #pragma GCC diagnostic push
  21. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  22. #endif
  23. namespace boost
  24. {
  25. template
  26. <
  27. class Key,
  28. class T,
  29. class Compare = std::less<Key>,
  30. class CloneAllocator = heap_clone_allocator,
  31. class Allocator = std::allocator< std::pair<const Key,typename ptr_container_detail::void_ptr<T>::type> >
  32. >
  33. class ptr_map :
  34. public ptr_map_adapter<T,std::map<Key,
  35. typename ptr_container_detail::void_ptr<T>::type,
  36. Compare,Allocator>,CloneAllocator>
  37. {
  38. typedef ptr_map_adapter<T,std::map<Key,
  39. typename ptr_container_detail::void_ptr<T>::type,
  40. Compare,Allocator>,CloneAllocator>
  41. base_type;
  42. typedef ptr_map<Key,T,Compare,CloneAllocator,Allocator> this_type;
  43. public:
  44. ptr_map()
  45. { }
  46. explicit ptr_map( const Compare& comp,
  47. const Allocator& a = Allocator() )
  48. : base_type( comp, a ) { }
  49. template< class InputIterator >
  50. ptr_map( InputIterator first, InputIterator last )
  51. : base_type( first, last )
  52. { }
  53. template< class InputIterator >
  54. ptr_map( InputIterator first, InputIterator last,
  55. const Compare& comp,
  56. const Allocator& a = Allocator() )
  57. : base_type( first, last, comp, a )
  58. { }
  59. BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_map, base_type,
  60. this_type )
  61. template< class U >
  62. ptr_map( const ptr_map<Key,U>& r ) : base_type( r )
  63. { }
  64. ptr_map& operator=( ptr_map r )
  65. {
  66. this->swap( r );
  67. return *this;
  68. }
  69. };
  70. template
  71. <
  72. class Key,
  73. class T,
  74. class Compare = std::less<Key>,
  75. class CloneAllocator = heap_clone_allocator,
  76. class Allocator = std::allocator< std::pair<const Key,void*> >
  77. >
  78. class ptr_multimap :
  79. public ptr_multimap_adapter<T,std::multimap<Key,void*,
  80. Compare,Allocator>,CloneAllocator>
  81. {
  82. typedef ptr_multimap_adapter<T,std::multimap<Key,void*,
  83. Compare,Allocator>,CloneAllocator>
  84. base_type;
  85. typedef ptr_multimap<Key,T,Compare,CloneAllocator,Allocator> this_type;
  86. public:
  87. ptr_multimap()
  88. { }
  89. explicit ptr_multimap( const Compare& comp,
  90. const Allocator& a = Allocator() )
  91. : base_type( comp, a ) { }
  92. template< class InputIterator >
  93. ptr_multimap( InputIterator first, InputIterator last )
  94. : base_type( first, last )
  95. { }
  96. template< class InputIterator >
  97. ptr_multimap( InputIterator first, InputIterator last,
  98. const Compare& comp,
  99. const Allocator& a = Allocator() )
  100. : base_type( first, last, comp, a )
  101. { }
  102. BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_multimap,
  103. base_type,
  104. this_type )
  105. template< class U >
  106. ptr_multimap( const ptr_multimap<Key,U>& r ) : base_type( r )
  107. { }
  108. ptr_multimap& operator=( ptr_multimap r )
  109. {
  110. this->swap( r );
  111. return *this;
  112. }
  113. };
  114. //////////////////////////////////////////////////////////////////////////////
  115. // clonability
  116. template< class K, class T, class C, class CA, class A >
  117. inline ptr_map<K,T,C,CA,A>* new_clone( const ptr_map<K,T,C,CA,A>& r )
  118. {
  119. return r.clone().release();
  120. }
  121. template< class K, class T, class C, class CA, class A >
  122. inline ptr_multimap<K,T,C,CA,A>* new_clone( const ptr_multimap<K,T,C,CA,A>& r )
  123. {
  124. return r.clone().release();
  125. }
  126. /////////////////////////////////////////////////////////////////////////
  127. // swap
  128. template< typename K, typename T, typename C, typename CA, typename A >
  129. inline void swap( ptr_map<K,T,C,CA,A>& l, ptr_map<K,T,C,CA,A>& r )
  130. {
  131. l.swap(r);
  132. }
  133. template< typename K, typename T, typename C, typename CA, typename A >
  134. inline void swap( ptr_multimap<K,T,C,CA,A>& l, ptr_multimap<K,T,C,CA,A>& r )
  135. {
  136. l.swap(r);
  137. }
  138. }
  139. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  140. #pragma GCC diagnostic pop
  141. #endif
  142. #endif