mame
mame copied to clipboard
Changed a number of parameters on calls in unicode.h to use references and not pointers
I'm torn on this. These functions are very "C-like", returning a length and producing output in the first parameter. Changing it to a reference makes it harder to accidentally index a pointer to a single value. But on the other hand, requiring the &
makes it clearer that the first parameter is used for output at the call site. Does anyone else have arguments for or against this?
If we were on C++17, I would be proposing these work this way:
auto [ch, len] = uchar_from_utf8(utf8_char, utf8_len)
Obviously a moot point
More auto
in places where the types are definitely known isn't a good thing. Also that breaks the aspect of it where it doesn't set the result variable if it doesn't consume input.
It would be nice if it could have an API like things in <algorithm>
, something like:
template <typename InputIt, typename OutputIt>
OutputIt utf8_to_uchar(InputIt first, InputIt last, OutputIt dest);
The trouble with trying to use an API like that is there's no way to say how much space you're providing for output (e.g. to restrict it to converting a single character), and there's no way to indicate how much of the input is consumed (because these functions stop on invalid input).
So, we are on C++17 now, is this still worth doing or should I just close it like everything else from 2017?