diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-21 11:11:23 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-21 11:11:23 +0100 |
| commit | 185335e8efcac46e96e25e5a50e0d4b93152f983 (patch) | |
| tree | 8b5f824d4913aa7a3d3e70df0aaa6c0980b81122 | |
| parent | 646d97f28c2891d634e3066535524fa28e297045 (diff) | |
feat: New release of `OCL.Core`, standalone module.v3.0
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
| -rw-r--r-- | example/option_example/example.cc | 14 | ||||
| -rw-r--r-- | example/simple_allocator_op/example.cc | 2 | ||||
| -rw-r--r-- | example/smart_ptr_example/example.cc | 1 | ||||
| -rw-r--r-- | include/ocl/basic_hash.hpp | 23 | ||||
| -rw-r--r-- | include/ocl/detail/config.hpp | 13 | ||||
| -rw-r--r-- | include/ocl/equiv.hpp | 13 | ||||
| -rw-r--r-- | include/ocl/is_same.hpp | 9 | ||||
| -rw-r--r-- | include/ocl/option.hpp | 32 | ||||
| -rw-r--r-- | include/ocl/print.hpp | 7 | ||||
| -rw-r--r-- | include/ocl/tracked_ptr.hpp | 4 |
10 files changed, 68 insertions, 50 deletions
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 <ocl/crc_hash.hpp> #include <ocl/print.hpp> #include <ocl/option.hpp> -// #include <ocl/is_same.hpp> +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<invalid_callable>("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 <ocl/print.hpp> #include <ocl/allocator_op.hpp> -/// @brief Basic Send test +/// \brief Allocation of ints example. int main() { ocl::allocator<int> 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 <ocl/print.hpp> #include <ocl/smart_ptr.hpp> +/// \brief Smart pointer example. auto main(int argc, char** argv) -> int { ocl::shared_ptr<std::ostream> 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 <ocl/detail/config.hpp> + +/// @brief OCL equivalence namespace. +namespace ocl +{ + template <class T> + 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 <boost/core/demangle.hpp> #include <boost/core/null_deleter.hpp> #include <boost/container/allocator.hpp> +#include <boost/assert/source_location.hpp> #include <boost/assert.hpp> +#include <boost/utility/string_view.hpp> #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 <class T> - 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 <typename T> 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 <ocl/equiv.hpp> 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 <ocl/detail/config.hpp> -#include <utility> +#include <ocl/print.hpp> 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 <typename Handleable> - 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 <class ObjFirst, class ObjLast> - bool operator()(ObjFirst a, ObjLast b) noexcept - { - return false; - } - }; - - struct eq_teller final : teller + struct eq_teller final { template <class ObjFirst, class ObjLast> 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 <class ObjFirst, class ObjLast> 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 <class ObjFirst, class ObjLast> bool operator()(ObjFirst a, ObjLast b) noexcept @@ -124,7 +113,6 @@ namespace ocl template <typename Teller, typename... Lst> inline return_type eval(const Teller& tell, Lst&&... arg) { - static_assert(std::is_base_of_v<detail::teller, Teller>, "Teller is not evalueable."); return tell(std::forward<Lst>(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 |
