Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <type_traits>
- #include <memory>
- #include <vector>
- #include <string>
- #define log(x) std::cout << x << std::endl;
- namespace alx
- {
- template <class T>
- class unique_ptr;
- }
- template <class T>
- class alx::unique_ptr
- {
- T* ptr;
- //bool isarray;
- public:
- unique_ptr(T* inp = nullptr);
- ~unique_ptr();
- T& operator*();
- operator T*() const;
- };
- template <class T>
- alx::unique_ptr<T>::unique_ptr(T* inp)
- : ptr(inp)
- {
- }
- template <class T> //array-ra nemjó
- alx::unique_ptr<T>::~unique_ptr()
- {
- delete ptr;
- std::endl(std::cout);
- std::cout << "uniqueptr is being deleted"<<std::endl;
- }
- template<class T>
- T& alx::unique_ptr<T>::operator*()
- {
- return *ptr;
- }
- template<class T>
- alx::unique_ptr<T>::operator T*() const
- {
- return ptr;
- }
- /*
- template<class T, std::size_t N>
- alx::unique_ptr<(T&)[N]>unique_ptr(T* inp)
- : ptr(inp)
- {
- }*/
- int main()
- {
- {
- alx::unique_ptr<std::string> stringptr(new std::string("asd"));
- std::cout << (*stringptr);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement