J
Juha Nieminen
Christian Hackl said:It goes against experience because std::vector is used more often than
other containers.
I'm sorry, but I have hard time understanding how "it's more commonly
used" is an argument for std::vector being the correct substitute and
std::deque being the incorrect one. Popularity is not a measurement of
correctness. That's a fallacy.
It goes against common sense because std::deque's
ability of growing in both directions is obviously a special requirement.
The ability of std::vector to grow at all is against "common sense"
because basic arrays can't grow. std::vector adds the capability of
growing the array by adding to the end in constant time, which is
something you can't do out-of-the-box with basic arrays. So that's
something where std::vector already differs from basic arrays.
std::deque additionally gives the possiblity of adding elements to
the beginning in constant time. Why does that make it a "non-array"?
Why is adding to the end ok, but adding to the beginning not?
So no, std::vector doesn't make any more sense than std::deque does.
And of course, you cannot pass a std::deque to a C function usig &d[0]
and d.size(), while you can do this with a std::vector, which only
strengthens the point that vectors are designed as the array replacement
of C++.
I thought you wanted to distance the beginner from such low-level stuff
and teach higher-level constructs instead.
A std::deque has slower element access. How is element access less
important than inserting elements at the beginning?
So using premature optimization as an argument is ok when it makes
std::vector look good, but it's bad when it's used to make basic arrays
look good? You yourself argued that the efficiency arguments for basic
arrays are just "premature optimization". Now you are arguing in favor
of std::vector using the same kind of argument.
Of course, it won't make any difference for a beginner, but again: why
expose him to a special container type instead of simply starting with
the most general and most used, which is std::vector?
What would be wrong in teaching different alternatives and explain their
strengths and weaknesses, and where they are useful and where something
else would be better? A person can learn such things relatively easily,
and claiming otherwise is a bit patronizing, IMO.