Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <memory>
- #include "Test.hpp"
- namespace smart_pointer {
- // обьявление класса "исключение"
- class exception : std::exception {
- using base_class = std::exception;
- using base_class::base_class;
- };
- // обьявление класса "умный указатель"
- template<
- typename T,
- typename Allocator
- >
- class SmartPointer {
- // эта строчка нужно, ее не удалять
- ENABLE_CLASS_TESTS;
- public:
- using value_type = T;
- SmartPointer(value_type * = nullptr);
- // конструктор копирования
- SmartPointer(const SmartPointer &);
- // конструктор перемещения? (move)
- SmartPointer(SmartPointer &&);
- // присвоение
- SmartPointer &operator=(const SmartPointer &);
- // присвоение с rval
- SmartPointer &operator=(SmartPointer &&);
- //
- SmartPointer &operator=(value_type *);
- ~SmartPointer();
- // возвращаем ссылку на объект класса / типа T
- // если SmartPointer указывает на (или содержит) nullptr, кидаем throw `SmartPointer::exception`
- value_type &operator*();
- const value_type &operator*() const;
- // возвращает указатель на объект класса / типа T
- value_type *operator->() const;
- value_type *get() const;
- // если указатель == nullptr => return false
- operator bool() const;
- // если указатели оба указывают на один и тот же адрес или оба на nullptr => return true
- template<typename U, typename AnotherAllocator>
- bool operator==(const SmartPointer<U, AnotherAllocator> &) const;
- // если указатели оба указывают на один и тот же адрес или оба на nullptr => return false
- template<typename U, typename AnotherAllocator>
- bool operator!=(const SmartPointer<U, AnotherAllocator> &) const;
- // если умный указатель содержит (или указывает) НЕ nullptr => return количество владельцев (count owners)
- // если умный указатель содержит (или указывает) nullptr => return 0
- std::size_t count_owners() const;
- private:
- class Core;
- Core *core;
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement