Skip to content

Commit 26e5e36

Browse files
committed
fix bool, add tests
1 parent 75c81ab commit 26e5e36

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

include/xsimd/arch/xsimd_scalar.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,9 +1208,15 @@ namespace xsimd
12081208
template <class T_out, class T_in>
12091209
XSIMD_INLINE constexpr T_out batch_cast(T_in const& val) noexcept
12101210
{
1211-
static_assert(std::is_same<T_in, bool>::value ^ std::is_same<T_in, bool>::value, "cannot convert to/from bool; use !x or x != 0");
1211+
static_assert(!std::is_same<T_out, bool>::value, "cannot convert to bool, use !x or x != 0");
12121212
return static_cast<T_out>(val);
12131213
}
1214+
1215+
template <class T>
1216+
XSIMD_INLINE constexpr bool batch_cast(bool b) noexcept
1217+
{
1218+
return b;
1219+
}
12141220
}
12151221

12161222
#endif

test/test_batch_cast.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ struct batch_cast_test
341341
T_out scalar_ref = static_cast<T_out>(in_test_value);
342342
T_out scalar_res = res.get(0);
343343
CHECK_SCALAR_EQ(scalar_ref, scalar_res);
344+
CHECK_SCALAR_EQ(scalar_ref, xsimd::batch_cast<T_out>(in_test_value));
344345
}
345346
}
346347

@@ -353,14 +354,22 @@ struct batch_cast_test
353354
using B_common_out = xsimd::batch_bool<T_out>;
354355

355356
B_common_in all_true_in(true);
356-
B_common_out all_true_res = xsimd::batch_bool_cast<T_out>(all_true_in);
357+
B_common_out all_true_res0 = xsimd::batch_bool_cast<T_out>(all_true_in);
358+
B_common_out all_true_res1 = xsimd::batch_cast<T_out>(all_true_in);
357359
INFO(name);
358-
CHECK_SCALAR_EQ(all_true_res.get(0), true);
360+
CHECK_SCALAR_EQ(all_true_res0.get(0), true);
361+
CHECK_SCALAR_EQ(all_true_res1.get(0), true);
362+
CHECK_SCALAR_EQ(xsimd::batch_bool_cast<B_out>(true), true);
363+
CHECK_SCALAR_EQ(xsimd::batch_cast<B_out>(true), true);
359364

360365
B_common_in all_false_in(false);
361-
B_common_out all_false_res = xsimd::batch_bool_cast<T_out>(all_false_in);
366+
B_common_out all_false_res0 = xsimd::batch_bool_cast<T_out>(all_false_in);
367+
B_common_out all_false_res1 = xsimd::batch_cast<T_out>(all_false_in);
362368
INFO(name);
363-
CHECK_SCALAR_EQ(all_false_res.get(0), false);
369+
CHECK_SCALAR_EQ(all_false_res0.get(0), false);
370+
CHECK_SCALAR_EQ(all_false_res1.get(0), false);
371+
CHECK_SCALAR_EQ(xsimd::batch_bool_cast<B_out>(false), false);
372+
CHECK_SCALAR_EQ(xsimd::batch_cast<B_out>(false), false);
364373
}
365374
};
366375

0 commit comments

Comments
 (0)