ptr_inserter.rst 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ++++++++++++++++++++++++++++++++++
  2. |Boost| Pointer Container Library
  3. ++++++++++++++++++++++++++++++++++
  4. .. |Boost| image:: boost.png
  5. Insert Iterators
  6. ----------------
  7. When you work with normal value-based containers and algorithms, you often
  8. use insert iterators ::
  9. std::list<int> coll1;
  10. // ...
  11. std::vector<int> coll2;
  12. std::copy( coll1.begin(), coll1.end(),
  13. back_inserter(coll2) );
  14. With the special insert iterators for pointer containers,
  15. you can do exactly the same ::
  16. boost::ptr_list<Base> coll1;
  17. // ...
  18. boost::ptr_vector<Base> coll2;
  19. std::copy( coll1.begin(), coll1.end(),
  20. boost::ptr_container::ptr_back_inserter(coll2) );
  21. Each element is cloned and inserted into the container. Furthermore,
  22. if the source range iterates over pointers
  23. instead of references, ``NULL`` pointers
  24. can be transfered as well.
  25. **Navigate**
  26. - `home <ptr_container.html>`_
  27. - `reference <reference.html>`_
  28. **Synopsis:**
  29. ::
  30. namespace boost
  31. {
  32. namespace ptr_container
  33. {
  34. template< class PtrContainer >
  35. class ptr_back_insert_iterator;
  36. template< class PtrContainer >
  37. class ptr_front_insert_iterator;
  38. template< class PtrContainer >
  39. class ptr_insert_iterator;
  40. template< class PtrContainer >
  41. ptr_back_insert_iterator<PtrContainer>
  42. ptr_back_inserter( PtrContainer& cont );
  43. template< class PtrContainer >
  44. ptr_front_insert_iterator<PtrContainer>
  45. ptr_front_inserter( PtrContainer& cont );
  46. template< class PtrContainer >
  47. ptr_insert_iterator<PtrContainer>
  48. ptr_inserter( PtrContainer& cont, typename PtrContainer::iterator before );
  49. } // namespace 'ptr_container'
  50. } // namespace 'boost'
  51. .. raw:: html
  52. <hr>
  53. :Copyright: Thorsten Ottosen 2008. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt__).
  54. __ http://www.boost.org/LICENSE_1_0.txt