From 22f6534081acfabdab4956d337604a21e7da5b64 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 22 Sep 2026 18:56:44 +0200 Subject: lib: generalize concepts --- ttwhy/routers/concepts.cppm | 7 ++----- ttwhy/routers/echo.cppm | 2 -- ttwhy/routers/echo.tests.cpp | 20 +++++++++----------- 3 files changed, 11 insertions(+), 18 deletions(-) (limited to 'ttwhy/routers') diff --git a/ttwhy/routers/concepts.cppm b/ttwhy/routers/concepts.cppm index 9660afc..cfbcb5a 100644 --- a/ttwhy/routers/concepts.cppm +++ b/ttwhy/routers/concepts.cppm @@ -6,14 +6,11 @@ module; export module ttwhy.routers:concepts; -import ttwhy.scanners; - namespace ttwhy { - export template - concept router = requires(Candidate candidate, scanners::input_event event) { - typename Candidate::terminal_policy; + export template + concept router = requires(Candidate candidate, Event event) { { candidate.process(event) } -> std::same_as>; }; diff --git a/ttwhy/routers/echo.cppm b/ttwhy/routers/echo.cppm index ff309c8..c9cd7c7 100644 --- a/ttwhy/routers/echo.cppm +++ b/ttwhy/routers/echo.cppm @@ -29,8 +29,6 @@ namespace ttwhy::routers export template struct echo { - using terminal_policy = scanners::xterm_policy; - explicit echo(StreamType & stream) : m_output_stream{stream} {} diff --git a/ttwhy/routers/echo.tests.cpp b/ttwhy/routers/echo.tests.cpp index c6ea10a..da2db40 100644 --- a/ttwhy/routers/echo.tests.cpp +++ b/ttwhy/routers/echo.tests.cpp @@ -46,29 +46,27 @@ namespace } }; - struct incomplete_router_no_policy - { - auto process(ttwhy::scanners::input_event) -> asio::awaitable; - }; - struct incomplete_router_no_process { - using terminal_policy = ttwhy::scanners::xterm_policy; }; struct incomplete_router_wrong_return { - using terminal_policy = ttwhy::scanners::xterm_policy; auto process(ttwhy::scanners::input_event) -> void; }; + + struct incomplete_router_wrong_event + { + auto process(int) -> asio::awaitable; + }; } // namespace TEST_CASE("The router concept validates router candidate interfaces", "[router][concept]") { - STATIC_REQUIRE(ttwhy::router>); - STATIC_REQUIRE_FALSE(ttwhy::router); - STATIC_REQUIRE_FALSE(ttwhy::router); - STATIC_REQUIRE_FALSE(ttwhy::router); + STATIC_REQUIRE(ttwhy::router, ttwhy::scanners::input_event>); + STATIC_REQUIRE_FALSE(ttwhy::router); + STATIC_REQUIRE_FALSE(ttwhy::router); + STATIC_REQUIRE_FALSE(ttwhy::router); } SCENARIO("The echo router handles terminal navigation within the valid printed area", "[router][echo]") -- cgit v1.2.3