• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef MAPLE_UTIL_INCLUDE_UTILS_META_H
17 #define MAPLE_UTIL_INCLUDE_UTILS_META_H
18 #include <type_traits>
19 
20 namespace maple {
21 namespace utils {
22 template <typename T, typename U>
23 struct meta_and : public std::conditional_t<T::value, U, T> {
24 };
25 
26 template <typename T, typename U>
27 struct meta_or : public std::conditional_t<T::value, T, U> {
28 };
29 
30 template <typename T>
31 struct meta_not : public std::integral_constant<bool, !static_cast<bool>(T::value)>::type {
32 };
33 
34 template <typename...>
35 struct is_signed;
36 
37 template <typename T>
38 struct is_signed<T> : public std::is_signed<T>::type {
39 };
40 
41 template <typename T, typename U>
42 struct is_signed<T, U> : public meta_and<std::is_signed<T>, std::is_signed<U>>::type {
43 };
44 
45 template <typename... T>
46 constexpr bool is_signed_v = is_signed<T...>::value;
47 
48 template <typename...>
49 struct is_unsigned;
50 
51 template <typename T>
52 struct is_unsigned<T> : public std::is_unsigned<T>::type {
53 };
54 
55 template <typename T, typename U>
56 struct is_unsigned<T, U> : public meta_and<std::is_unsigned<T>, std::is_unsigned<U>>::type {
57 };
58 
59 template <typename... T>
60 constexpr bool is_unsigned_v = is_unsigned<T...>::value;
61 
62 template <typename T, typename U>
63 struct is_same_sign : public meta_or<is_signed<T, U>, is_unsigned<T, U>>::type {
64 };
65 
66 template <typename T, typename U>
67 struct is_diff_sign : public meta_not<is_same_sign<T, U>>::type {
68 };
69 
70 template <typename...>
71 struct is_pointer;
72 
73 template <typename T>
74 struct is_pointer<T> : public std::is_pointer<T>::type {
75 };
76 
77 template <typename T, typename U>
78 struct is_pointer<T, U> : public meta_and<is_pointer<T>, is_pointer<U>>::type {
79 };
80 
81 template <typename... T>
82 constexpr bool is_pointer_v = is_pointer<T...>::value;
83 
84 template <typename T, typename U>
85 struct const_of : public meta_and<std::is_const<U>, std::is_same<std::add_const_t<T>, U>>::type {
86 };
87 
88 template <typename T, typename U>
89 constexpr bool const_of_v = const_of<T, U>::value;
90 
91 template <typename T, typename U>
92 struct is_ncv_same : public std::is_same<std::remove_cv_t<T>, std::remove_cv_t<U>>::type {
93 };
94 
95 template <typename T, typename U>
96 constexpr bool is_ncv_same_v = is_ncv_same<T, U>::value;
97 
98 namespace ptr {
99 template <typename T, typename U, typename = std::enable_if_t<is_pointer_v<T, U>>>
100 struct const_of : public utils::const_of<std::remove_pointer_t<T>, std::remove_pointer_t<U>>::type {
101 };
102 
103 template <typename T, typename U, typename = std::enable_if_t<is_pointer_v<T, U>>>
104 constexpr bool const_of_v = const_of<T, U>::value;
105 
106 template <typename T, typename U, typename = std::enable_if_t<is_pointer_v<T, U>>>
107 struct is_ncv_same : public utils::is_ncv_same<std::remove_pointer_t<T>, std::remove_pointer_t<U>>::type {
108 };
109 
110 template <typename T, typename U, typename = std::enable_if_t<is_pointer_v<T, U>>>
111 constexpr bool is_ncv_same_v = is_ncv_same<T, U>::value;
112 }  // namespace ptr
113 }  // namespace utils
114 }  // namespace maple
115 #endif  // MAPLE_UTIL_INCLUDE_UTILS_META_H
116