From 230212213b00b2e17a2fd1a0c524050b6cc8b71b Mon Sep 17 00:00:00 2001 From: Alex Kremer Date: Wed, 10 Apr 2024 19:14:53 +0100 Subject: [PATCH] Remove Any wrapper (#1336) Fixes #1174 --- src/util/async/AnyExecutionContext.hpp | 53 ++++++------- src/util/async/AnyOperation.hpp | 1 - src/util/async/AnyStrand.hpp | 21 +++-- src/util/async/impl/Any.hpp | 53 ------------- src/util/async/impl/ErasedOperation.hpp | 10 +-- unittests/util/MockExecutionContext.hpp | 20 ++--- unittests/util/MockStrand.hpp | 16 ++-- .../util/async/AnyExecutionContextTests.cpp | 78 +++++++++---------- unittests/util/async/AnyOperationTests.cpp | 7 +- unittests/util/async/AnyStrandTests.cpp | 34 ++++---- 10 files changed, 117 insertions(+), 176 deletions(-) delete mode 100644 src/util/async/impl/Any.hpp diff --git a/src/util/async/AnyExecutionContext.hpp b/src/util/async/AnyExecutionContext.hpp index 8cbf1ad9e..8ebbe27c0 100644 --- a/src/util/async/AnyExecutionContext.hpp +++ b/src/util/async/AnyExecutionContext.hpp @@ -23,7 +23,6 @@ #include "util/async/AnyStopToken.hpp" #include "util/async/AnyStrand.hpp" #include "util/async/Concepts.hpp" -#include "util/async/impl/Any.hpp" #include "util/async/impl/ErasedOperation.hpp" #include @@ -66,9 +65,9 @@ public: execute(SomeHandlerWithoutStopToken auto&& fn) { using RetType = std::decay_t; - static_assert(not std::is_same_v); + static_assert(not std::is_same_v); - return AnyOperation(pimpl_->execute([fn = std::forward(fn)]() -> impl::Any { + return AnyOperation(pimpl_->execute([fn = std::forward(fn)]() -> std::any { if constexpr (std::is_void_v) { fn(); return {}; @@ -90,18 +89,16 @@ public: execute(SomeHandlerWith auto&& fn) { using RetType = std::decay_t()))>; - static_assert(not std::is_same_v); + static_assert(not std::is_same_v); - return AnyOperation( - pimpl_->execute([fn = std::forward(fn)](auto stopToken) -> impl::Any { - if constexpr (std::is_void_v) { - fn(std::move(stopToken)); - return {}; - } else { - return std::make_any(fn(std::move(stopToken))); - } - }) - ); + return AnyOperation(pimpl_->execute([fn = std::forward(fn)](auto stopToken) -> std::any { + if constexpr (std::is_void_v) { + fn(std::move(stopToken)); + return {}; + } else { + return std::make_any(fn(std::move(stopToken))); + } + })); } /** @@ -117,10 +114,10 @@ public: execute(SomeHandlerWith auto&& fn, SomeStdDuration auto timeout) { using RetType = std::decay_t()))>; - static_assert(not std::is_same_v); + static_assert(not std::is_same_v); return AnyOperation(pimpl_->execute( - [fn = std::forward(fn)](auto stopToken) -> impl::Any { + [fn = std::forward(fn)](auto stopToken) -> std::any { if constexpr (std::is_void_v) { fn(std::move(stopToken)); return {}; @@ -145,12 +142,12 @@ public: scheduleAfter(SomeStdDuration auto delay, SomeHandlerWith auto&& fn) { using RetType = std::decay_t()))>; - static_assert(not std::is_same_v); + static_assert(not std::is_same_v); auto millis = std::chrono::duration_cast(delay); return AnyOperation(pimpl_->scheduleAfter( millis, - [fn = std::forward(fn)](auto stopToken) -> impl::Any { + [fn = std::forward(fn)](auto stopToken) -> std::any { if constexpr (std::is_void_v) { fn(std::move(stopToken)); return {}; @@ -175,12 +172,12 @@ public: scheduleAfter(SomeStdDuration auto delay, SomeHandlerWith auto&& fn) { using RetType = std::decay_t(), true))>; - static_assert(not std::is_same_v); + static_assert(not std::is_same_v); auto millis = std::chrono::duration_cast(delay); return AnyOperation(pimpl_->scheduleAfter( millis, - [fn = std::forward(fn)](auto stopToken, auto cancelled) -> impl::Any { + [fn = std::forward(fn)](auto stopToken, auto cancelled) -> std::any { if constexpr (std::is_void_v) { fn(std::move(stopToken), cancelled); return {}; @@ -211,14 +208,14 @@ private: virtual impl::ErasedOperation execute( - std::function, + std::function, std::optional timeout = std::nullopt ) = 0; - virtual impl::ErasedOperation execute(std::function) = 0; + virtual impl::ErasedOperation execute(std::function) = 0; virtual impl::ErasedOperation - scheduleAfter(std::chrono::milliseconds, std::function) = 0; + scheduleAfter(std::chrono::milliseconds, std::function) = 0; virtual impl::ErasedOperation - scheduleAfter(std::chrono::milliseconds, std::function) = 0; + scheduleAfter(std::chrono::milliseconds, std::function) = 0; virtual AnyStrand makeStrand() = 0; }; @@ -232,25 +229,25 @@ private: } impl::ErasedOperation - execute(std::function fn, std::optional timeout) override + execute(std::function fn, std::optional timeout) override { return ctx.get().execute(std::move(fn), timeout); } impl::ErasedOperation - execute(std::function fn) override + execute(std::function fn) override { return ctx.get().execute(std::move(fn)); } impl::ErasedOperation - scheduleAfter(std::chrono::milliseconds delay, std::function fn) override + scheduleAfter(std::chrono::milliseconds delay, std::function fn) override { return ctx.get().scheduleAfter(delay, std::move(fn)); } impl::ErasedOperation - scheduleAfter(std::chrono::milliseconds delay, std::function fn) override + scheduleAfter(std::chrono::milliseconds delay, std::function fn) override { return ctx.get().scheduleAfter(delay, std::move(fn)); } diff --git a/src/util/async/AnyOperation.hpp b/src/util/async/AnyOperation.hpp index 872e597bb..7f030cabf 100644 --- a/src/util/async/AnyOperation.hpp +++ b/src/util/async/AnyOperation.hpp @@ -21,7 +21,6 @@ #include "util/async/Concepts.hpp" #include "util/async/Error.hpp" -#include "util/async/impl/Any.hpp" #include "util/async/impl/ErasedOperation.hpp" #include diff --git a/src/util/async/AnyStrand.hpp b/src/util/async/AnyStrand.hpp index fb4e9fe9c..e0ad96115 100644 --- a/src/util/async/AnyStrand.hpp +++ b/src/util/async/AnyStrand.hpp @@ -21,7 +21,6 @@ #include "util/async/AnyStopToken.hpp" #include "util/async/Concepts.hpp" -#include "util/async/impl/Any.hpp" #include "util/async/impl/ErasedOperation.hpp" #include @@ -64,10 +63,10 @@ public: execute(SomeHandlerWithoutStopToken auto&& fn) { using RetType = std::decay_t; - static_assert(not std::is_same_v); + static_assert(not std::is_same_v); return AnyOperation( // - pimpl_->execute([fn = std::forward(fn)]() -> impl::Any { + pimpl_->execute([fn = std::forward(fn)]() -> std::any { if constexpr (std::is_void_v) { fn(); return {}; @@ -88,10 +87,10 @@ public: execute(SomeHandlerWith auto&& fn) { using RetType = std::decay_t()))>; - static_assert(not std::is_same_v); + static_assert(not std::is_same_v); return AnyOperation( // - pimpl_->execute([fn = std::forward(fn)](auto stopToken) -> impl::Any { + pimpl_->execute([fn = std::forward(fn)](auto stopToken) -> std::any { if constexpr (std::is_void_v) { fn(std::move(stopToken)); return {}; @@ -113,11 +112,11 @@ public: execute(SomeHandlerWith auto&& fn, SomeStdDuration auto timeout) { using RetType = std::decay_t()))>; - static_assert(not std::is_same_v); + static_assert(not std::is_same_v); return AnyOperation( // pimpl_->execute( - [fn = std::forward(fn)](auto stopToken) -> impl::Any { + [fn = std::forward(fn)](auto stopToken) -> std::any { if constexpr (std::is_void_v) { fn(std::move(stopToken)); return {}; @@ -136,10 +135,10 @@ private: [[nodiscard]] virtual impl::ErasedOperation execute( - std::function, + std::function, std::optional timeout = std::nullopt ) = 0; - [[nodiscard]] virtual impl::ErasedOperation execute(std::function) = 0; + [[nodiscard]] virtual impl::ErasedOperation execute(std::function) = 0; }; template @@ -153,13 +152,13 @@ private: } [[nodiscard]] impl::ErasedOperation - execute(std::function fn, std::optional timeout) override + execute(std::function fn, std::optional timeout) override { return strand.execute(std::move(fn), timeout); } [[nodiscard]] impl::ErasedOperation - execute(std::function fn) override + execute(std::function fn) override { return strand.execute(std::move(fn)); } diff --git a/src/util/async/impl/Any.hpp b/src/util/async/impl/Any.hpp deleted file mode 100644 index dd5cba2d9..000000000 --- a/src/util/async/impl/Any.hpp +++ /dev/null @@ -1,53 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of clio: https://github.com/XRPLF/clio - Copyright (c) 2024, the clio developers. - - Permission to use, copy, modify, and distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#pragma once - -#include -#include - -// Will be removed after the migration to std::expected is complete (#1173) -// Issue to track this removal can be found here: https://github.com/XRPLF/clio/issues/1174 -namespace util::async::impl { - -/** - * @brief A wrapper for std::any to workaround issues with boost.outcome - */ -class Any { - std::any value_; - -public: - Any() = default; - Any(Any const&) = default; - - Any(Any&&) = default; - // note: this needs to be `auto` instead of `std::any` because of a bug in gcc 11.4 - Any(auto&& v) - requires(std::is_same_v, std::any>) - : value_{std::forward(v)} - { - } - - operator std::any&() noexcept - { - return value_; - } -}; - -} // namespace util::async::impl diff --git a/src/util/async/impl/ErasedOperation.hpp b/src/util/async/impl/ErasedOperation.hpp index 8bf535ae6..2faa5e21b 100644 --- a/src/util/async/impl/ErasedOperation.hpp +++ b/src/util/async/impl/ErasedOperation.hpp @@ -22,8 +22,8 @@ #include "util/Assert.hpp" #include "util/async/Concepts.hpp" #include "util/async/Error.hpp" -#include "util/async/impl/Any.hpp" +#include #include #include #include @@ -55,7 +55,7 @@ public: pimpl_->wait(); } - std::expected + std::expected get() { return pimpl_->get(); @@ -87,7 +87,7 @@ private: virtual void wait() noexcept = 0; - virtual std::expected + virtual std::expected get() = 0; virtual void requestStop() = 0; @@ -111,10 +111,10 @@ private: return operation.wait(); } - std::expected + std::expected get() override { - // Note: return type of the operation was already wrapped to impl::Any by AnyExecutionContext + // Note: return type of the operation was already wrapped to std::any by AnyExecutionContext return operation.get(); } diff --git a/unittests/util/MockExecutionContext.hpp b/unittests/util/MockExecutionContext.hpp index 1a950cd31..a3e152a08 100644 --- a/unittests/util/MockExecutionContext.hpp +++ b/unittests/util/MockExecutionContext.hpp @@ -24,10 +24,10 @@ #include "util/MockStrand.hpp" #include "util/async/AnyStopToken.hpp" #include "util/async/Error.hpp" -#include "util/async/impl/Any.hpp" #include +#include #include #include #include @@ -50,29 +50,29 @@ struct MockExecutionContext { template using ScheduledOperation = MockScheduledOperation; - MOCK_METHOD(Operation const&, execute, (std::function), (const)); + MOCK_METHOD(Operation const&, execute, (std::function), (const)); MOCK_METHOD( - Operation const&, + Operation const&, execute, - (std::function, std::optional), + (std::function, std::optional), (const) ); MOCK_METHOD( - StoppableOperation const&, + StoppableOperation const&, execute, - (std::function, std::optional), + (std::function, std::optional), (const) ); MOCK_METHOD( - ScheduledOperation const&, + ScheduledOperation const&, scheduleAfter, - (std::chrono::milliseconds, std::function), + (std::chrono::milliseconds, std::function), (const) ); MOCK_METHOD( - ScheduledOperation const&, + ScheduledOperation const&, scheduleAfter, - (std::chrono::milliseconds, std::function), + (std::chrono::milliseconds, std::function), (const) ); MOCK_METHOD(MockStrand const&, makeStrand, (), (const)); diff --git a/unittests/util/MockStrand.hpp b/unittests/util/MockStrand.hpp index 088086169..dc7d72de2 100644 --- a/unittests/util/MockStrand.hpp +++ b/unittests/util/MockStrand.hpp @@ -22,10 +22,10 @@ #include "util/MockOperation.hpp" #include "util/async/AnyStopToken.hpp" #include "util/async/Error.hpp" -#include "util/async/impl/Any.hpp" #include +#include #include #include #include @@ -41,23 +41,23 @@ struct MockStrand { template using StoppableOperation = MockStoppableOperation; - MOCK_METHOD(Operation const&, execute, (std::function), (const)); + MOCK_METHOD(Operation const&, execute, (std::function), (const)); MOCK_METHOD( - Operation const&, + Operation const&, execute, - (std::function, std::optional), + (std::function, std::optional), (const) ); MOCK_METHOD( - StoppableOperation const&, + StoppableOperation const&, execute, - (std::function), + (std::function), (const) ); MOCK_METHOD( - StoppableOperation const&, + StoppableOperation const&, execute, - (std::function, std::optional), + (std::function, std::optional), (const) ); }; diff --git a/unittests/util/async/AnyExecutionContextTests.cpp b/unittests/util/async/AnyExecutionContextTests.cpp index ec7fa4302..554613e26 100644 --- a/unittests/util/async/AnyExecutionContextTests.cpp +++ b/unittests/util/async/AnyExecutionContextTests.cpp @@ -54,8 +54,8 @@ struct AnyExecutionContextTests : Test { TEST_F(AnyExecutionContextTests, ExecuteWithoutTokenAndVoid) { - auto mockOp = OperationType{}; - EXPECT_CALL(mockExecutionContext, execute(An>())).WillOnce(ReturnRef(mockOp)); + auto mockOp = OperationType{}; + EXPECT_CALL(mockExecutionContext, execute(An>())).WillOnce(ReturnRef(mockOp)); EXPECT_CALL(mockOp, get()); auto op = ctx.execute([] { throw 0; }); @@ -66,17 +66,17 @@ TEST_F(AnyExecutionContextTests, ExecuteWithoutTokenAndVoid) TEST_F(AnyExecutionContextTests, ExecuteWithoutTokenAndVoidThrowsException) { - auto mockOp = OperationType{}; - EXPECT_CALL(mockExecutionContext, execute(An>())) - .WillOnce([](auto&&) -> OperationType const& { throw 0; }); + auto mockOp = OperationType{}; + EXPECT_CALL(mockExecutionContext, execute(An>())) + .WillOnce([](auto&&) -> OperationType const& { throw 0; }); EXPECT_ANY_THROW([[maybe_unused]] auto unused = ctx.execute([] { throw 0; })); } TEST_F(AnyExecutionContextTests, ExecuteWithStopTokenAndVoid) { - auto mockOp = StoppableOperationType{}; - EXPECT_CALL(mockExecutionContext, execute(An>(), _)) + auto mockOp = StoppableOperationType{}; + EXPECT_CALL(mockExecutionContext, execute(An>(), _)) .WillOnce(ReturnRef(mockOp)); EXPECT_CALL(mockOp, get()); @@ -88,17 +88,17 @@ TEST_F(AnyExecutionContextTests, ExecuteWithStopTokenAndVoid) TEST_F(AnyExecutionContextTests, ExecuteWithStopTokenAndVoidThrowsException) { - EXPECT_CALL(mockExecutionContext, execute(An>(), _)) - .WillOnce([](auto&&, auto) -> StoppableOperationType const& { throw 0; }); + EXPECT_CALL(mockExecutionContext, execute(An>(), _)) + .WillOnce([](auto&&, auto) -> StoppableOperationType const& { throw 0; }); EXPECT_ANY_THROW([[maybe_unused]] auto unused = ctx.execute([](auto) { throw 0; })); } TEST_F(AnyExecutionContextTests, ExecuteWithStopTokenAndReturnValue) { - auto mockOp = StoppableOperationType{}; + auto mockOp = StoppableOperationType{}; EXPECT_CALL(mockOp, get()).WillOnce(Return(std::make_any(42))); - EXPECT_CALL(mockExecutionContext, execute(An>(), _)) + EXPECT_CALL(mockExecutionContext, execute(An>(), _)) .WillOnce(ReturnRef(mockOp)); auto op = ctx.execute([](auto) -> int { throw 0; }); @@ -109,19 +109,19 @@ TEST_F(AnyExecutionContextTests, ExecuteWithStopTokenAndReturnValue) TEST_F(AnyExecutionContextTests, ExecuteWithStopTokenAndReturnValueThrowsException) { - EXPECT_CALL(mockExecutionContext, execute(An>(), _)) - .WillOnce([](auto&&, auto) -> StoppableOperationType const& { throw 0; }); + EXPECT_CALL(mockExecutionContext, execute(An>(), _)) + .WillOnce([](auto&&, auto) -> StoppableOperationType const& { throw 0; }); EXPECT_ANY_THROW([[maybe_unused]] auto unused = ctx.execute([](auto) -> int { throw 0; })); } TEST_F(AnyExecutionContextTests, TimerCancellation) { - auto mockScheduledOp = ScheduledOperationType{}; + auto mockScheduledOp = ScheduledOperationType{}; EXPECT_CALL(mockScheduledOp, cancel()); EXPECT_CALL( mockExecutionContext, - scheduleAfter(An(), An>()) + scheduleAfter(An(), An>()) ) .WillOnce(ReturnRef(mockScheduledOp)); @@ -133,13 +133,13 @@ TEST_F(AnyExecutionContextTests, TimerCancellation) TEST_F(AnyExecutionContextTests, TimerExecuted) { - auto mockScheduledOp = ScheduledOperationType{}; + auto mockScheduledOp = ScheduledOperationType{}; EXPECT_CALL(mockScheduledOp, get()).WillOnce(Return(std::make_any(42))); EXPECT_CALL( mockExecutionContext, - scheduleAfter(An(), An>()) + scheduleAfter(An(), An>()) ) - .WillOnce([&mockScheduledOp](auto, auto&&) -> ScheduledOperationType const& { + .WillOnce([&mockScheduledOp](auto, auto&&) -> ScheduledOperationType const& { return mockScheduledOp; }); @@ -151,11 +151,11 @@ TEST_F(AnyExecutionContextTests, TimerExecuted) TEST_F(AnyExecutionContextTests, TimerWithBoolHandlerCancellation) { - auto mockScheduledOp = ScheduledOperationType{}; + auto mockScheduledOp = ScheduledOperationType{}; EXPECT_CALL(mockScheduledOp, cancel()); EXPECT_CALL( mockExecutionContext, - scheduleAfter(An(), An>()) + scheduleAfter(An(), An>()) ) .WillOnce(ReturnRef(mockScheduledOp)); @@ -167,13 +167,13 @@ TEST_F(AnyExecutionContextTests, TimerWithBoolHandlerCancellation) TEST_F(AnyExecutionContextTests, TimerWithBoolHandlerExecuted) { - auto mockScheduledOp = ScheduledOperationType{}; + auto mockScheduledOp = ScheduledOperationType{}; EXPECT_CALL(mockScheduledOp, get()).WillOnce(Return(std::make_any(42))); EXPECT_CALL( mockExecutionContext, - scheduleAfter(An(), An>()) + scheduleAfter(An(), An>()) ) - .WillOnce([&mockScheduledOp](auto, auto&&) -> ScheduledOperationType const& { + .WillOnce([&mockScheduledOp](auto, auto&&) -> ScheduledOperationType const& { return mockScheduledOp; }); @@ -185,11 +185,11 @@ TEST_F(AnyExecutionContextTests, TimerWithBoolHandlerExecuted) TEST_F(AnyExecutionContextTests, StrandExecuteWithVoid) { - auto mockOp = OperationType{}; + auto mockOp = OperationType{}; auto mockStrand = StrandType{}; EXPECT_CALL(mockOp, get()); EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand)); - EXPECT_CALL(mockStrand, execute(An>())).WillOnce(ReturnRef(mockOp)); + EXPECT_CALL(mockStrand, execute(An>())).WillOnce(ReturnRef(mockOp)); auto strand = ctx.makeStrand(); static_assert(std::is_same_v); @@ -204,8 +204,8 @@ TEST_F(AnyExecutionContextTests, StrandExecuteWithVoidThrowsException) { auto mockStrand = StrandType{}; EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand)); - EXPECT_CALL(mockStrand, execute(An>())) - .WillOnce([](auto&&) -> OperationType const& { throw 0; }); + EXPECT_CALL(mockStrand, execute(An>())) + .WillOnce([](auto&&) -> OperationType const& { throw 0; }); auto strand = ctx.makeStrand(); static_assert(std::is_same_v); @@ -215,11 +215,11 @@ TEST_F(AnyExecutionContextTests, StrandExecuteWithVoidThrowsException) TEST_F(AnyExecutionContextTests, StrandExecuteWithReturnValue) { - auto mockOp = OperationType{}; + auto mockOp = OperationType{}; auto mockStrand = StrandType{}; EXPECT_CALL(mockOp, get()).WillOnce(Return(std::make_any(42))); EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand)); - EXPECT_CALL(mockStrand, execute(An>())).WillOnce(ReturnRef(mockOp)); + EXPECT_CALL(mockStrand, execute(An>())).WillOnce(ReturnRef(mockOp)); auto strand = ctx.makeStrand(); static_assert(std::is_same_v); @@ -234,8 +234,8 @@ TEST_F(AnyExecutionContextTests, StrandExecuteWithReturnValueThrowsException) { auto mockStrand = StrandType{}; EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand)); - EXPECT_CALL(mockStrand, execute(An>())) - .WillOnce([](auto&&) -> OperationType const& { throw 0; }); + EXPECT_CALL(mockStrand, execute(An>())) + .WillOnce([](auto&&) -> OperationType const& { throw 0; }); auto strand = ctx.makeStrand(); static_assert(std::is_same_v); @@ -245,11 +245,11 @@ TEST_F(AnyExecutionContextTests, StrandExecuteWithReturnValueThrowsException) TEST_F(AnyExecutionContextTests, StrandExecuteWithStopTokenAndVoid) { - auto mockOp = StoppableOperationType{}; + auto mockOp = StoppableOperationType{}; auto mockStrand = StrandType{}; EXPECT_CALL(mockOp, get()); EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand)); - EXPECT_CALL(mockStrand, execute(An>(), _)).WillOnce(ReturnRef(mockOp)); + EXPECT_CALL(mockStrand, execute(An>(), _)).WillOnce(ReturnRef(mockOp)); auto strand = ctx.makeStrand(); static_assert(std::is_same_v); @@ -264,8 +264,8 @@ TEST_F(AnyExecutionContextTests, StrandExecuteWithStopTokenAndVoidThrowsExceptio { auto mockStrand = StrandType{}; EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand)); - EXPECT_CALL(mockStrand, execute(An>(), _)) - .WillOnce([](auto&&, auto) -> StoppableOperationType const& { throw 0; }); + EXPECT_CALL(mockStrand, execute(An>(), _)) + .WillOnce([](auto&&, auto) -> StoppableOperationType const& { throw 0; }); auto strand = ctx.makeStrand(); static_assert(std::is_same_v); @@ -275,11 +275,11 @@ TEST_F(AnyExecutionContextTests, StrandExecuteWithStopTokenAndVoidThrowsExceptio TEST_F(AnyExecutionContextTests, StrandExecuteWithStopTokenAndReturnValue) { - auto mockOp = StoppableOperationType{}; + auto mockOp = StoppableOperationType{}; auto mockStrand = StrandType{}; EXPECT_CALL(mockOp, get()).WillOnce(Return(std::make_any(42))); EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand)); - EXPECT_CALL(mockStrand, execute(An>(), _)).WillOnce(ReturnRef(mockOp)); + EXPECT_CALL(mockStrand, execute(An>(), _)).WillOnce(ReturnRef(mockOp)); auto strand = ctx.makeStrand(); static_assert(std::is_same_v); @@ -294,8 +294,8 @@ TEST_F(AnyExecutionContextTests, StrandExecuteWithStopTokenAndReturnValueThrowsE { auto mockStrand = StrandType{}; EXPECT_CALL(mockExecutionContext, makeStrand()).WillOnce(ReturnRef(mockStrand)); - EXPECT_CALL(mockStrand, execute(An>(), _)) - .WillOnce([](auto&&, auto) -> StoppableOperationType const& { throw 0; }); + EXPECT_CALL(mockStrand, execute(An>(), _)) + .WillOnce([](auto&&, auto) -> StoppableOperationType const& { throw 0; }); auto strand = ctx.makeStrand(); static_assert(std::is_same_v); diff --git a/unittests/util/async/AnyOperationTests.cpp b/unittests/util/async/AnyOperationTests.cpp index 0ec877863..21ffac7f5 100644 --- a/unittests/util/async/AnyOperationTests.cpp +++ b/unittests/util/async/AnyOperationTests.cpp @@ -32,8 +32,8 @@ using namespace util::async; using namespace ::testing; struct AnyOperationTests : Test { - using OperationType = MockOperation>; - using ScheduledOperationType = MockScheduledOperation>; + using OperationType = MockOperation>; + using ScheduledOperationType = MockScheduledOperation>; NaggyMock mockOp; NaggyMock mockScheduledOp; @@ -46,8 +46,7 @@ using AnyOperationDeathTest = AnyOperationTests; TEST_F(AnyOperationTests, VoidDataYieldsNoError) { - auto const noError = std::expected(impl::Any{}); - EXPECT_CALL(mockOp, get()).WillOnce(Return(noError)); + EXPECT_CALL(mockOp, get()).WillOnce(Return(std::any{})); auto res = voidOp.get(); ASSERT_TRUE(res); } diff --git a/unittests/util/async/AnyStrandTests.cpp b/unittests/util/async/AnyStrandTests.cpp index 4547df6ab..fbaee9e18 100644 --- a/unittests/util/async/AnyStrandTests.cpp +++ b/unittests/util/async/AnyStrandTests.cpp @@ -48,8 +48,8 @@ struct AnyStrandTests : ::testing::Test { TEST_F(AnyStrandTests, ExecuteWithoutTokenAndVoid) { - auto mockOp = OperationType{}; - EXPECT_CALL(mockStrand, execute(An>())).WillOnce(ReturnRef(mockOp)); + auto mockOp = OperationType{}; + EXPECT_CALL(mockStrand, execute(An>())).WillOnce(ReturnRef(mockOp)); auto op = strand.execute([] {}); static_assert(std::is_same_v>); @@ -59,17 +59,17 @@ TEST_F(AnyStrandTests, ExecuteWithoutTokenAndVoid) TEST_F(AnyStrandTests, ExecuteWithoutTokenAndVoidThrowsException) { - auto mockOp = OperationType{}; - EXPECT_CALL(mockStrand, execute(An>())) - .WillOnce([](auto&&) -> OperationType const& { throw 0; }); + auto mockOp = OperationType{}; + EXPECT_CALL(mockStrand, execute(An>())) + .WillOnce([](auto&&) -> OperationType const& { throw 0; }); EXPECT_ANY_THROW([[maybe_unused]] auto unused = strand.execute([] {})); } TEST_F(AnyStrandTests, ExecuteWithStopTokenAndVoid) { - auto mockOp = StoppableOperationType{}; - EXPECT_CALL(mockStrand, execute(An>(), _)).WillOnce(ReturnRef(mockOp)); + auto mockOp = StoppableOperationType{}; + EXPECT_CALL(mockStrand, execute(An>(), _)).WillOnce(ReturnRef(mockOp)); auto op = strand.execute([](auto) {}); static_assert(std::is_same_v>); @@ -79,17 +79,17 @@ TEST_F(AnyStrandTests, ExecuteWithStopTokenAndVoid) TEST_F(AnyStrandTests, ExecuteWithStopTokenAndVoidThrowsException) { - EXPECT_CALL(mockStrand, execute(An>(), _)) - .WillOnce([](auto&&, auto) -> StoppableOperationType const& { throw 0; }); + EXPECT_CALL(mockStrand, execute(An>(), _)) + .WillOnce([](auto&&, auto) -> StoppableOperationType const& { throw 0; }); EXPECT_ANY_THROW([[maybe_unused]] auto unused = strand.execute([](auto) {})); } TEST_F(AnyStrandTests, ExecuteWithStopTokenAndReturnValue) { - auto mockOp = StoppableOperationType{}; + auto mockOp = StoppableOperationType{}; EXPECT_CALL(mockOp, get()).WillOnce(Return(std::make_any(42))); - EXPECT_CALL(mockStrand, execute(An>(), _)).WillOnce(ReturnRef(mockOp)); + EXPECT_CALL(mockStrand, execute(An>(), _)).WillOnce(ReturnRef(mockOp)); auto op = strand.execute([](auto) { return 42; }); static_assert(std::is_same_v>); @@ -99,17 +99,17 @@ TEST_F(AnyStrandTests, ExecuteWithStopTokenAndReturnValue) TEST_F(AnyStrandTests, ExecuteWithStopTokenAndReturnValueThrowsException) { - EXPECT_CALL(mockStrand, execute(An>(), _)) - .WillOnce([](auto&&, auto) -> StoppableOperationType const& { throw 0; }); + EXPECT_CALL(mockStrand, execute(An>(), _)) + .WillOnce([](auto&&, auto) -> StoppableOperationType const& { throw 0; }); EXPECT_ANY_THROW([[maybe_unused]] auto unused = strand.execute([](auto) { return 42; })); } TEST_F(AnyStrandTests, ExecuteWithTimeoutAndStopTokenAndReturnValue) { - auto mockOp = StoppableOperationType{}; + auto mockOp = StoppableOperationType{}; EXPECT_CALL(mockOp, get()).WillOnce(Return(std::make_any(42))); - EXPECT_CALL(mockStrand, execute(An>(), _)).WillOnce(ReturnRef(mockOp)); + EXPECT_CALL(mockStrand, execute(An>(), _)).WillOnce(ReturnRef(mockOp)); auto op = strand.execute([](auto) { return 42; }, std::chrono::milliseconds{1}); static_assert(std::is_same_v>); @@ -119,8 +119,8 @@ TEST_F(AnyStrandTests, ExecuteWithTimeoutAndStopTokenAndReturnValue) TEST_F(AnyStrandTests, ExecuteWithTimoutAndStopTokenAndReturnValueThrowsException) { - EXPECT_CALL(mockStrand, execute(An>(), _)) - .WillOnce([](auto&&, auto) -> StoppableOperationType const& { throw 0; }); + EXPECT_CALL(mockStrand, execute(An>(), _)) + .WillOnce([](auto&&, auto) -> StoppableOperationType const& { throw 0; }); EXPECT_ANY_THROW( [[maybe_unused]] auto unused = strand.execute([](auto) { return 42; }, std::chrono::milliseconds{1})