summaryrefslogtreecommitdiffhomepage
path: root/include/ocl/core/is_same.hpp
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-11-30 00:42:50 -0500
committerAmlal El Mahrouss <amlal@nekernel.org>2025-11-30 00:42:50 -0500
commite6579534e7c64be652ffeb74be7c977564a3ddab (patch)
tree69b908f5b2d81f477d3cfe39ecc6c01fbdc89657 /include/ocl/core/is_same.hpp
parenta8e99f3a783069cf85b626c6cfb2fbe83ae4fd44 (diff)
chore & feat: final library changes to stabilize changes.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'include/ocl/core/is_same.hpp')
-rw-r--r--include/ocl/core/is_same.hpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/include/ocl/core/is_same.hpp b/include/ocl/core/is_same.hpp
new file mode 100644
index 0000000..e6f42c4
--- /dev/null
+++ b/include/ocl/core/is_same.hpp
@@ -0,0 +1,106 @@
+/*
+ * File: is_same.hpp
+ * Purpose: Equivalence header.
+ * Author: Amlal El Mahrouss (amlal@nekernel.org)
+ * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License.
+ */
+
+#pragma once
+
+#include <core/config.hpp>
+
+/// @brief OCL equivalence namespace.
+namespace ocl::is_same
+{
+ template <typename T>
+ struct basic_hash
+ {
+ /// @brief hash from T's result_type.
+ static typename T::result_type hash()
+ {
+ static T val;
+ return val.hash();
+ }
+ };
+
+ template <typename T, typename U>
+ 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 <typename T>
+ struct is_same<T, T>
+ {
+ static constexpr bool value = true;
+ };
+
+ template <typename T, typename U>
+ struct is_not_same
+ {
+ static constexpr bool value = true;
+
+ constexpr bool operator()() noexcept
+ {
+ return T::hash() != U::hash();
+ }
+ };
+
+ template <typename T>
+ struct is_not_same<T, T>
+ {
+ static constexpr bool value = false;
+ };
+
+ template <typename T>
+ struct equiv_is_int8
+ {
+ private:
+ T left_ = 127, right_ = 127;
+
+ public:
+ using result_type = T;
+
+ constexpr result_type hash()
+ {
+ return (left_ + right_) < 1;
+ }
+ };
+
+ template <typename T>
+ 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 <typename T>
+ 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::is_same