From a5ded91f8a187dcf172d41112042fe24bdfddb53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20R=C3=B6ger?= Date: Thu, 19 Mar 2026 01:17:57 +0100 Subject: [PATCH] feat(pipeline): add MetaStack --- include/mosh-me/pipeline.hpp | 41 ++++++++++++++++++++++++++++++++++++ test/pipeline.cpp | 10 +++++++++ 2 files changed, 51 insertions(+) diff --git a/include/mosh-me/pipeline.hpp b/include/mosh-me/pipeline.hpp index 2943e7c..8c6fad2 100644 --- a/include/mosh-me/pipeline.hpp +++ b/include/mosh-me/pipeline.hpp @@ -10,6 +10,47 @@ enum class PipeStatus { PIPE_ERROR, }; +struct EmptyMeta { + template auto get() { + static_assert(false, "ID not found in the MetaStack"); + } +}; + +template class MetaStack { +private: + Data data_; + ParentMeta parent_; + +public: + using ID_t = ID; + using Data_t = Data; + + template + MetaStack(D &&data, P &&parent) + : data_(std::forward(data)), parent_(std::forward

(parent)) {} + + template auto get() { + if constexpr (std::is_same_v) { + return data_; + } else { + return parent_.template get(); + } + } +}; + +template +MetaStack> makeMeta(Data &&d) { + return MetaStack>(std::forward(d), + EmptyMeta{}); +} + +template +MetaStack, ID, std::decay_t> +makeMeta(ParentMeta &&p, Data &&d) { + return MetaStack, ID, std::decay_t>( + std::forward(d), std::forward(p)); +} + template using PipeData = std::expected; template class PipeOutput { diff --git a/test/pipeline.cpp b/test/pipeline.cpp index c82ca69..f9fcaab 100644 --- a/test/pipeline.cpp +++ b/test/pipeline.cpp @@ -69,3 +69,13 @@ TEST_CASE("Pipeline") { REQUIRE(count == 5); } + +TEST_CASE("MetaStack") { + struct IntId; + struct StringId; + + auto s = makeMeta(makeMeta(std::string("test")), 10); + + REQUIRE(s.get() == "test"); + REQUIRE(s.get() == 10); +}