@@ -223,6 +223,47 @@ KERNEL_FLOAT_INLINE void storen(const V& values, T* ptr, ptrdiff_t offset, ptrdi
223223#define KERNEL_FLOAT_ASSUME_ALIGNED (ptr, alignment ) (ptr)
224224#endif
225225
226+ template <typename T, size_t N>
227+ struct AssignConversionProxy {
228+ KERNEL_FLOAT_INLINE
229+ explicit AssignConversionProxy (T* ptr) : ptr_(ptr) {}
230+
231+ template <typename U>
232+ KERNEL_FLOAT_INLINE AssignConversionProxy& operator =(U&& values) {
233+ auto indices = range<ptrdiff_t , N>();
234+ detail::store_impl<T, N>::call (
235+ ptr_,
236+ convert_storage<T, N>(std::forward<U>(values)).data (),
237+ indices.data ());
238+
239+ return *this ;
240+ }
241+
242+ private:
243+ T* ptr_;
244+ };
245+
246+ /* *
247+ * Takes a reference to a vector and returns a special proxy object that automatically performs the correct conversion
248+ * when a vector of a different element type is assigned. This is useful to perform implicit type conversions.
249+ *
250+ * For example, let assume that a line like `x = expression;` would not compile since `x` and `expressions` are
251+ * vectors of different element types. Then it is possible to use `cast_to(x) = expression;` to fix this error,
252+ * which possibly introduces a type conversion.
253+ *
254+ * Example
255+ * =======
256+ * ```
257+ * vec<float, 2> x;
258+ * vec<double, 2> y = {1.0, 2.0};
259+ * cast_to(x) = y; // normally, the line `x = y;` would not compile, but `cast_to` make this possible
260+ * ```
261+ */
262+ template <typename T, typename E>
263+ KERNEL_FLOAT_INLINE AssignConversionProxy<T, E::value> cast_to (vector<T, E>& input) {
264+ return AssignConversionProxy<T, E::value>(input.data ());
265+ }
266+
226267/* *
227268 * Represents a pointer of type ``T*`` that is guaranteed to be aligned to ``alignment`` bytes.
228269 */
0 commit comments