doc_extended_allocators.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2013-2013. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #include <boost/container/detail/config_begin.hpp>
  11. #include <boost/container/detail/workaround.hpp>
  12. //[doc_extended_allocators
  13. #include <boost/container/vector.hpp>
  14. #include <boost/container/flat_set.hpp>
  15. #include <boost/container/list.hpp>
  16. #include <boost/container/set.hpp>
  17. //"allocator" is a general purpose allocator that can reallocate
  18. //memory, something useful for vector and flat associative containers
  19. #include <boost/container/allocator.hpp>
  20. //"adaptive_pool" is a node allocator, specially suited for
  21. //node-based containers
  22. #include <boost/container/adaptive_pool.hpp>
  23. int main ()
  24. {
  25. using namespace boost::container;
  26. //A vector that can reallocate memory to implement faster insertions
  27. vector<int, allocator<int> > extended_alloc_vector;
  28. //A flat set that can reallocate memory to implement faster insertions
  29. flat_set<int, std::less<int>, allocator<int> > extended_alloc_flat_set;
  30. //A list that can manages nodes to implement faster
  31. //range insertions and deletions
  32. list<int, adaptive_pool<int> > extended_alloc_list;
  33. //A set that can recycle nodes to implement faster
  34. //range insertions and deletions
  35. set<int, std::less<int>, adaptive_pool<int> > extended_alloc_set;
  36. //Now user them as always
  37. extended_alloc_vector.push_back(0);
  38. extended_alloc_flat_set.insert(0);
  39. extended_alloc_list.push_back(0);
  40. extended_alloc_set.insert(0);
  41. //...
  42. return 0;
  43. }
  44. //]
  45. #include <boost/container/detail/config_end.hpp>