Skip to content

Commit 09dc820

Browse files
committed
Change AssignConversionProxy to also accept rvalues
1 parent 212efee commit 09dc820

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

include/kernel_float/conversion.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ KERNEL_FLOAT_INLINE vector<R, extent<N>> convert(const V& input, extent<N> new_s
8787
template<typename T, RoundingMode M = RoundingMode::ANY>
8888
struct AssignConversionProxy {
8989
KERNEL_FLOAT_INLINE
90-
explicit AssignConversionProxy(T* ptr) : ptr_(ptr) {}
90+
explicit AssignConversionProxy(T&& ptr) : ptr_(std::forward<T>(ptr)) {}
9191

9292
template<typename U>
9393
KERNEL_FLOAT_INLINE AssignConversionProxy& operator=(U&& values) {
94-
*ptr_ = detail::convert_impl<
94+
ptr_ = detail::convert_impl<
9595
vector_value_type<U>,
9696
vector_extent_type<U>,
9797
vector_value_type<T>,
@@ -102,12 +102,12 @@ struct AssignConversionProxy {
102102
}
103103

104104
private:
105-
T* ptr_;
105+
T ptr_;
106106
};
107107

108108
/**
109109
* Takes a vector reference and gives back a helper object. This object allows you to assign
110-
* a vector of a different type to another vector while perofrming implicit type converion.
110+
* a vector of a different type to another vector while performing implicit type conversion.
111111
*
112112
* For example, if `x = expression;` does not compile because `x` and `expression` are
113113
* different vector types, you can use `cast_to(x) = expression;` to make it work.
@@ -120,9 +120,9 @@ struct AssignConversionProxy {
120120
* cast_to(x) = y; // Normally, `x = y;` would give an error, but `cast_to` fixes that.
121121
* ```
122122
*/
123-
template<typename T, RoundingMode M = RoundingMode::ANY>
124-
KERNEL_FLOAT_INLINE AssignConversionProxy<T, M> cast_to(T& input) {
125-
return AssignConversionProxy<T, M>(&input);
123+
template<RoundingMode M = RoundingMode::ANY, typename T>
124+
KERNEL_FLOAT_INLINE AssignConversionProxy<T, M> cast_to(T&& input) {
125+
return AssignConversionProxy<T, M>(std::forward<T>(input));
126126
}
127127

128128
/**
@@ -135,7 +135,7 @@ KERNEL_FLOAT_INLINE AssignConversionProxy<T, M> cast_to(T& input) {
135135
* ```
136136
*/
137137
template<size_t N, typename T>
138-
KERNEL_FLOAT_INLINE vector<T, extent<N>> fill(T value = {}, extent<N> = {}) {
138+
KERNEL_FLOAT_INLINE vector<T, extent<N>> fill(T value, extent<N> = {}) {
139139
vector_storage<T, 1> input = {value};
140140
return detail::broadcast_impl<T, extent<1>, extent<N>>::call(input);
141141
}

0 commit comments

Comments
 (0)