From 06c154057fdc27186ec4d1c6c22fd6f73adba468 Mon Sep 17 00:00:00 2001 From: allem Date: Sat, 11 Jan 2020 21:22:58 -0500 Subject: [PATCH] overload walk to use gen directly --- include/tc/core.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/tc/core.hpp b/include/tc/core.hpp index b8cfd4e..d69f1b0 100644 --- a/include/tc/core.hpp +++ b/include/tc/core.hpp @@ -49,6 +49,23 @@ namespace tc { return res; } + template + [[nodiscard]] std::vector walk( + T start, + std::function op + ) const { + std::vector res(size()); + res[0] = start; + + for (int i = 1; i < res.size(); ++i) { + auto &action = path[i]; + auto &from = res[action.from_idx]; + auto &val = action.gen; + res[i] = op(from, val); + } + + return res; + } [[nodiscard]] size_t size() const; };