summaryrefslogtreecommitdiffhomepage
path: root/dev/lib/logic/opt.hpp
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-09-10 03:28:35 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-09-10 03:28:35 +0200
commit3f9c5017abf3c4279780f685580a334574e6d760 (patch)
treea54540a8549542bf5385ae5b17878949b011aae4 /dev/lib/logic/opt.hpp
parent2ecbd2bfb27060b6f45196d8481fd0ccdbea730c (diff)
feat:! breaking changes in the `opt` module. Fix `println` in `io`
module. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/lib/logic/opt.hpp')
-rw-r--r--dev/lib/logic/opt.hpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/dev/lib/logic/opt.hpp b/dev/lib/logic/opt.hpp
index 442756c..137460c 100644
--- a/dev/lib/logic/opt.hpp
+++ b/dev/lib/logic/opt.hpp
@@ -20,6 +20,7 @@ namespace ocl
count = err - okay + 1,
};
+ template <typename char_type = char>
struct opt final
{
explicit opt(const return_type& return_type)
@@ -27,11 +28,23 @@ namespace ocl
{
}
- opt& expect(const char* input)
+ template <typename ErrorHandler>
+ opt& try_or_handle(const char_type* input)
{
if (m_ret == return_type::err)
{
- throw std::runtime_error(input);
+ ErrorHandler handler;
+ handler(input ? input : "");
+ }
+
+ return *this;
+ }
+
+ opt& try_or_throw(const char_type* input)
+ {
+ if (m_ret == return_type::err)
+ {
+ throw std::runtime_error(input ? input : "");
}
return *this;