The C++ Standard Template Library (STL) provides a framework for processing algorithms on different kind of containers. However, ordinary arrays don’t provide the interface of STL containers (although, they provide the iterator interface of STL containers). As replacement for ordinary arrays, the STL provides class std::vector. However, std::vector<> provides the semantics of dynamic arrays. It manages data to be able to change the number of elements. This results in some overhead in case only arrays with static size are needed.
New new C++ provides a new class called array which is static in usage but able use a standard C++ container. It also provides access to the underlying data. Thus it’s possible to use as raw array pointers. See the sample snippet below to too see how to use array class. A better documentation can be found at boost::array page.
[sourcecode language='cpp']
// using array class
void FooTR1Array()
{
std::tr1::array
using namespace std;
cout << "Contents of array " < // array swapping - both arrays should have same properties and size cout << "Contents of array 2" < // swap array cout << endl<< "Contents of array 1 after swapping with array 2" < cout << endl<< "Contents of array 2 after swapping with array 1" <
ostream_iterator
cout << "Size of array - " << arr.size() <
std::tr1::array
ostream_iterator
arr.swap( arrNew );
ostream_iterator
ostream_iterator
}
[/sourcecode]
2 Comments
Hey Sharath, that was interesting. Its great to see the C++ standard incorporating ideas from the Boost library. The future looks bright!
Most of the proposed changes for TR1 has taken from boost library. The ISO committee members are also present in the top of boost.org and also, boost license is totally flexible and better than GNU-GPL. It’s really matters when it’s used with commercial products.