Advertisement
sve_vash

Untitled

Nov 17th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. //класс, выделяющий и управляющий памятью
  2. class allocator {
  3. public:
  4. using size_type = std::size_t;
  5. using difference_type = std::ptrdiff_t;
  6. using pointer = T*;
  7. using const_pointer = const T*;
  8. using reference = typename std::add_lvalue_reference<T>::type;
  9. using const_reference = typename std::add_lvalue_reference<const T>::type;
  10. using value_type = T;
  11.  
  12. allocator() noexcept = default;
  13.  
  14. allocator(const allocator&) noexcept = default;
  15.  
  16. template <class U>
  17. allocator(const allocator<U>&) noexcept {};
  18.  
  19. ~allocator() = default;
  20.  
  21. pointer allocate(size_type size) {
  22. auto p = ::operator new(size * sizeof(value_type));
  23. return static_cast<pointer>(p);
  24. }
  25.  
  26. void deallocate(pointer p, size_type n) noexcept {
  27. ::operator delete (p, n);
  28. }
  29. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement