tut34.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #include <boost/ptr_container/ptr_sequence_adapter.hpp>
  12. #include <vector>
  13. #include <boost/ptr_container/ptr_map_adapter.hpp>
  14. #include <map>
  15. template< class T >
  16. struct my_ptr_vector :
  17. public boost::ptr_sequence_adapter< std::vector<T*> >
  18. {
  19. };
  20. template< class Key, class T, class Pred = std::less<Key>,
  21. class Allocator = std::allocator< std::pair<const Key, T> > >
  22. struct my_map : public std::map<Key,T,Pred,Allocator>
  23. {
  24. explicit my_map( const Pred& pred = Pred(),
  25. const Allocator& alloc = Allocator() )
  26. { }
  27. };
  28. #include <string>
  29. struct Foo {};
  30. typedef boost::ptr_map_adapter< my_map<std::string,Foo*> > foo_map;
  31. template< class Key, class T, class Pred = std::less<Key> >
  32. struct my_ptr_map : public boost::ptr_map_adapter< std::map<Key,T*,Pred> >
  33. {
  34. };
  35. typedef my_ptr_map<std::string,Foo> foo_map2;
  36. int main()
  37. {
  38. my_ptr_vector<Foo> vec;
  39. vec.push_back( new Foo );
  40. foo_map m1;
  41. foo_map2 m2;
  42. std::string s("");
  43. m1.insert( s, new Foo );
  44. m2.insert( s, new Foo );
  45. }