diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-03-28 05:05:55 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-03-28 05:05:55 +0100 |
| commit | 02856414d220a5a4cb8d196de490698dd0cc0c70 (patch) | |
| tree | 64f0a3d47848a5f00b462a1be5ea232164ae2a49 /lib/stdx | |
| parent | 944dafbf0ab104fabad8da471d947f2da8584e15 (diff) | |
lib: restructure stdx headers and rename to opt, relocate example
Move stdx.hpp into a stdx/ subdirectory and rename to opt.hpp, reflecting
its specific purpose. Rename stdx.cc to opt.cc accordingly.
Update includes in both the library and examples to reflect the new path.
Also move must_pass.cc and its CMake config into examples/must_pass/ for
better organization and consistency.
No functional changes made.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'lib/stdx')
| -rw-r--r-- | lib/stdx/opt.hpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/lib/stdx/opt.hpp b/lib/stdx/opt.hpp new file mode 100644 index 0000000..66ef4a5 --- /dev/null +++ b/lib/stdx/opt.hpp @@ -0,0 +1,110 @@ +/* + * File: stdx.hpp + * Author: Amlal El Mahrouss, + * Copyright 2023-2025, Amlal El Mahrouss all rights reserved. + */ + +#ifndef _STDX_HPP +#define _STDX_HPP + +#include <stdexcept> +#include <utility> + +namespace stdx +{ + enum class ret + { + okay, + err + }; + + struct opt final + { + explicit opt(const ret& ret) + : m_ret(ret) + { + } + + opt& expect(const char* input) + { + if (m_ret == ret::err) + { + throw std::runtime_error(input); + } + + return *this; + } + + private: + ret m_ret; + }; + + template <typename Teller, typename... Lst> + inline stdx::ret eval(Teller tell, Lst&&... arg) + { + return tell(std::forward<Lst>(arg)...) ? stdx::ret::okay : stdx::ret::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 ret eval_less_than(Lst&&... arg) + { + static traits::int_less_than_teller eq; + return eq(std::forward<Lst>(arg)...) ? ret::okay : ret::err; + } + + template <typename... Lst> + inline ret eval_eq(Lst&&... arg) + { + static traits::int_eq_teller less_than; + return less_than(std::forward<Lst>(arg)...) ? ret::okay : ret::err; + } + + template <typename... Lst> + inline ret eval_greater(Lst&&... arg) + { + static traits::int_greater_than_teller greater_than; + return greater_than(std::forward<Lst>(arg)...) ? ret::okay : ret::err; + } + +} /* namespace stdx */ + +#endif /* ifndef _STDX_HPP */ |
