The question's pretty self-explanatory really. I know vaguely about vectors in maths, but I don't really see the link to C++ vectors. Thanks!
A vector is simply a sequence of values, all of the same type. This is pretty much in line with the use in mathematics. I guess the mathematical idea that vectors should support some common operations (such as adding, and scaling by a scalar) are not carried over, the important aspect is mainly the structure.
I'd guess it comes from the term row vector. Also, computer scientists love thinking up new names for things...
Also if you make it store integers or floating points it does make an excellent type for storing N dimensional vectors. After all all a vector is, is a list of numbers kept in a specific order.
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.
The name comes from the linear algebra, where vector is matrix with only one column or only one row.
No idea about the real reason, but C++ calling it a vector instead of an array, reduces confusion between the C and C++ structures, although they fulfill the same roles.
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."
Just to say why it probably isn't called array
: Because std::vector
has a dynamic size. An array conceptually is fixed in length. Next C++ Standard by the way has a std::array
template, which is fixed in size and should be preferred over a plain array:
std::array<int, 4> f = { 1, 2, 3, 4 };
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. Now C++0X will compound this mistake by introducing a class 'array' that will behave similar to a mathematical vector.
Alex's lesson: be very careful every time you name something.
So the real question is why is a physics vector (magnitue+direction) called a vector?
Wonders that parametrisation on types does to names..
here a column gets blasted.. (view source for some server-side ASP.NET HTML encoding skills)
or was it a row?
Then again, thinking of it in MIMD or even SSE vector machine context, the name still sounds damn good.