feat(pipeline): add MetaStack

This commit is contained in:
2026-03-19 01:17:57 +01:00
parent db53fb7952
commit a5ded91f8a
2 changed files with 51 additions and 0 deletions

View File

@@ -10,6 +10,47 @@ enum class PipeStatus {
PIPE_ERROR,
};
struct EmptyMeta {
template <typename GetID> auto get() {
static_assert(false, "ID not found in the MetaStack");
}
};
template <typename ParentMeta, typename ID, typename Data> class MetaStack {
private:
Data data_;
ParentMeta parent_;
public:
using ID_t = ID;
using Data_t = Data;
template <typename D, typename P>
MetaStack(D &&data, P &&parent)
: data_(std::forward<D>(data)), parent_(std::forward<P>(parent)) {}
template <typename GetID> auto get() {
if constexpr (std::is_same_v<ID_t, GetID>) {
return data_;
} else {
return parent_.template get<GetID>();
}
}
};
template <typename ID, typename Data>
MetaStack<EmptyMeta, ID, std::decay_t<Data>> makeMeta(Data &&d) {
return MetaStack<EmptyMeta, ID, std::decay_t<Data>>(std::forward<Data>(d),
EmptyMeta{});
}
template <typename ID, typename ParentMeta, typename Data>
MetaStack<std::decay_t<ParentMeta>, ID, std::decay_t<Data>>
makeMeta(ParentMeta &&p, Data &&d) {
return MetaStack<std::decay_t<ParentMeta>, ID, std::decay_t<Data>>(
std::forward<Data>(d), std::forward<ParentMeta>(p));
}
template <typename Data> using PipeData = std::expected<Data, PipeStatus>;
template <typename Output, typename OMeta> class PipeOutput {

View File

@@ -69,3 +69,13 @@ TEST_CASE("Pipeline") {
REQUIRE(count == 5);
}
TEST_CASE("MetaStack") {
struct IntId;
struct StringId;
auto s = makeMeta<IntId>(makeMeta<StringId>(std::string("test")), 10);
REQUIRE(s.get<StringId>() == "test");
REQUIRE(s.get<IntId>() == 10);
}