I'm working on an extended string class (derived from STL string). What features do you think it should support?
Printable View
I'm working on an extended string class (derived from STL string). What features do you think it should support?
I don't think you can derive from it (no virtual destructor).
You'd have to implement it as an adapter.
hmmmm... true, that's what I don't like about the standard library...
What's an adapter?
It's like that for efficiency reasons (similar to a final Java class), and you wouldn't normally want to derive from the standard containers.
An adapter extends or alters the functionality by compositing an object inside another. Take a look at the source to stack<>, I think that internally uses deque<> to handle the allocation.
I see.
But since my own destructor does nothing (~WString(){}), does it matter?
WString& destructed -> ~WString() called -> ~tstring called
tstring& destructed -> ~tstring called
Since ~WString does nothing, do I loose anything? Or does the destructor do some secret things I don't know about?
Oh, tstring is defined like this:
#ifdef UNICODE
typedef wchar_t tchar_t;
#else
typedef char tchar_t;
#endif
typedef basic_string<tchar_t> tstring;
I think final Java classes exist mainly for security reasons - so that no one can derive a class and manipulate behaviour.
Whether a particular implementation does anything "secret" in its destructor is up to the implementer, and you can't rely on it.
I don't know completely what the standard says about the string class, but I definitely know you can't derive from the standard containers.
What sort of functionality were you thinking of adding?
Functions that do nice things. Search, Strip, Trim, all those things. Maybe RegExp capability.
Well, it's already got find, but trim is a good one to have.
For regexps, see those boost classes :D www.boost.org