Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <type_traits>
  3. #include <memory>
  4. #include <vector>
  5. #include <string>
  6. #define log(x) std::cout << x << std::endl;
  7.  
  8. namespace alx
  9. {
  10.     template <class T>
  11.     class unique_ptr;
  12. }
  13.  
  14.  
  15. template <class T>
  16. class alx::unique_ptr
  17. {
  18.     T* ptr;
  19.     //bool isarray;
  20. public:
  21.     unique_ptr(T* inp = nullptr);
  22.     ~unique_ptr();
  23.     T& operator*();
  24.     operator T*() const;
  25. };
  26.  
  27.  
  28. template <class T>
  29. alx::unique_ptr<T>::unique_ptr(T* inp)
  30. : ptr(inp)
  31. {
  32.  
  33. }
  34.  
  35. template <class T> //array-ra nemjó
  36. alx::unique_ptr<T>::~unique_ptr()
  37. {
  38.     delete ptr;
  39.     std::endl(std::cout);
  40.     std::cout << "uniqueptr is being deleted"<<std::endl;
  41. }
  42.  
  43. template<class T>
  44. T& alx::unique_ptr<T>::operator*()
  45. {
  46.     return *ptr;
  47. }
  48.  
  49. template<class T>
  50. alx::unique_ptr<T>::operator T*() const
  51. {
  52.     return ptr;
  53. }
  54. /*
  55. template<class T, std::size_t N>
  56. alx::unique_ptr<(T&)[N]>unique_ptr(T* inp)
  57.     : ptr(inp)
  58. {
  59.  
  60. }*/
  61.  
  62. int main()
  63. {
  64.     {
  65.         alx::unique_ptr<std::string> stringptr(new std::string("asd"));
  66.         std::cout << (*stringptr);
  67.     }
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement