そのため、パフォーマンスに敏感なアプリケーションでこれが必要になるケースがたくさんあり、私はついにラクダを壊した藁にいます。プラットフォームの少なくとも1つはC++98準拠のみを保証するため、C++98でコンパイルする必要があります。
うまくいけば、私が欲しいものをもう少し明確にするために編集しました。
例:
// This will allocate storage for 1024, and then loop 1024 times touching all of it just to place a 0 in it
std::vector< char > buffer( 1024 );
// Now read will write into that buffer, overwriting the 0s ( we payed for the fill unnecessarily )
buffer.resize( read( someSource, &buffer[0], buffer.size() ) );
これは一般的なCインターフェイスであり、バッファにデータを書き込むためにほぼすべてのCライブラリで使用されます。一般にプリミティブを含むバッファを扱う場合にも同じ問題が発生します。新しいサイズ変更は、代わりに次のようになります。
// Disabled for anything which doesn't pass boost::is_POD< T >, they get the standard version
void resize( size_t a_NewSize )
{
reserve( a_NewSize );
_end = _begin + a_NewSize;
}
construct_backは転送コンストラクターになり、1つのconst引数の場合、次のようになります(テストされていません):
template< typename T1 >
void construct_back( const T1& a_Arg1 )
{
if( capacity() <= size() ) // No room
reserve( size() + 1 );
// Construct in place using Ts constructor that accepts const T1&
new (&(*end()) T( T1 );
++_end; // Account for new element
}
construct_backには、可能なすべての数の引数^ 2オーバーロードが必要です。これは、C++98で完全に転送するための一般的なブルートフォースアプローチです。