From 185335e8efcac46e96e25e5a50e0d4b93152f983 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 21 Dec 2025 11:11:23 +0100 Subject: feat: New release of `OCL.Core`, standalone module. Signed-off-by: Amlal El Mahrouss --- example/option_example/example.cc | 14 +++++++++++--- example/simple_allocator_op/example.cc | 2 +- example/smart_ptr_example/example.cc | 1 + include/ocl/basic_hash.hpp | 23 +++++++++++++++++++++++ include/ocl/detail/config.hpp | 13 +++++++++++++ include/ocl/equiv.hpp | 13 ------------- include/ocl/is_same.hpp | 9 --------- include/ocl/option.hpp | 32 ++++++++++---------------------- include/ocl/print.hpp | 7 +++++++ include/ocl/tracked_ptr.hpp | 4 ++-- 10 files changed, 68 insertions(+), 50 deletions(-) create mode 100644 include/ocl/basic_hash.hpp delete mode 100644 include/ocl/is_same.hpp diff --git a/example/option_example/example.cc b/example/option_example/example.cc index e35f73b..c784dec 100644 --- a/example/option_example/example.cc +++ b/example/option_example/example.cc @@ -1,15 +1,23 @@ #include #include #include -// #include +struct invalid_callable { + explicit invalid_callable() = default; + void operator()(const char* reason) + { + ocl::detail::throw_runtime_error(BOOST_CURRENT_LOCATION.to_string()); + } +}; + +/// \brief Option Monad example int main(int argc, char** argv) { ocl::option opt{ocl::eval_eq(nullptr, nullptr)}; - opt.expect("is incorrect"); + opt.expect("option::incorrect"); ocl::option opt2{ocl::eval_eq(argv, nullptr)}; - opt2.expect("is incorrect"); + opt2.expect("option::incorrect"); return 0; } diff --git a/example/simple_allocator_op/example.cc b/example/simple_allocator_op/example.cc index 83be033..433da22 100644 --- a/example/simple_allocator_op/example.cc +++ b/example/simple_allocator_op/example.cc @@ -1,7 +1,7 @@ #include #include -/// @brief Basic Send test +/// \brief Allocation of ints example. int main() { ocl::allocator int_alloc; diff --git a/example/smart_ptr_example/example.cc b/example/smart_ptr_example/example.cc index a8293f2..e0f8555 100644 --- a/example/smart_ptr_example/example.cc +++ b/example/smart_ptr_example/example.cc @@ -2,6 +2,7 @@ #include #include +/// \brief Smart pointer example. auto main(int argc, char** argv) -> int { ocl::shared_ptr smart = ocl::delete_ptr(&std::cout); diff --git a/include/ocl/basic_hash.hpp b/include/ocl/basic_hash.hpp new file mode 100644 index 0000000..6a39df2 --- /dev/null +++ b/include/ocl/basic_hash.hpp @@ -0,0 +1,23 @@ +#ifndef __OCL_CORE_BASIC_HASH +#define __OCL_CORE_BASIC_HASH + +#include + +/// @brief OCL equivalence namespace. +namespace ocl +{ + template + struct basic_hash final + { + using result_type = typename T::result_type; + using type = T; + + // AMLALE: If it throws, we can't compute the hash correctly. + constexpr result_type hash() noexcept + { + return type{}.hash(); + } + }; +} + +#endif \ No newline at end of file diff --git a/include/ocl/detail/config.hpp b/include/ocl/detail/config.hpp index 2efc037..ae5735e 100644 --- a/include/ocl/detail/config.hpp +++ b/include/ocl/detail/config.hpp @@ -15,7 +15,9 @@ #include #include #include +#include #include +#include #endif #define OCL_DEPRECATED() [[deprecated]] @@ -51,4 +53,15 @@ #define OCL_HAS_PRAGMA_ONCE 1 #endif +namespace ocl +{ + namespace detail + { + inline void throw_runtime_error(const boost::string_view& loc = BOOST_CURRENT_LOCATION.to_string()) + { + throw std::runtime_error(loc.to_string()); + } + } +} + #endif \ No newline at end of file diff --git a/include/ocl/equiv.hpp b/include/ocl/equiv.hpp index ac6e2cd..f9031b1 100644 --- a/include/ocl/equiv.hpp +++ b/include/ocl/equiv.hpp @@ -13,19 +13,6 @@ /// @brief OCL equivalence namespace. namespace ocl { - template - struct basic_hash final - { - using result_type = typename T::result_type; - using type = T; - - // AMLALE: If it throws, we can't compute the hash correctly. - constexpr result_type hash() noexcept - { - return type{}.hash(); - } - }; - template struct is_real final { diff --git a/include/ocl/is_same.hpp b/include/ocl/is_same.hpp deleted file mode 100644 index 655ee4c..0000000 --- a/include/ocl/is_same.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#if __cplusplus < 202301L -#error "This header has been deprecated, it now redirects to equiv.hpp" -#else -#warning "This header has been deprecated, it now redirects to equiv.hpp" -#endif - -#include diff --git a/include/ocl/option.hpp b/include/ocl/option.hpp index 07cf194..93e01c7 100644 --- a/include/ocl/option.hpp +++ b/include/ocl/option.hpp @@ -8,7 +8,7 @@ #define __OCL_CORE_OPTION #include -#include +#include namespace ocl { @@ -24,9 +24,9 @@ namespace ocl { using option_error = std::runtime_error; - void throw_option_invalid_type_error() + inline void throw_option_invalid_type_error(const boost::string_view& loc = BOOST_CURRENT_LOCATION.to_string()) { - throw option_error("option has invalid type."); + throw option_error(loc.to_string()); } } // namespace detail @@ -52,21 +52,22 @@ namespace ocl if (ret_ == return_type::err) { - throw detail::option_error(input ? input : "option::error"); + io::println(input ? input : "option::error"); + detail::throw_option_invalid_type_error(); } return *this; } template - option& expect_or_handle(const char* input) + option& expect(const char* input) { assert(ret_ != return_type::invalid); if (ret_ == return_type::err) { // AMLALE: Shall it be a functor or container here? - Handleable(input ? input : "option::error"); + Handleable{}(input ? input : "option::error"); } return *this; @@ -81,19 +82,7 @@ namespace ocl // AMLALE: The operator() are marked as `noexcept` as failing conditions within an evaluation (say a overloads operator==) proves that the // predictate is wrong. Thus program state is undefined. - struct teller - { - teller() = default; - virtual ~teller() = default; - - template - bool operator()(ObjFirst a, ObjLast b) noexcept - { - return false; - } - }; - - struct eq_teller final : teller + struct eq_teller final { template bool operator()(ObjFirst a, ObjLast b) noexcept @@ -102,7 +91,7 @@ namespace ocl } }; - struct greater_than_teller final : teller + struct greater_than_teller final { template bool operator()(ObjFirst a, ObjLast b) noexcept @@ -111,7 +100,7 @@ namespace ocl } }; - struct less_than_teller final : teller + struct less_than_teller final { template bool operator()(ObjFirst a, ObjLast b) noexcept @@ -124,7 +113,6 @@ namespace ocl template inline return_type eval(const Teller& tell, Lst&&... arg) { - static_assert(std::is_base_of_v, "Teller is not evalueable."); return tell(std::forward(arg)...) ? return_type::okay : return_type::err; } diff --git a/include/ocl/print.hpp b/include/ocl/print.hpp index a667225..70b79dd 100644 --- a/include/ocl/print.hpp +++ b/include/ocl/print.hpp @@ -42,6 +42,13 @@ namespace ocl::io namespace detail { inline bool is_stdio_sync = true; + + using io_error = std::runtime_error; + + inline void throw_option_invalid_type_error(const boost::string_view& loc = BOOST_CURRENT_LOCATION.to_string()) + { + throw io_error(loc.to_string()); + } } inline void enable_stdio_sync(const bool& enable) noexcept diff --git a/include/ocl/tracked_ptr.hpp b/include/ocl/tracked_ptr.hpp index 8675a9d..c43276d 100644 --- a/include/ocl/tracked_ptr.hpp +++ b/include/ocl/tracked_ptr.hpp @@ -215,9 +215,9 @@ namespace ocl { using tracked_error = std::runtime_error; - inline void throw_tracked_error() + inline void throw_tracked_error(const boost::string_view& loc = BOOST_CURRENT_LOCATION.to_string()) { - throw tracked_error("tracked_error: memory leak detected."); + throw tracked_error(loc.to_string()); } } // namespace detail -- cgit v1.2.3