C++: Alternative to STL and Boost?
STL and Boost are as object-oriented as you can get.
For all theoretical purposes, member function and a free function overloaded on the first argument are the same thing. They behave very similarly in practice, including for inheritance, so in C++ you should really consider free functions taking (possibly const) reference as first arguments to be methods of their first argument.
Advantage of free functions is they can be defined for existing class allowing you to add an interface to existing class. Which is why STL and especially boost uses them so much. Main advantage of member functions is they can be virtual (but virtual methods should be private anyway!)
You don't want to extend collections by derivation. Generally, you don't want to extend anything by derivation unless it is an abstract base class specifically designed for it. See this question about advantages of composition over inheritance.
Many (most!) older libraries for C++ used containers that bore a much closer resemblance to those used in such things as Java and C#.
A few example of such libraries include COOL, ET++, the NIH Class Library, and Rogue Wave Tools.h++.
Two points:
- At most, these are a source if inspiration. I'm pretty sure it's been at least 10 years (and often more like 20) since any of them has been updated. There's virtually no chance that any of them will even compile with any reasonably current compiler.
- I want to go on record as pointing out that I'm providing links to these only in answer to a very specific question. I most assuredly do not recommend that you use any of the above code, nor do I recommend that you even use them as inspiration.
To be sure I'm clear here, at least IMO:
- The allegations in your question are utterly false.
- What you're trying to do is completely insane!
- You're wasting your time.
- Writing code this way is a really, really bad idea. Just say no!
- If you insist on doing this, you will become a pariah.
- Even non-programmers who don't quite understand why, will begin to hate you intensely.
- Your dog will use your shoes and bed as his toilet.
You're on your own. You have been warned!
Closed captioning for the humor impaired: of course some of that is meant to be humorous -- it is a really, really lousy idea though
You're heading the wrong way. If you want to program in Java then program in Java. If you program in C++ then program as C++ programmers do. Always swim with the current, never against it.
This avoids redundancy for the library writers, but is painful for library users.
I don't agree with this premise at all. And even if I did, it's a huge over-generalization that doesn't apply to every library user. But this is a subjective statement anyway, so I'll ignore it.
Are there C++ alternatives to STL/Boost which offer such containers in a more traditional object-oriented flavour?
...
Containers should have methods that allow one to manipulate on them directly. (For example, calling vector.sort() instead of sort(vector.begin(),vector.end()).
Sure. Just make your own containers that have the standard containers as data members and delegate calls to them and to algorithms as needed via member functions. It's rather trivial to implement:
template<typename T>
class MyVector
{
public:
void sort()
{
std::sort(vec.begin(), vec.end());
}
// ...
private:
std::vector<T> vec;
};
There's nothing in C++ that prevents you from doing something like this, ironically thanks to the multi-paradigm nature of C++ that you seem to not agree with.
You can probably use private
inheritance and using
declarations if you much rather not write out wrapper functions.
STL/Boost make it a pain to derive from their containers and extend them.
That's because you're not supposed to derive from them. The proper way is to use composition, like the code snippet I presented above.