summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-03-25 09:33:38 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-03-25 09:33:38 +0100
commit944dafbf0ab104fabad8da471d947f2da8584e15 (patch)
treeeadfae789836ae2d3435aa6726179676f7152951 /lib
parente101c9a779a8df023973be161453994fe2aa6346 (diff)
feat(stdx.hpp): add forwardwing since we're taking by universal
reference here. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/stdx.cc1
-rw-r--r--lib/stdx.hpp185
2 files changed, 96 insertions, 90 deletions
diff --git a/lib/stdx.cc b/lib/stdx.cc
index dd6d4c6..a094f89 100644
--- a/lib/stdx.cc
+++ b/lib/stdx.cc
@@ -6,5 +6,4 @@
#include <stdx.hpp>
-
// EOF
diff --git a/lib/stdx.hpp b/lib/stdx.hpp
index 845bb67..25e4157 100644
--- a/lib/stdx.hpp
+++ b/lib/stdx.hpp
@@ -4,100 +4,107 @@
* Copyright 2023-2025, Amlal El Mahrouss all rights reserved.
*/
-#ifndef _STDX
-#define _STDX
+#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>
- stdx::ret eval(Teller tell, Lst&&... arg)
- {
- return tell(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);
- }
- };
- }
-
- template <typename... Lst>
- ret eval_less_than(Lst&&... arg)
- {
- static traits::int_less_than_teller eq;
- return eq(arg...) ? ret::okay : ret::err;
- }
-
- template <typename... Lst>
- ret eval_eq(Lst&&... arg)
- {
- static traits::int_eq_teller less_than;
- return less_than(arg...) ? ret::okay : ret::err;
- }
-
- template <typename... Lst>
- ret eval_greater(Lst&&... arg)
- {
- static traits::int_greater_than_teller greater_than;
- return greater_than(arg...) ? ret::okay : ret::err;
- }
+ 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>
+ 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>
+ 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>
+ 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>
+ 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 */
+#endif /* ifndef _STDX_HPP */