ptr_list.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_LIST_HPP
  12. #define BOOST_PTR_CONTAINER_PTR_LIST_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif
  16. #include <boost/ptr_container/ptr_sequence_adapter.hpp>
  17. #include <list>
  18. namespace boost
  19. {
  20. template
  21. <
  22. class T,
  23. class CloneAllocator = heap_clone_allocator,
  24. class Allocator = std::allocator<void*>
  25. >
  26. class ptr_list : public
  27. ptr_sequence_adapter< T,
  28. std::list<void*,Allocator>,
  29. CloneAllocator >
  30. {
  31. typedef ptr_sequence_adapter< T,
  32. std::list<void*,Allocator>,
  33. CloneAllocator >
  34. base_class;
  35. typedef ptr_list<T,CloneAllocator,Allocator> this_type;
  36. public:
  37. BOOST_PTR_CONTAINER_DEFINE_SEQEUENCE_MEMBERS( ptr_list,
  38. base_class,
  39. this_type )
  40. typedef BOOST_DEDUCED_TYPENAME base_class::value_type value_type;
  41. public:
  42. using base_class::merge;
  43. void merge( ptr_list& x )
  44. {
  45. merge( x, std::less<T>() );
  46. }
  47. template< typename Compare >
  48. void merge( ptr_list& x, Compare comp )
  49. {
  50. this->base().merge( x.base(), void_ptr_indirect_fun<Compare,T>( comp ) ); }
  51. void sort()
  52. {
  53. sort( std::less<T>() );
  54. };
  55. template< typename Compare >
  56. void sort( Compare comp )
  57. {
  58. this->base().sort( void_ptr_indirect_fun<Compare,T>( comp ) );
  59. }
  60. template< class Pred >
  61. void erase_if( iterator first, iterator last, Pred pred )
  62. {
  63. base_class::erase_if( first, last, pred );
  64. }
  65. template< class Pred >
  66. void erase_if( Pred pred )
  67. {
  68. this->base().remove_if( BOOST_DEDUCED_TYPENAME base_class::
  69. BOOST_NESTED_TEMPLATE void_ptr_delete_if<Pred,value_type>
  70. (pred) );
  71. }
  72. }; // class 'ptr_list'
  73. //////////////////////////////////////////////////////////////////////////////
  74. // clonability
  75. template< typename T, typename CA, typename A >
  76. inline ptr_list<T,CA,A>* new_clone( const ptr_list<T,CA,A>& r )
  77. {
  78. return r.clone().release();
  79. }
  80. /////////////////////////////////////////////////////////////////////////
  81. // swap
  82. template< typename T, typename CA, typename A >
  83. inline void swap( ptr_list<T,CA,A>& l, ptr_list<T,CA,A>& r )
  84. {
  85. l.swap(r);
  86. }
  87. }
  88. #endif