jsource
jsource copied to clipboard
Port conversions to c++
The main funtion doing the conversion work is convert<From, To>(). The external interface is unchanged (except B -> bool).
- Simple cases use just simple copy, with range check when
Frommay exceedTos value range. - Another overload takes additional trasformation function, if the function returns
std::optional<T>, astd::nulloptsignals failure and is checked - More complex cases use template specialisations
Also added template parameter to specify return type of pointer_to_values() (https://github.com/codereport/jsource/pull/200/commits/e9e7f414ff0a8d5e9416630cf642c0729c50c72a).
This changes the semantics of set_value_at() to depend on the type of the value:
T value;
set_value_at(arr, idx, value)
// was previously equivalent to
int64_t *values = (int64_t*)AV(arr);
values[idx] = value;
// is now equivalent to
T *values = (T*)AV(arr);
values[idx] = value;
This allows use of set_value_at() with types wider than, or not convertible to, int64_t.
However, this requires more care with the value parameter, it must be the correct type (correct bit width), to get the correct stride.
This is awesome! Will do a live code review on the next live stream!
CI compiler is giving somewhat ambiguous error:
../jsrc/conversions.cpp:565:71: error: call of overloaded ‘jtccvt(JST*&, <unnamed enum>, AD*&, AD**)’ is ambiguous
--
No idea how it thinks jtccvt() from all the functions would be overloaded...
Turned out the CI compiler had different idea of I compared to int64_t