ptr_set.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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_SET_HPP
  12. #define BOOST_PTR_CONTAINER_PTR_SET_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif
  16. #include <boost/ptr_container/indirect_fun.hpp>
  17. #include <boost/ptr_container/ptr_set_adapter.hpp>
  18. #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
  19. #include <set>
  20. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  21. #pragma GCC diagnostic push
  22. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  23. #endif
  24. namespace boost
  25. {
  26. template
  27. <
  28. class Key,
  29. class Compare = std::less<Key>,
  30. class CloneAllocator = heap_clone_allocator,
  31. class Allocator = std::allocator<typename ptr_container_detail::void_ptr<Key>::type>
  32. >
  33. class ptr_set :
  34. public ptr_set_adapter< Key, std::set<
  35. typename ptr_container_detail::void_ptr<Key>::type,
  36. void_ptr_indirect_fun<Compare,Key>,Allocator>,
  37. CloneAllocator, true >
  38. {
  39. typedef ptr_set_adapter< Key, std::set<
  40. typename ptr_container_detail::void_ptr<Key>::type,
  41. void_ptr_indirect_fun<Compare,Key>,Allocator>,
  42. CloneAllocator, true >
  43. base_type;
  44. typedef ptr_set<Key,Compare,CloneAllocator,Allocator> this_type;
  45. public:
  46. ptr_set()
  47. { }
  48. explicit ptr_set( const Compare& comp,
  49. const Allocator& a = Allocator() )
  50. : base_type( comp, a )
  51. { }
  52. template< typename InputIterator >
  53. ptr_set( InputIterator first, InputIterator last )
  54. : base_type( first, last )
  55. { }
  56. template< typename InputIterator >
  57. ptr_set( InputIterator first, InputIterator last,
  58. const Compare& comp,
  59. const Allocator& a = Allocator() )
  60. : base_type( first, last, comp, a )
  61. { }
  62. BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_set,
  63. base_type,
  64. this_type )
  65. BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( ptr_set, base_type )
  66. };
  67. template
  68. <
  69. class Key,
  70. class Compare = std::less<Key>,
  71. class CloneAllocator = heap_clone_allocator,
  72. class Allocator = std::allocator<void*>
  73. >
  74. class ptr_multiset :
  75. public ptr_multiset_adapter< Key,
  76. std::multiset<void*,void_ptr_indirect_fun<Compare,Key>,Allocator>,
  77. CloneAllocator, true >
  78. {
  79. typedef ptr_multiset_adapter< Key,
  80. std::multiset<void*,void_ptr_indirect_fun<Compare,Key>,Allocator>,
  81. CloneAllocator, true >
  82. base_type;
  83. typedef ptr_multiset<Key,Compare,CloneAllocator,Allocator> this_type;
  84. public:
  85. ptr_multiset()
  86. { }
  87. explicit ptr_multiset( const Compare& comp,
  88. const Allocator& a = Allocator() )
  89. : base_type( comp, a )
  90. { }
  91. template< typename InputIterator >
  92. ptr_multiset( InputIterator first, InputIterator last )
  93. : base_type( first, last )
  94. { }
  95. template< typename InputIterator >
  96. ptr_multiset( InputIterator first, InputIterator last,
  97. const Compare& comp,
  98. const Allocator& a = Allocator() )
  99. : base_type( first, last, comp, a )
  100. { }
  101. BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_multiset,
  102. base_type,
  103. this_type )
  104. BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( ptr_multiset,
  105. base_type )
  106. };
  107. /////////////////////////////////////////////////////////////////////////
  108. // clonability
  109. template< typename K, typename C, typename CA, typename A >
  110. inline ptr_set<K,C,CA,A>* new_clone( const ptr_set<K,C,CA,A>& r )
  111. {
  112. return r.clone().release();
  113. }
  114. template< typename K, typename C, typename CA, typename A >
  115. inline ptr_multiset<K,C,CA,A>* new_clone( const ptr_multiset<K,C,CA,A>& r )
  116. {
  117. return r.clone().release();
  118. }
  119. /////////////////////////////////////////////////////////////////////////
  120. // swap
  121. template< typename K, typename C, typename CA, typename A >
  122. inline void swap( ptr_set<K,C,CA,A>& l, ptr_set<K,C,CA,A>& r )
  123. {
  124. l.swap(r);
  125. }
  126. template< typename K, typename C, typename CA, typename A >
  127. inline void swap( ptr_multiset<K,C,CA,A>& l, ptr_multiset<K,C,CA,A>& r )
  128. {
  129. l.swap(r);
  130. }
  131. }
  132. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  133. #pragma GCC diagnostic pop
  134. #endif
  135. #endif