@@ -81,6 +81,45 @@ namespace xt
81
81
} \
82
82
}
83
83
84
+ // This functor avoids implicit conversions of small integral types to 'int'
85
+ // by returning the same type instead of 'auto'.
86
+ #define UNARY_BITWISE_OPERATOR_FUNCTOR (NAME, OP ) \
87
+ struct NAME \
88
+ { \
89
+ template <class A1 > \
90
+ constexpr std::decay_t <A1> operator ()(const A1& arg) const \
91
+ { \
92
+ return OP arg; \
93
+ } \
94
+ template <class B > \
95
+ constexpr auto simd_apply (const B& arg) const \
96
+ { \
97
+ return OP arg; \
98
+ } \
99
+ }
100
+
101
+ // This functor avoids implicit conversions of small integral types to 'int'
102
+ // by returning the largest type instead of 'auto'.
103
+ #define BINARY_BITWISE_OPERATOR_FUNCTOR (NAME, OP ) \
104
+ struct NAME \
105
+ { \
106
+ template <class T1 , class T2 > \
107
+ constexpr \
108
+ std::conditional_t <(sizeof (std::decay_t <T1>) > sizeof (std::decay_t <T2>)), \
109
+ std::decay_t <T1>, std::decay_t <T2>> \
110
+ operator ()(T1&& arg1, T2&& arg2) const \
111
+ { \
112
+ using xt::detail::operator OP; \
113
+ return (std::forward<T1>(arg1) OP std::forward<T2>(arg2)); \
114
+ } \
115
+ template <class B > \
116
+ constexpr auto simd_apply (const B& arg1, const B& arg2) const \
117
+ { \
118
+ return (arg1 OP arg2); \
119
+ } \
120
+ }
121
+
122
+
84
123
namespace detail
85
124
{
86
125
DEFINE_COMPLEX_OVERLOAD (+);
@@ -112,10 +151,10 @@ namespace xt
112
151
BINARY_OPERATOR_FUNCTOR (logical_or, ||);
113
152
BINARY_OPERATOR_FUNCTOR (logical_and, &&);
114
153
UNARY_OPERATOR_FUNCTOR (logical_not, !);
115
- BINARY_OPERATOR_FUNCTOR (bitwise_or, |);
116
- BINARY_OPERATOR_FUNCTOR (bitwise_and, &);
117
- BINARY_OPERATOR_FUNCTOR (bitwise_xor, ^);
118
- UNARY_OPERATOR_FUNCTOR (bitwise_not, ~);
154
+ BINARY_BITWISE_OPERATOR_FUNCTOR (bitwise_or, |);
155
+ BINARY_BITWISE_OPERATOR_FUNCTOR (bitwise_and, &);
156
+ BINARY_BITWISE_OPERATOR_FUNCTOR (bitwise_xor, ^);
157
+ UNARY_BITWISE_OPERATOR_FUNCTOR (bitwise_not, ~);
119
158
BINARY_OPERATOR_FUNCTOR (left_shift, <<);
120
159
BINARY_OPERATOR_FUNCTOR (right_shift, >>);
121
160
BINARY_OPERATOR_FUNCTOR (less, <);
0 commit comments