diff --git a/support-lib/cpp/Future.hpp b/support-lib/cpp/Future.hpp index dede703d..6fe597cb 100644 --- a/support-lib/cpp/Future.hpp +++ b/support-lib/cpp/Future.hpp @@ -56,13 +56,13 @@ template struct ValueHolder { using type = T; std::optional value; - T getValueUnsafe() const {return *value;} + T&& getValueUnsafe() && {return std::move(*value);} }; template <> struct ValueHolder { using type = bool; std::optional value; - void getValueUnsafe() const {} + void getValueUnsafe() && {} }; template @@ -295,7 +295,7 @@ class Future { sharedState->cv.wait(lk, [state = sharedState] {return state->isReady();}); #endif if (!sharedState->exception) { - return sharedState->getValueUnsafe(); + return std::move(*sharedState).getValueUnsafe(); } else { std::rethrow_exception(sharedState->exception); } diff --git a/test-suite/handwritten-src/objc/tests/DBCppFutureTests.mm b/test-suite/handwritten-src/objc/tests/DBCppFutureTests.mm new file mode 100644 index 00000000..a34fdef3 --- /dev/null +++ b/test-suite/handwritten-src/objc/tests/DBCppFutureTests.mm @@ -0,0 +1,29 @@ +#import + +#include + +@interface DBCppFutureTests : XCTestCase + +@end + +@implementation DBCppFutureTests + +- (void)setUp +{ + [super setUp]; +} + +- (void)tearDown +{ + [super tearDown]; +} + +- (void)testCppFutureMovesResult +{ + auto future = djinni::Promise>::resolve(std::make_unique(5)); + auto ptr = future.get(); + XCTAssertTrue(!!ptr); + XCTAssertEqual(*ptr, 5); +} + +@end