Skip to content

Commit 189175b

Browse files
Introduce make_iota_batch_constant() helper
Fix #1230
1 parent ae3822f commit 189175b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

include/xsimd/types/xsimd_batch_constant.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,29 @@ namespace xsimd
483483

484484
#endif
485485

486+
namespace generator
487+
{
488+
template <class T>
489+
struct iota
490+
{
491+
static constexpr T get(size_t index, size_t)
492+
{
493+
return static_cast<T>(index);
494+
}
495+
};
496+
}
497+
/**
498+
* @brief Build a @c batch_constant as an enumerated range
499+
*
500+
* @tparam T type of the data held in the batch.
501+
* @tparam A Architecture that will be used when converting to a regular batch.
502+
*/
503+
template <typename T, class A = default_arch>
504+
XSIMD_INLINE constexpr auto make_iota_batch_constant() noexcept
505+
{
506+
return make_batch_constant<T, generator::iota<T>, A>();
507+
}
508+
486509
} // namespace xsimd
487510

488511
#endif

test/test_batch_constant.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ struct constant_batch_test
8282
constexpr auto b = xsimd::make_batch_constant<value_type, arange, arch_type>();
8383
INFO("batch(value_type)");
8484
CHECK_BATCH_EQ((batch_type)b, expected);
85+
86+
constexpr auto b_p = xsimd::make_iota_batch_constant<value_type, arch_type>();
87+
INFO("batch(value_type)");
88+
CHECK_BATCH_EQ((batch_type)b_p, expected);
8589
}
8690

8791
template <value_type V>

0 commit comments

Comments
 (0)