Re: Why C++ is vastly superior to C
Ian Collins <ian-news@hotmail.com> wrote:
I normally just use RAII as the reason. Everything else else can be
kludged in C, but not RAII.
It's quite difficult to kludge any kind of generic data containers in C
(which is probably the reason why the standard C library does not offer
any such containers). You could achieve something similar with preprocessor
macros, but it would be quite limited, and definitely less safe (in big
part because of the lack of RAII, constructors, destructors, etc).
You could perhaps make some more or less generic containers for basic
types and structs which only contain basic types (but not pointers) with
preprocessor macros, but immediately when you need more resource management
than that (such as a struct that as pointers pointing to dynamically
allocated memory or other such resources) it becomes complicated. For that
same reason it's complicated to make the containers nested. (Assigning
a container object would not be the same as assigning a basic type.)
It's so much simpler with C++ templates. Just write any amount of
nested containers you want, no problem.
std::deque<std::list<std::vector<std::set<std::string> > > > container;