From 78bf3e039d77e3eb0d5e394273adb69b2b70a76d Mon Sep 17 00:00:00 2001
From: Kimplul <kimi.h.kuparinen@gmail.com>
Date: Mon, 17 Mar 2025 02:12:02 +0200
Subject: detect leaks

---
 lib/fwdlib.hpp | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

(limited to 'lib')

diff --git a/lib/fwdlib.hpp b/lib/fwdlib.hpp
index 623dc13..51450c1 100644
--- a/lib/fwdlib.hpp
+++ b/lib/fwdlib.hpp
@@ -10,7 +10,9 @@
 
 using namespace std;
 
-static void fwd_getline(auto next)
+typedef const char *fwd_err_t;
+
+static fwd_err_t fwd_getline(auto next)
 {
 	if (cin.eof())
 		return next(optional<string>{});
@@ -21,13 +23,13 @@ static void fwd_getline(auto next)
 		return next(optional<string>{});
 }
 
-static void fwd_foreach(auto container, auto next)
+static fwd_err_t fwd_foreach(auto container, auto next)
 {
 	for (auto &n : container)
 		next(n);
 }
 
-static void fwd_some(auto option, auto ok, auto fail)
+static fwd_err_t fwd_some(auto option, auto ok, auto fail)
 {
 	if (option)
 		return ok(std::move(option.value()));
@@ -35,12 +37,12 @@ static void fwd_some(auto option, auto ok, auto fail)
 		return fail();
 }
 
-static void fwd_copy(auto n, auto next)
+static fwd_err_t fwd_copy(auto n, auto next)
 {
 	return next(n, n);
 }
 
-static void fwd_null(auto *x, auto fail, auto ok)
+static fwd_err_t fwd_null(auto *x, auto fail, auto ok)
 {
 	if (x)
 		return ok(*x);
@@ -48,18 +50,19 @@ static void fwd_null(auto *x, auto fail, auto ok)
 		return fail();
 }
 
-static void fwd_insert(auto container, auto elem, auto next)
+static fwd_err_t fwd_insert(auto container, auto elem, auto next)
 {
 	container.insert(std::move(elem));
 	return next(std::move(container));
 }
 
-static void fwd_println(auto elem)
+static fwd_err_t fwd_println(auto elem)
 {
 	cout << elem << endl;
+	return nullptr;
 }
 
-static void fwd_intalloc(auto ok)
+static fwd_err_t fwd_intalloc(auto ok)
 {
 	int *p = new int{20};
 	ok(p);
-- 
cgit v1.2.3