From 65a8349aa5526d071b18cd4d42586c46faaa3823 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 24 Nov 2025 02:13:48 +0100 Subject: feat! breaking changes for OCL v1.0.48. Signed-off-by: Amlal El Mahrouss --- include/ocl/logic/equiv.hpp | 104 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 include/ocl/logic/equiv.hpp (limited to 'include/ocl/logic/equiv.hpp') diff --git a/include/ocl/logic/equiv.hpp b/include/ocl/logic/equiv.hpp new file mode 100644 index 0000000..1bdb6d9 --- /dev/null +++ b/include/ocl/logic/equiv.hpp @@ -0,0 +1,104 @@ +/* + * File: equiv.hpp + * Purpose: Equivalence header. + * Author: Amlal El Mahrouss (amlal@nekernel.org) + * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License. + */ + +#pragma once + +/// @brief OCL equivalence namespace. +namespace ocl::equiv +{ + template + struct basic_hash_trait + { + /// @brief hash from T's result_type. + static typename T::result_type hash() + { + static T val; + return val.hash(); + } + }; + + template + struct is_same + { + static constexpr bool value = false; + + /// @brief check if hash matches what we expect. + constexpr bool operator()() noexcept + { + return T::hash() == U::hash(); + } + }; + + template + struct is_same + { + static constexpr bool value = true; + }; + + template + struct is_not_same + { + static constexpr bool value = true; + + constexpr bool operator()() noexcept + { + return T::hash() != U::hash(); + } + }; + + template + struct is_not_same + { + static constexpr bool value = false; + }; + + template + struct equiv_is_int8 + { + private: + T left_ = 127, right_ = 127; + + public: + using result_type = T; + + constexpr result_type hash() + { + return (left_ + right_) < 1; + } + }; + + template + struct equiv_not_int8 + { + private: + // these shall overflow if not int8. + T left_ = 127, right_ = 127; + + public: + using result_type = T; + + constexpr result_type hash() + { + return (left_ + right_) > 0; + } + }; + + template + struct equiv_is_real + { + private: + T left_ = 5, right_ = 3; + + public: + using result_type = T; + + constexpr result_type hash() + { + return left_ / right_ == 1; + } + }; +} // namespace ocl::equiv -- cgit v1.2.3