From 6022483a6062615b371e9c82758754494318c49c Mon Sep 17 00:00:00 2001 From: artpaul Date: Thu, 22 May 2025 17:37:52 +0500 Subject: [PATCH 1/3] helper base class move_only --- include/acto/util.h | 18 ++++++++++++++++++ test/tests.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 include/acto/util.h diff --git a/include/acto/util.h b/include/acto/util.h new file mode 100644 index 0000000..e1d2ed6 --- /dev/null +++ b/include/acto/util.h @@ -0,0 +1,18 @@ +#pragma once + +namespace acto::util { + +/** + * This base class is usefull for defining move-only events. + */ +struct move_only { + constexpr move_only() = default; + + constexpr move_only(const move_only&) = delete; + constexpr move_only(move_only&&) noexcept = default; + + constexpr move_only& operator=(const move_only&) = delete; + constexpr move_only& operator=(move_only&&) noexcept = default; +}; + +} // namespace acto::util diff --git a/test/tests.cpp b/test/tests.cpp index 2afa888..99b7add 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -1,5 +1,6 @@ #include "catch.hpp" #include +#include #include #include @@ -196,6 +197,30 @@ TEST_CASE("Key for containers") { acto::destroy(b); } +TEST_CASE("Move only") { + struct A : acto::actor { + struct M : acto::util::move_only { + std::string s; + }; + + A() { + actor::handler([this](M e) { + handle(std::move(e)); + actor::die(); + }); + } + + void handle(M&& m) { + REQUIRE(m.s == "test"); + } + }; + + A::M ev{.s = "test"}; + auto a = acto::spawn(); + a.send(std::move(ev)); + acto::join(a); +} + TEST_CASE("Send from bootstrap") { struct A : acto::actor { struct M { }; From d66fcaedf7436104dbfc46e477a9bf2e25a91a42 Mon Sep 17 00:00:00 2001 From: artpaul Date: Thu, 22 May 2025 17:39:56 +0500 Subject: [PATCH 2/3] typo --- include/acto/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/acto/util.h b/include/acto/util.h index e1d2ed6..b72fe0d 100644 --- a/include/acto/util.h +++ b/include/acto/util.h @@ -3,7 +3,7 @@ namespace acto::util { /** - * This base class is usefull for defining move-only events. + * This base class is useful for defining move-only events. */ struct move_only { constexpr move_only() = default; From 9fc86c888d91b8d10a0abb31649852e0c825ab71 Mon Sep 17 00:00:00 2001 From: artpaul Date: Thu, 22 May 2025 17:42:09 +0500 Subject: [PATCH 3/3] fix --- test/tests.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/tests.cpp b/test/tests.cpp index 99b7add..4c12b6f 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -215,7 +215,8 @@ TEST_CASE("Move only") { } }; - A::M ev{.s = "test"}; + A::M ev; + ev.s = "test"; auto a = acto::spawn(); a.send(std::move(ev)); acto::join(a);