On 1/10/2016 8:37 AM, Alf P. Steinbach wrote:
> auto overflow( In_<int_type> char_code = traits_type::eof() )
> -> int_type override
> {
> const Ptr_<const Char> p_after = pptr();
> if( p_after != nullptr )
> {
> const Ptr_<const Char> p_first = pbase();
> if( p_after > p_first )
> {
> String s( p_first, p_after );
> if( char_code != traits_type::eof() ) { s << Char(
> char_code ); }
> console::write( s );
> goto finished;
> }
> }
> if( char_code != traits_type::eof() ) { console::write_char(
> char_code ); }
>
> finished:
> init_put_area_pointers();
> // return (success? traits_type::not_eof( char_code ) :
> traits_type::eof());
> return traits_type::not_eof( char_code );
> }
>
Well OK what else does one have to do on a Sunday's morning than posting
to clc++? By guaranteeing a buffer to write to, the above code was
simplified enough that the “goto” disappeared. This makes the code
slightly less general, but there's not much point in writing potentially
reusable code without some actual reuse visible ahead, so:
auto overflow( In_<int_type> char_code = traits_type::eof() )
-> int_type override
{
const Ptr_<const Char> p_after = pptr();
const Ptr_<const Char> p_first = pbase();
if( p_after > p_first )
{
String s( p_first, p_after );
if( char_code != traits_type::eof() ) { s << Char(
char_code ); }
console::write( s );
}
else if( char_code != traits_type::eof() )
{
console::write_char( char_code );
}
set_put_area_pointers();
// return (success? traits_type::not_eof( char_code ) :
traits_type::eof());
return traits_type::not_eof( char_code );
}
If anyone should wonder, this is an override in a class derived from
std::basic_streambuf<Char>.
The interface is dirty, the naming of things is ungrokable, and
different standard library implementations seem to have different
opinions about how it should work...
Cheers,
- Alf