jsource icon indicating copy to clipboard operation
jsource copied to clipboard

Port conversions to c++

Open juntuu opened this issue 4 years ago • 2 comments

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 From may exceed Tos value range.
  • Another overload takes additional trasformation function, if the function returns std::optional<T>, a std::nullopt signals 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.

juntuu avatar Mar 07 '21 00:03 juntuu

This is awesome! Will do a live code review on the next live stream!

codereport avatar Mar 09 '21 04:03 codereport

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

juntuu avatar Mar 17 '21 01:03 juntuu