Generate a variable containing the iota sequence (i.e., 0, 1, 2, ... size-1) for the given simd::vec type. This can be used as the basis of generating other sequences, including those used in constexpr scenarios. For example, to generate all multiples of 3 you can do `iota<T> * 3'. Using the constexpr nature of iota, along with the constexpr operations and functions makes it natural to build simd::vec constants with particular properties. Perhaps even easier than using the generator constructor.
- Template Parameters
-
| _Tp | The vec or arithmetic type for which to generate the iota sequence |
- Returns
- A simd::vec or scalar value containing the iota sequence for the type */ template<typename _Tp> requires (vec_type<_Tp> || std::is_arithmetic_v<_Tp>) inline constexpr _Tp iota = []{ if constexpr (vec_type<_Tp>) return _Tp([](simd_size_type i) { return typename _Tp::value_type(i); }); else return _Tp{}; }();
namespace detail {
:TODO: Move into utilities. const auto perm_uninitResize = [](auto idx, auto isize) { return idx < isize ? idx : uninit_element; };
Provide a way to initialise the values in a vec_impl::vector from a generator. template<vec_type _Vp, typename _Gp> constexpr auto generate(_Gp generator) { if constexpr (complex_number<typename _Vp::value_type>) { using _Tp = typename _Vp::traits::element_type; return _Vp([=]<simd_size_type... _Idx>(std::integer_sequence<simd_size_type, _Idx...>) { return typename _Vp::traits::builtin_type{_Tp((_Idx % 2) ? generator(size_constant<_Idx / 2>()).imag() : generator(size_constant<_Idx / 2>()).real())...}; }(std::make_integer_sequence<simd_size_type, _Vp::size() * 2>())); } else { return _Vp([=]<simd_size_type... _Idx>(std::integer_sequence<simd_size_type, _Idx...>) { return typename _Vp::traits::builtin_type{std::bit_cast<typename _Vp::traits::element_type>( generator(size_constant<_Idx>{}))...}; }(std::make_integer_sequence<simd_size_type, _Vp::size()>())); } }
template<simd_size_type _NewSize, vec_or_mask_type _Vp> constexpr resize_t<_NewSize, _Vp> fit_to_size(const _Vp& v) { if constexpr (_NewSize == _Vp::size()) return v; else return permute<_NewSize>(v, [](simd_size_type i) { return (i < _Vp::size()) ? i : zero_element; }); }
template<vec_type _Vp, contiguous_sized_range _Range, typename _Flags> constexpr void mandates_for_store(const _Vp&, const _Range&, _Flags f) { using _Tp = typename _Vp::value_type; using _Rp = std::ranges::range_value_t<_Range>;
static_assert(detail::contains_flag<detail::flag_convert>(f) || !detail::needs_explicit_conversion<_Tp, _Rp>, "Store or scatter conversion requires flag_convert"); }
template<vec_type _Vp, contiguous_sized_range _Range, typename _Flags> constexpr void mandates_for_load(const _Range&, const _Vp&, _Flags f) { using _Tp = typename _Vp::value_type; using _Rp = std::ranges::range_value_t<_Range>;
static_assert(detail::vectorizable<_Rp>); static_assert(detail::explicitly_convertible_to<_Rp, _Tp>); static_assert(std::same_as<std::remove_cvref_t<_Vp>, _Vp>);
flag_convert is required if and only if the equivalent simd converting constructor would be explicit. static_assert(detail::contains_flag<detail::flag_convert>(f) || !detail::needs_explicit_conversion<_Rp, _Tp>, "Load or gather conversion requires flag_convert"); }
/** Convert a vec_type into the appropriate container type. Each element is the same size as the original and the number of elements is the same. The return value is bitwise equivalent to the original, but with a new type. This function is useful for converting a simd of a specific element type into a generic simd container which can be manipulated as a bucket-of-bits. It can also be used to convert a mask into a suitable container, allowing generic permute-like operations to work on masks too.