diff --git a/include/acto/util.h b/include/acto/util.h new file mode 100644 index 0000000..b72fe0d --- /dev/null +++ b/include/acto/util.h @@ -0,0 +1,18 @@ +#pragma once + +namespace acto::util { + +/** + * This base class is useful 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..4c12b6f 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -1,5 +1,6 @@ #include "catch.hpp" #include +#include #include #include @@ -196,6 +197,31 @@ 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; + 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 { };