ptr_set.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 <set>
  19. namespace boost
  20. {
  21. template
  22. <
  23. class Key,
  24. class Compare = std::less<Key>,
  25. class CloneAllocator = heap_clone_allocator,
  26. class Allocator = std::allocator<void*>
  27. >
  28. class ptr_set :
  29. public ptr_set_adapter< Key,
  30. std::set<void*,void_ptr_indirect_fun<Compare,Key>,Allocator>,
  31. CloneAllocator, true >
  32. {
  33. typedef ptr_set_adapter< Key, std::set<void*,void_ptr_indirect_fun<Compare,Key>,Allocator>,
  34. CloneAllocator, true >
  35. base_type;
  36. typedef ptr_set<Key,Compare,CloneAllocator,Allocator> this_type;
  37. public:
  38. ptr_set()
  39. { }
  40. explicit ptr_set( const Compare& comp,
  41. const Allocator& a = Allocator() )
  42. : base_type( comp, a )
  43. { }
  44. template< typename InputIterator >
  45. ptr_set( InputIterator first, InputIterator last )
  46. : base_type( first, last )
  47. { }
  48. template< typename InputIterator >
  49. ptr_set( InputIterator first, InputIterator last,
  50. const Compare& comp,
  51. const Allocator& a = Allocator() )
  52. : base_type( first, last, comp, a )
  53. { }
  54. BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_set,
  55. base_type,
  56. this_type )
  57. BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( ptr_set, base_type )
  58. };
  59. template
  60. <
  61. class Key,
  62. class Compare = std::less<Key>,
  63. class CloneAllocator = heap_clone_allocator,
  64. class Allocator = std::allocator<void*>
  65. >
  66. class ptr_multiset :
  67. public ptr_multiset_adapter< Key,
  68. std::multiset<void*,void_ptr_indirect_fun<Compare,Key>,Allocator>,
  69. CloneAllocator, true >
  70. {
  71. typedef ptr_multiset_adapter< Key,
  72. std::multiset<void*,void_ptr_indirect_fun<Compare,Key>,Allocator>,
  73. CloneAllocator, true >
  74. base_type;
  75. typedef ptr_multiset<Key,Compare,CloneAllocator,Allocator> this_type;
  76. public:
  77. ptr_multiset()
  78. { }
  79. explicit ptr_multiset( const Compare& comp,
  80. const Allocator& a = Allocator() )
  81. : base_type( comp, a )
  82. { }
  83. template< typename InputIterator >
  84. ptr_multiset( InputIterator first, InputIterator last )
  85. : base_type( first, last )
  86. { }
  87. template< typename InputIterator >
  88. ptr_multiset( InputIterator first, InputIterator last,
  89. const Compare& comp,
  90. const Allocator& a = Allocator() )
  91. : base_type( first, last, comp, a )
  92. { }
  93. BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_multiset,
  94. base_type,
  95. this_type )
  96. BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( ptr_multiset,
  97. base_type )
  98. };
  99. /////////////////////////////////////////////////////////////////////////
  100. // clonability
  101. template< typename K, typename C, typename CA, typename A >
  102. inline ptr_set<K,C,CA,A>* new_clone( const ptr_set<K,C,CA,A>& r )
  103. {
  104. return r.clone().release();
  105. }
  106. template< typename K, typename C, typename CA, typename A >
  107. inline ptr_multiset<K,C,CA,A>* new_clone( const ptr_multiset<K,C,CA,A>& r )
  108. {
  109. return r.clone().release();
  110. }
  111. /////////////////////////////////////////////////////////////////////////
  112. // swap
  113. template< typename K, typename C, typename CA, typename A >
  114. inline void swap( ptr_set<K,C,CA,A>& l, ptr_set<K,C,CA,A>& r )
  115. {
  116. l.swap(r);
  117. }
  118. template< typename K, typename C, typename CA, typename A >
  119. inline void swap( ptr_multiset<K,C,CA,A>& l, ptr_multiset<K,C,CA,A>& r )
  120. {
  121. l.swap(r);
  122. }
  123. }
  124. #endif