Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #include "shared.h"
- #include <iostream>
- #include "shared.h" // for size_t
- // #include "tmp.h" // for size_t
- #include <iostream> // for std::nullptr_t
- #include <cassert>
- #define REQUIRE assert
- template<typename T>
- class A {
- private:
- T* ptr_;
- public:
- template<typename Y>
- requires (std::derived_from<T, Y> || std::same_as<T, Y>)
- explicit A(Y* ptr) : ptr_(static_cast<T*>(ptr)) {
- // some code
- }
- };
- struct Pinned {
- Pinned(int tag) : tag_(tag) {
- }
- Pinned(const Pinned& a) = delete;
- Pinned(Pinned&& a) = delete;
- Pinned& operator=(const Pinned& a) = delete;
- Pinned& operator=(Pinned&& a) = delete;
- ~Pinned() = default;
- int GetTag() const {
- return tag_;
- }
- private:
- int tag_;
- };
- int main() {
- /**/
- SharedPtr<std::string> a(new std::string("aba"));
- std::string* ptr;
- {
- SharedPtr b(a);
- SharedPtr c(a);
- ptr = c.Get();
- }
- REQUIRE(ptr == a.Get());
- REQUIRE(*ptr == "aba");
- SharedPtr<std::string> b(new std::string("caba"));
- {
- SharedPtr c(b);
- SharedPtr d(b);
- d = std::move(a);
- REQUIRE(*c == "caba");
- REQUIRE(*d == "aba");
- b.Reset(new std::string("test"));
- REQUIRE(*c == "caba");
- }
- REQUIRE(*b == "test");
- SharedPtr<std::string> end;
- {
- SharedPtr<std::string> d(new std::string("delete"));
- d = b;
- SharedPtr c(std::move(b));
- REQUIRE(*d == "test");
- REQUIRE(*c == "test");
- d = d;
- c = end;
- d.Reset(new std::string("delete"));
- end = d;
- }
- REQUIRE(*end == "delete");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement