Why is a C++ Vector called a Vector?
An excerpt from The C++ Programming Language by Bjarne Stroustrup:
"One could argue that valarray should have been called vector because it is a traditional mathematical vector and that vector should have been called array. However, this is not the way the terminology evolved."
Mathematical definition of a vector is a member of the set S
n
, which is an ordered sequence of values in a specific set (S
). This is what a C++ vector
stores.
It's called a vector because Alex Stepanov, the designer of the Standard Template Library, was looking for a name to distinguish it from built-in arrays. He admits now that he made a mistake, because mathematics already uses the term 'vector' for a fixed-length sequence of numbers. C++11 compounds this mistake by introducing a class 'array' that behaves similarly to a mathematical vector.
Alex's lesson: be very careful every time you name something.