mattkretz / std-simd-feedback

Feedback from simd in the Parallelism TS 2
0 stars 0 forks source link

Reinstate simd_cast but implement using rebind #34

Open danieltowner opened 1 year ago

danieltowner commented 1 year ago

Real-world use of rebind_simd_t suggests that simd_cast is a concise and readable way of indiciating what you mean, while rebind_simd_t is a bit verbose.

mattkretz commented 1 year ago

I'd like to see a paper to SG6 proposing a general value_type / representation type cast.

mattkretz commented 1 year ago

@mpusz FYI. I guess such a cast would be interesting for mp-units as well. It would be equivalent to your quantity_cast overload for casting the representation type.

mpusz commented 1 year ago

Yes, we call it a representation_cast in mp-units V2 framework for now but value_cast is also a good name. However, in our case it will cast not only an underlying representation type but also will be used to change the unit as such conversion may also change/truncate the value. To make it even more entertaining, Unit is provided by value (NTTP) and representation type as a type parameter kind.

For example:

auto s1 = representation_cast<int>(speed);
auto s2 = representation_cast<km / h>(speed);
mattkretz commented 1 year ago

Assuming WG21 adds a std::value_cast with a specific goal to allow UDTs to reuse it. Then there would be some mechanism to call a function defined by mp-units that implements the cast.

I wrote a quick prototype: https://godbolt.org/z/M6e5q9ao7.

Who wants to run with it and write a paper? :wink: