Skip to content

Commit 98c4a59

Browse files
committed
Add make_batch_constant from std::array in C++20
1 parent f2b9203 commit 98c4a59

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

include/xsimd/types/xsimd_batch_constant.hpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,15 @@ namespace xsimd
408408
return {};
409409
}
410410

411+
#if __cplusplus >= 202002L
412+
template <std::array Arr, class A, std::size_t... Is>
413+
XSIMD_INLINE constexpr batch_constant<typename decltype(Arr)::value_type, A, Arr[Is]...>
414+
make_batch_constant(std::index_sequence<Is...>) noexcept
415+
{
416+
return {};
417+
}
418+
#endif
419+
411420
template <typename T, class G, class A, std::size_t... Is>
412421
XSIMD_INLINE constexpr batch_bool_constant<T, A, G::get(Is, sizeof...(Is))...>
413422
make_batch_bool_constant(std::index_sequence<Is...>) noexcept
@@ -422,6 +431,15 @@ namespace xsimd
422431
return {};
423432
}
424433

434+
#if __cplusplus >= 202002L
435+
template <typename T, std::array Arr, class A, std::size_t... Is>
436+
XSIMD_INLINE constexpr batch_bool_constant<T, A, Arr[Is]...>
437+
make_batch_bool_constant(std::index_sequence<Is...>) noexcept
438+
{
439+
return {};
440+
}
441+
#endif
442+
425443
} // namespace detail
426444

427445
/**
@@ -479,6 +497,21 @@ namespace xsimd
479497
return {};
480498
}
481499

500+
#if __cplusplus >= 202002L
501+
/**
502+
* @brief Build a @c batch_constant from a std::array (C++20)
503+
*
504+
* @tparam Arr The std::array containing the values (non type template argument).
505+
* @tparam A Architecture that will be used when converting to a regular batch.
506+
*/
507+
template <std::array Arr, class A = default_arch>
508+
requires(Arr.size() == batch<typename decltype(Arr)::value_type, A>::size)
509+
XSIMD_INLINE constexpr auto make_batch_constant() noexcept
510+
{
511+
return detail::make_batch_constant<Arr, A>(std::make_index_sequence<Arr.size()>());
512+
}
513+
#endif
514+
482515
/*
483516
* @brief Build a @c batch_bool_constant with a single repeated value.
484517
*
@@ -491,6 +524,23 @@ namespace xsimd
491524
return {};
492525
}
493526

527+
#if __cplusplus >= 202002L
528+
/**
529+
* @brief Build a @c batch_constant from a std::array of boolean (C++20)
530+
*
531+
* @tparam Arr The std::array containing the boolean values (non type template argument).
532+
* @tparam A Architecture that will be used when converting to a regular batch.
533+
*/
534+
template <typename T, std::array Arr, class A = default_arch>
535+
requires(
536+
(Arr.size() == batch_bool<T, A>::size)
537+
&& std::is_same_v<typename decltype(Arr)::value_type, bool>)
538+
XSIMD_INLINE constexpr auto make_batch_bool_constant() noexcept
539+
{
540+
return detail::make_batch_bool_constant<T, Arr, A>(std::make_index_sequence<Arr.size()>());
541+
}
542+
#endif
543+
494544
#endif
495545

496546
namespace generator

0 commit comments

Comments
 (0)