<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&#39;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&lt;speedtf8, std::u8string&gt;, 
std::text::text&lt;speedtf8, std::vector&lt;char8_t&gt;&gt;, but it would fail instantiations of std::text::text&lt;speedtf8, std::deque&lt;char8_t&gt;&gt;:



</div><div><br></div><div>-------------------------<br>
<div>fast/include/fast/speedtf8.hpp<br></div>

-------------------------<br></div></div><br></div></div><div>#include &lt;span&gt;<br><br></div><div>struct speedtf8;<br></div><div><br></div><div>
<div>using encoded_t = span&lt;char8_t&gt;;<br></div>


<div>using decoded_t = span&lt;char32_t&gt;;<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&lt;encoded_t, decoded_t, speedtf8_state&gt;;<br></div>


<div>using encode_result_t = encode_result&lt;encoded_t, 
decoded_t, speedtf8_state&gt;;</div><div><br></div>

</div>


</div><div><br></div><div>struct fast_replacement_handler {</div>     decode_result_t operator()( const 
speedtf8&amp; encoding, decode_result res ) const noexcept;<br>


     encode_result_t operator()( 
const speedtf8&amp; 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 &lt;fast/speedtf8.hpp&gt;<br></div><div>
<br>// include &quot;bloated&quot; std header

</div>

#include &lt;text&gt; <br></div><br></div><div>// use &quot;bloated&quot; implementation, but only ever compile it once
<div><br></div><div>
decode_result_t

fast_replacement_error_handler::operator(

const 
speedtf8&amp; 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&amp; 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&amp; 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&amp; 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>