xsimd icon indicating copy to clipboard operation
xsimd copied to clipboard

Add constructors from intializer lists and helpers

Open JohanMabille opened this issue 6 years ago • 2 comments

Batch constructor taking an initializer list should be available. Helpers allowing to build batches from initializer lists without knowing their real type should be implemented too.

JohanMabille avatar Mar 27 '18 13:03 JohanMabille

For the record, something similar (using boost.simd syntax) works just fine for my use case

  template<class P, size_t... Is>
  P iota(std::index_sequence<Is...>) {
    return {static_cast<typename P::value_type>(Is)...};
  }

  template<class P>
  P iota() {
    return iota<P>(std::make_index_sequence<P::static_size>());
  }

called as

iota<boost::simd::pack<T>>()

serge-sans-paille avatar Mar 27 '18 13:03 serge-sans-paille

Since you know the length at compile time, shouldn't you take an std::array<T, N> instead of an initializer_list? Seems to me that it would avoid brace initialization confusion with the constructor taking N scalars...

HadrienG2 avatar May 04 '18 21:05 HadrienG2

At some point we've been supporting initializer lists, but they turned out to be confusing for users. This got removed by 3ce1809f417703bc804de4fc1b3310c678b823d2 as an answer to #775.

Current supported constructor has the following signature:

template <class T, class A>
    template <class... Ts>
    inline batch<T, A>::batch(T val0, T val1, Ts... vals) noexcept

And it performs compile-time checking on the number of elements to make sure they match batch size.

serge-sans-paille avatar Oct 14 '22 08:10 serge-sans-paille