diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-07-26 01:47:32 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-07-26 01:47:32 +0100 |
| commit | c52dbf5513ae7f106634967162da5cfb01dc5af3 (patch) | |
| tree | b6715d0fdacebd48491b9b05cf85f1d92028f84b /dev/lib/logic/opt.hpp | |
| parent | 01565adb9cf5ef991196f56c7f5f7b6161daa005 (diff) | |
feat: SOCL v1.0.2, changelog soon!v1.0.2
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/lib/logic/opt.hpp')
| -rw-r--r-- | dev/lib/logic/opt.hpp | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/dev/lib/logic/opt.hpp b/dev/lib/logic/opt.hpp new file mode 100644 index 0000000..facbf2c --- /dev/null +++ b/dev/lib/logic/opt.hpp @@ -0,0 +1,121 @@ +/* + * File: opt.hpp + * Author: Amlal El Mahrouss, + * Copyright 2023-2025, Amlal El Mahrouss/SNU Systems Corp all rights reserved. + */ + +#ifndef _SNU_OPT_HPP +#define _SNU_OPT_HPP + +#include <lib/detail/error.hpp> +#include <utility> + +namespace snu::opt +{ + enum class return_type + { + invalid = 0, + okay = 100, + err, + count = err - okay + 1, + }; + + struct opt final + { + explicit opt(const return_type& return_type) + : m_ret(return_type) + { + } + + opt& expect(const char* input) + { + if (m_ret == return_type::err) + { + throw std::runtime_error(input); + } + + return *this; + } + + private: + return_type m_ret; + }; + + template <typename Teller, typename... Lst> + inline return_type eval(Teller tell, Lst&&... arg) + { + return tell(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err; + } + + namespace traits + { + struct int_eq_teller + { + explicit int_eq_teller() + { + } + + bool operator()(int a, int b) + { + return (a == b); + } + }; + + struct int_greater_than_teller + { + explicit int_greater_than_teller() + { + } + + bool operator()(int a, int b) + { + return (a > b); + } + }; + + struct int_less_than_teller + { + explicit int_less_than_teller() + { + } + + bool operator()(int a, int b) + { + return (a < b); + } + }; + } // namespace traits + + template <typename... Lst> + inline return_type eval_less_than(Lst&&... arg) + { + static traits::int_less_than_teller eq; + return eq(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err; + } + + template <typename... Lst> + inline return_type eval_eq(Lst&&... arg) + { + static traits::int_eq_teller less_than; + return less_than(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err; + } + + template <typename... Lst> + inline return_type eval_greater_than(Lst&&... arg) + { + static traits::int_greater_than_teller greater_than; + return greater_than(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err; + } + + inline return_type eval_true() + { + return return_type::okay; + } + + inline return_type eval_false() + { + return return_type::err; + } +} // namespace snu::opt + +#endif /* ifndef _SNU_OPT_HPP */ |
