#ifndef TEST_INTEROP_CXX_STDLIB_INPUTS_STD_UNIQUE_PTR_H #define TEST_INTEROP_CXX_STDLIB_INPUTS_STD_UNIQUE_PTR_H #include #include #include struct NonCopyable { NonCopyable(int x) : x(x) {} NonCopyable(const NonCopyable &) = delete; NonCopyable(NonCopyable &&other) : x(other.x) { other.x = -123; } int method(int y) const { return x * y; } int mutMethod(int y) { x = y; return y; } int x; }; struct NonCopyableDerived: public NonCopyable { NonCopyableDerived(int x) : NonCopyable(x) {} }; inline std::shared_ptr getNonCopyableSharedPtr() { return std::make_shared(42); } inline std::unique_ptr getNonCopyableUniquePtr() { return std::make_unique(42); } inline std::vector> getVectorNonCopyableUniquePtr() { std::vector> vec; vec.emplace_back(); return vec; } std::unique_ptr makeInt() { return std::make_unique(42); } std::unique_ptr makeString() { return std::make_unique("Unique string"); } std::unique_ptr makeArray() { int *array = new int[3]; array[0] = 1; array[1] = 2; array[2] = 3; return std::unique_ptr(array); } static bool dtorCalled = false; struct HasDtor { HasDtor() = default; #if __is_target_os(windows) // On windows, force this type to be address-only. HasDtor(const HasDtor &other); #endif ~HasDtor() { dtorCalled = true; } private: int x; }; std::unique_ptr makeDtor() { return std::make_unique(); } std::shared_ptr makeIntShared() { return std::make_unique(42); } std::shared_ptr makeStringShared() { return std::make_unique("Shared string"); } static int copies = 0; struct CountCopies { CountCopies() = default; CountCopies(const CountCopies& other) { ++copies; } ~CountCopies() {} int getCopies() const { return copies; } void method() {} void constMethod() const {} int field = 42; }; inline std::unique_ptr getCopyCountedUniquePtr() { return std::make_unique(); } #endif // TEST_INTEROP_CXX_STDLIB_INPUTS_STD_UNIQUE_PTR_H