すべてのインクルード ステートメントを独自の内部ヘッダーに変更したい場合は、mystringstream.h
テンプレートの特殊化を使用してこれを実行できますが、多くの警告があるため、私はそれを行いません。
- 以前に含めたすべての場所で、このヘッダーを必ず使用する必要があります
sstream
。
- STL 実装がまだ特化されていてはなりません
basic_stringstream <char, char_traits<char>, allocator<char> >
- STL 実装、または含めるその他のヘッダーには、インスタンス化された stringstream がまだ含まれていてはなりません
そうは言っても、この単純なコードパッドの例ではうまくいきました。
// mystringstream.h
namespace std
{
// This class exists solely to "trick" the compiler into
// considering this allocator a new, different type
class newallocator : public allocator<char>
{
};
// template specialize std::stringstream to inherit from basic_stringstream
// using our newallocator in place of std::allocator<char>
template <>
class basic_stringstream<char, char_traits<char>, allocator<char> >
: public basic_stringstream <char, char_traits<char>, newallocator >
{
public:
basic_stringstream()
{
precision(16); // or whatever precision you like
}
};
}
このソリューションは、標準ライブラリを拡張するのではなく、基本的に動作を変更するため、個人的には好きではありません。