summaryrefslogtreecommitdiffhomepage
path: root/include/ocl/is_same.hpp
blob: 2ad6db5f36d7d884df12a74ea2be91727d7e67b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * 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.
 */

#ifndef __OCL_CORE_IS_SAME
#define __OCL_CORE_IS_SAME

#include <ocl/detail/config.hpp>

/// @brief OCL equivalence namespace.
namespace ocl
{
	template <typename T>
	struct basic_hash final
	{
		using result_type = typename T::result_type;
		using type		  = T;

		/// @brief hash from T's result_type.
		static result_type hash()
		{
			return T{}.hash();
		}
	};

	template <typename T, typename U>
	struct is_same
	{
        using left_type = T;
        using right_type = T;

		static constexpr bool value = false;
	};

	template <typename T>
	struct is_same<T, T>
	{
		static constexpr bool value = true;
	};

	template <typename T, typename U>
	struct is_not_same
	{
        using left_type = T;
        using right_type = T;

		static constexpr bool value = true;
	};

	template <typename T>
	struct is_not_same<T, T>
	{
		static constexpr bool value = false;
	};

	template <typename T>
	struct equiv_is_int8 final
	{
	private:
		T left_ = 127, right_ = 127;

	public:
		using result_type = bool;

		constexpr result_type hash()
		{
			return (left_ + right_) < 1;
		}
	};

	template <typename T>
	struct equiv_not_int8 final
	{
	private:
		// these shall overflow if not int8.
		T left_ = 127, right_ = 127;

	public:
		using result_type = bool;

		constexpr result_type hash()
		{
			return (left_ + right_) > 0;
		}
	};

	template <typename T>
	struct equiv_is_real final
	{
	private:
		T left_ = 5, right_ = 3;

	public:
		using result_type = bool;

		constexpr result_type hash()
		{
			return (left_ / right_) == 1;
		}
	};

	template <typename T>
	struct equiv_is final
	{
	private:
		T left_{}, right_{};

	public:
		using result_type = bool;
        using type = T;

		constexpr result_type hash()
		{
			return (left_ == right_);
		}
	};
} // namespace ocl

#endif