ptr_list.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
  18. #include <list>
  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 T,
  28. class CloneAllocator = heap_clone_allocator,
  29. class Allocator = std::allocator<typename ptr_container_detail::void_ptr<T>::type>
  30. >
  31. class ptr_list : public
  32. ptr_sequence_adapter< T, std::list<
  33. typename ptr_container_detail::void_ptr<T>::type,Allocator>,
  34. CloneAllocator >
  35. {
  36. typedef ptr_sequence_adapter< T, std::list<
  37. typename ptr_container_detail::void_ptr<T>::type,Allocator>,
  38. CloneAllocator >
  39. base_class;
  40. typedef ptr_list<T,CloneAllocator,Allocator> this_type;
  41. typedef BOOST_DEDUCED_TYPENAME boost::remove_nullable<T>::type U;
  42. public:
  43. BOOST_PTR_CONTAINER_DEFINE_SEQEUENCE_MEMBERS( ptr_list,
  44. base_class,
  45. this_type )
  46. typedef BOOST_DEDUCED_TYPENAME base_class::value_type value_type;
  47. public:
  48. using base_class::merge;
  49. void merge( ptr_list& x )
  50. {
  51. merge( x, std::less<U>() );
  52. }
  53. template< typename Compare >
  54. void merge( ptr_list& x, Compare comp )
  55. {
  56. this->base().merge( x.base(), void_ptr_indirect_fun<Compare,U>( comp ) ); }
  57. void sort()
  58. {
  59. sort( std::less<U>() );
  60. };
  61. template< typename Compare >
  62. void sort( Compare comp )
  63. {
  64. this->base().sort( void_ptr_indirect_fun<Compare,U>( comp ) );
  65. }
  66. template< class Pred >
  67. void erase_if( iterator first, iterator last, Pred pred )
  68. {
  69. base_class::erase_if( first, last, pred );
  70. }
  71. template< class Pred >
  72. void erase_if( Pred pred )
  73. {
  74. this->base().remove_if( BOOST_DEDUCED_TYPENAME base_class::
  75. BOOST_NESTED_TEMPLATE void_ptr_delete_if<Pred,value_type>
  76. (pred) );
  77. }
  78. }; // class 'ptr_list'
  79. //////////////////////////////////////////////////////////////////////////////
  80. // clonability
  81. template< typename T, typename CA, typename A >
  82. inline ptr_list<T,CA,A>* new_clone( const ptr_list<T,CA,A>& r )
  83. {
  84. return r.clone().release();
  85. }
  86. /////////////////////////////////////////////////////////////////////////
  87. // swap
  88. template< typename T, typename CA, typename A >
  89. inline void swap( ptr_list<T,CA,A>& l, ptr_list<T,CA,A>& r )
  90. {
  91. l.swap(r);
  92. }
  93. }
  94. #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
  95. #pragma GCC diagnostic pop
  96. #endif
  97. #endif