aboutsummaryrefslogtreecommitdiff
path: root/lib/fwdlib.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fwdlib.hpp')
-rw-r--r--lib/fwdlib.hpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/fwdlib.hpp b/lib/fwdlib.hpp
new file mode 100644
index 0000000..0462c52
--- /dev/null
+++ b/lib/fwdlib.hpp
@@ -0,0 +1,48 @@
+#ifndef FWDLIB_HPP
+#define FWDLIB_HPP
+
+#include <string>
+#include <optional>
+#include <iostream>
+#include <unordered_map>
+#include <unordered_set>
+
+using namespace std;
+
+static inline void fwd_getline(auto next)
+{
+ if (cin.eof())
+ next(optional<string>{});
+
+ if (string line; getline(cin, line))
+ next(optional<string>{line});
+ else
+ next(optional<string>{});
+}
+
+static void fwd_foreach(auto container, auto next)
+{
+ for (auto &n : container)
+ next(n);
+}
+
+static void fwd_some(auto option, auto ok, auto fail)
+{
+ if (option)
+ ok(std::move(option.value()));
+ else
+ fail();
+}
+
+static void fwd_insert(auto container, auto elem, auto next)
+{
+ container.insert(std::move(elem));
+ next(std::move(container));
+}
+
+static void fwd_println(auto elem)
+{
+ cout << elem << endl;
+}
+
+#endif /* FWDLIB_HPP */