<div dir="ltr"><div><div><div><div><div>As a minor sidenote, for the sake of discussion (and because I am drinking too much coffee), you can make the Encoding Object approach compile fast by employing all the type-fixing to fit your needs. Using the below implementation:<br><br></div><div>Pros: compiles fast, works only with contiguous ranges/span-constructibles, non-constexpr, can be optimized<br></div><div>Cons: works only with contiguous ranges, no flexible error handler choice, depends on LTO for inlining optimizations<br><br></div><div>More work could be put into it to make different tradeoffs, but this would work under the proposal and implementation's current specification since it is based on the concept of what is supposed to be on an encoding object and its associated structures. You could get away with
std::text::text<speedtf8, std::u8string>,
std::text::text<speedtf8, std::vector<char8_t>>, but it would fail instantiations of std::text::text<speedtf8, std::deque<char8_t>>:
</div><div><br></div><div>-------------------------<br>
<div>fast/include/fast/speedtf8.hpp<br></div>
-------------------------<br></div></div><br></div></div><div>#include <span><br><br></div><div>struct speedtf8;<br></div><div><br></div><div>
<div>using encoded_t = span<char8_t>;<br></div>
<div>using decoded_t = span<char32_t>;<br></div>
<br>struct empty_struct {};<br></div><div><br></div><div>using speedtf8_state = empty_struct;<br>
<div><div>using decode_result_t =
decode_result<encoded_t, decoded_t, speedtf8_state>;<br></div>
<div>using encode_result_t = encode_result<encoded_t,
decoded_t, speedtf8_state>;</div><div><br></div>
</div>
</div><div><br></div><div>struct fast_replacement_handler {</div> decode_result_t operator()( const
speedtf8& encoding, decode_result res ) const noexcept;<br>
encode_result_t operator()(
const speedtf8& encoding, encode_result res
) const noexcept;<br>
};<br><div><br></div><div>using
speedtf8_error_handler_t
= fast_replacement_handler;<br><br></div><div>struct speedtf8 {<br></div> using state = empty_struct;<br></div>
using code_unit = char8_t;<br>
using code_point = char32_t;<br><div><div><br></div></div>
<div> static decode_result_t decode(encoded_t input, decoded_t output, state,
speedtf8_error_handler_t) noexcept;<br>
<div>
static
encode_result_t encode(encoded_t input, decoded_t output, state,
speedtf8_error_handler_t) noexcept;<br></div>
};</div><div><br></div><div>
<div><div>--------------------------<br></div>fast/source/utf8.cpp<br>--------------------------<br></div><div>
<div>#include <fast/speedtf8.hpp><br></div><div>
<br>// include "bloated" std header
</div>
#include <text> <br></div><br></div><div>// use "bloated" implementation, but only ever compile it once
<div><br></div><div>
decode_result_t
fast_replacement_error_handler::operator(
const
speedtf8& encoding, decode_result res
) const {</div><div> return std::text::replacement_error_handler{}(encoding, res);<br></div><div>}</div>
<div><br></div><div>
encode_result_t
fast_replacement_error_handler::operator(
const
speedtf8& encoding, encode_result_t res
) const {</div><div>
<div> return std::text::replacement_error_handler{}(encoding, res);<br></div>
</div><div>}</div>
</div><div><br></div><div>speedtf8::encoding_result_t speedtf8::encode( decoded_t input, encoded_t output, speedtf8_state& s,
speedtf8_error_handler_t
err_handler
) noexcept {<br>
<div>
<div> std::text::utf8::state real_s;<br></div>
return std::text::utf8{}.encode(input, output, real_s, err_handler);<br></div>
}<br><br></div><div>
speedtf8::decoding_result_t
speedtf8::decode( encoded_t input, decoded_t output, speedtf8_state& s,
speedtf8_error_handler_t
err_handler
) noexcept {<br></div><div> std::text::utf8::state real_s;<br></div><div> return
std::text::utf8{}.decode(input, output, real_s, err_handler);<br></div><div>}<br></div><div><br></div></div>