Pregunta

In the libc++ header, <ios>, available to view here:

https://github.com/llvm-mirror/libcxx/blob/master/include/ios

there are two declarations of class ios_base, the "libcpp version" has a clear method, ios_base::clear() whilst the other does not. This is a public method and is not described here:

http://en.cppreference.com/w/cpp/io/ios_base

Further, in the implementation referenced above, basic_ios::clear() calls ios_base::clear() but it appears to not be defined anywhere. In libstdc++ it is implemented as can be seen here:

http://repo.or.cz/w/official-gcc.git/blob/HEAD:/libstdc%2B%2B-v3/include/bits/basic_ios.tcc

So my questions are:

1) why is there a public ios_base::clear() method in libc++?

2) where can I find how basic_ios::clear() is implemented in libc++?

¿Fue útil?

Solución

I guess you can blame me for this.

I've found that throwing an exception is something that is not small in code size. And so I like to outline functions that throw into sources when possible.

basic_ios::clear() must sometimes throw an exception, and is also a template class. If I correctly recall, this annoyed me, as the rdstate clearly does not depend upon the basic_ios template parameters: CharT, Traits. So I implemented rdstate down in the base class (ios_base), so that any associated non-inlined code could be shared by all instantiations of basic_ios.

As sty correctly pointed out, ios_base::clear() is implemented in src/ios.cpp. It is declared protected in ios_base, and then basic_ios::clear() is just an inline forwarding to this common implementation.

In a nutshell: The "why" is a code size optimization.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top