small_allocator.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Used in Boost.MultiIndex tests.
  2. *
  3. * Copyright 2003-2018 Joaquin M Lopez Munoz.
  4. * Distributed under the Boost Software License, Version 1.0.
  5. * (See accompanying file LICENSE_1_0.txt or copy at
  6. * http://www.boost.org/LICENSE_1_0.txt)
  7. *
  8. * See http://www.boost.org/libs/multi_index for library home page.
  9. */
  10. #ifndef BOOST_MULTI_INDEX_TEST_SMALL_ALLOCATOR_HPP
  11. #define BOOST_MULTI_INDEX_TEST_SMALL_ALLOCATOR_HPP
  12. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  13. template<typename T>
  14. class small_allocator
  15. {
  16. public:
  17. typedef unsigned char size_type;
  18. typedef signed char difference_type;
  19. typedef T* pointer;
  20. typedef const T* const_pointer;
  21. typedef void* void_pointer;
  22. typedef const void* const_void_pointer;
  23. typedef T& reference;
  24. typedef const T& const_reference;
  25. typedef T value_type;
  26. template<class U>struct rebind{typedef small_allocator<U> other;};
  27. small_allocator(){}
  28. small_allocator(const small_allocator<T>&){}
  29. template<class U>small_allocator(const small_allocator<U>&,int=0){}
  30. pointer allocate(size_type n)
  31. {
  32. return pointer((T*)(new char[n*sizeof(T)]));
  33. }
  34. void deallocate(pointer p,size_type)
  35. {
  36. delete[](char *)&*p;
  37. }
  38. size_type max_size()const{return (size_type)(-1);}
  39. friend bool operator==(const small_allocator&,const small_allocator&)
  40. {
  41. return true;
  42. }
  43. friend bool operator!=(const small_allocator&,const small_allocator&)
  44. {
  45. return false;
  46. }
  47. };
  48. #endif