summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-14 02:18:46 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-12-14 02:18:46 +0100
commit2448ac2ef13d96e4ef3b7a9a15ef1cfdc2195831 (patch)
tree55a4ab28858813722f926dc3a21ffdf7795aced6
parent3b336edafad6fecbe41b9485d80cdd247ac70d0e (diff)
chore: `option.hpp` improvements, new examples in `examples`.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--examples/hash_crc32_example/example.cc2
-rw-r--r--examples/option_example/CMakeLists.txt15
-rw-r--r--examples/option_example/example.cc11
-rw-r--r--examples/smart_ptr_example/CMakeLists.txt15
-rw-r--r--examples/smart_ptr_example/example.cc10
-rw-r--r--include/ocl/option.hpp18
6 files changed, 61 insertions, 10 deletions
diff --git a/examples/hash_crc32_example/example.cc b/examples/hash_crc32_example/example.cc
index 258aedc..be6780f 100644
--- a/examples/hash_crc32_example/example.cc
+++ b/examples/hash_crc32_example/example.cc
@@ -1,6 +1,6 @@
#include <ocl/crc_hash.hpp>
#include <ocl/print.hpp>
-#include <ocl/smart_ptr.hpp>
+#include <ocl/option.hpp>
int main(int argc, char** argv)
{
diff --git a/examples/option_example/CMakeLists.txt b/examples/option_example/CMakeLists.txt
new file mode 100644
index 0000000..a77d4c5
--- /dev/null
+++ b/examples/option_example/CMakeLists.txt
@@ -0,0 +1,15 @@
+
+cmake_minimum_required(VERSION 3.15...3.31)
+
+project(
+ OptionExample
+ VERSION 1.0
+ LANGUAGES CXX)
+
+find_package(Boost REQUIRED COMPONENTS container)
+
+add_executable(OptionExample example.cc)
+
+set_property(TARGET OptionExample PROPERTY CXX_STANDARD 20)
+target_include_directories(OptionExample PUBLIC ../../include/)
+target_link_libraries(OptionExample PRIVATE Boost::container)
diff --git a/examples/option_example/example.cc b/examples/option_example/example.cc
new file mode 100644
index 0000000..7649438
--- /dev/null
+++ b/examples/option_example/example.cc
@@ -0,0 +1,11 @@
+#include <ocl/crc_hash.hpp>
+#include <ocl/print.hpp>
+#include <ocl/option.hpp>
+
+int main(int argc, char** argv)
+{
+ ocl::option opt{ocl::eval_eq(nullptr, nullptr)};
+ opt.expect("is incorrect");
+
+ return 0;
+}
diff --git a/examples/smart_ptr_example/CMakeLists.txt b/examples/smart_ptr_example/CMakeLists.txt
new file mode 100644
index 0000000..6584ad2
--- /dev/null
+++ b/examples/smart_ptr_example/CMakeLists.txt
@@ -0,0 +1,15 @@
+
+cmake_minimum_required(VERSION 3.15...3.31)
+
+project(
+ SmartPtrExample
+ VERSION 1.0
+ LANGUAGES CXX)
+
+find_package(Boost REQUIRED COMPONENTS container)
+
+add_executable(SmartPtrExample example.cc)
+
+set_property(TARGET SmartPtrExample PROPERTY CXX_STANDARD 20)
+target_include_directories(SmartPtrExample PUBLIC ../../include/)
+target_link_libraries(SmartPtrExample PRIVATE Boost::container)
diff --git a/examples/smart_ptr_example/example.cc b/examples/smart_ptr_example/example.cc
new file mode 100644
index 0000000..ef1a865
--- /dev/null
+++ b/examples/smart_ptr_example/example.cc
@@ -0,0 +1,10 @@
+#include <ocl/crc_hash.hpp>
+#include <ocl/print.hpp>
+#include <ocl/smart_ptr.hpp>
+
+int main(int argc, char** argv)
+{
+ ocl::shared_ptr<std::ostream> smart = ocl::delete_ptr(&std::cout);
+
+ return 0;
+}
diff --git a/include/ocl/option.hpp b/include/ocl/option.hpp
index c1bc5cc..d84e935 100644
--- a/include/ocl/option.hpp
+++ b/include/ocl/option.hpp
@@ -69,7 +69,8 @@ namespace ocl
{
struct int_eq_teller final
{
- bool operator()(int a, int b)
+ template <class ObjFirst, class ObjLast>
+ bool operator()(ObjFirst a, ObjLast b)
{
return (a == b);
}
@@ -77,7 +78,8 @@ namespace ocl
struct int_greater_than_teller final
{
- bool operator()(int a, int b)
+ template <class ObjFirst, class ObjLast>
+ bool operator()(ObjFirst a, ObjLast b)
{
return (a > b);
}
@@ -85,7 +87,8 @@ namespace ocl
struct int_less_than_teller final
{
- bool operator()(int a, int b)
+ template <class ObjFirst, class ObjLast>
+ bool operator()(ObjFirst a, ObjLast b)
{
return (a < b);
}
@@ -95,22 +98,19 @@ namespace ocl
template <typename... Lst>
inline return_type eval_less_than(Lst&&... arg)
{
- static detail::int_less_than_teller eq;
- return eq(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err;
+ return detail::int_less_than_teller{}(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err;
}
template <typename... Lst>
inline return_type eval_eq(Lst&&... arg)
{
- static detail::int_eq_teller less_than;
- return less_than(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err;
+ return detail::int_eq_teller{}(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err;
}
template <typename... Lst>
inline return_type eval_greater_than(Lst&&... arg)
{
- static detail::int_greater_than_teller greater_than;
- return greater_than(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err;
+ return detail::int_greater_than_teller{}(std::forward<Lst>(arg)...) ? return_type::okay : return_type::err;
}
inline return_type eval_true() noexcept