There are two kinds of arrays in C -- fixed-length arrays and variable-length arrays. std::vector<> most closely models
a variable-length array. boost::array<> implements a fixed-length array.
This is important because many people try to compare the execution time of an algorithm using std::vector<> and then
a fixed-length array. This is comparing apples to oranges, unless care is taken to ensure that std::vector<> behaves like
a fixed-length array. (The way to do that is to call std::vector<>.reserve() to "fix" the size of the array before inserting
elements.
So, ahmed93, you can get by exclusively with std::vector<> now, however I would also encourage you to look at
boost::array<>. The advantage of boost::array<> for fixed-length arrays over std::vector<> is that you can
initialize a boost::array<> as if it were a C array:
|
boost::array< int, 5 > a = { { 1, 2, 3, 4, 5 } }; // Extra set of braces needed by some compilers
|
whereas you need to write a little more code to initialize a std::vector<>:
1 2 3 4
|
std::vector<int> v;
v.reserve( 5 );
for( int i = 1; i < 6; ++i )
v.push_back( i );
|
The boost::array<> line is much easier to understand than the second because the boost::array
example is simply a declaration whereas the std::vector<> example requires you to figure out
the algorithm (albeit easy).