Style Question
I have a stylistic question.
I have an application where I need a queue of buffers whose size changes
relatively often. I was doing it with a "char *" with separate Size and
MaxSize members, but it seemed like a great candidate for a
std::vector<char>. After the size changes, I fill it immediately, so the
zero filling that vector::resize does is useless to me, and it costs a
fair amount.
So, I derived a class from std::vector<char>, and overrode resize, using
knowledge of the VC++ STL implementation:
class ByteVector
: public std::vector<char>
{
...
void resize( size_t newSize, char init = -1 )
{
if( (init == -1) && (_Myfirst + newSize <= _Myend) )
_Mylast = _Myfirst + newSize;
else
std::vector<char>::resize( newSize, init );
}
};
This solves my problem neatly, but is this considered very bad form? It's
certainly true that this won't work with another STL implementation. Would
you fire a programmer that did this to you?
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.