This week we studied a number of STL algorithms, and through them enforced the better understanding of different types of iterators: Input Iterator (II), Output Iterator (OI), Forward Iterator (FI), Bidirectional Iterator (BI), and Random access Iterator (RI). Having studied different algorithms such as: Find, MinElement, Transform, Remove, Reverse, Equal, and Accumulate helped in understanding the conventional concept behind different categories of iterators.
We studied the Vector class, which efficiently develops a heap allocated array of objects. The way Vector accomplishes this is by calling the copy constructor of the underlying object class, in contrast to calling the default constructor and the assignment operator as done by stack allocated array. vector uses allocator (memory) to first allocate memory space for the array to be constructed. The allocated memory space is in raw form. Thereafter, it calls the uninitialized_copy/uninitialized_fill which then calls the construct() method; consequently the copy constructor of the underlying value_type. The construct() method calls the placement version of new:
new (p) value_type(v);
A reverse process is pursued while destructing the vector object. It calls, the destory() which calls the destructor for the underlying datatype. It finally deallocates the memory that it assigned for the vector object.
In the last class we studied about iterator_traits, and how meta information inside the Iterator class can be used to infer the return datatype, which in general is not passed as a function template argument.
As for the project, we have been developing an Array class that would implement stack allocated array object and related operations, and methods. Initially we have been getting segfault when trying to call the non-const version of a method from the const method. We overcome the problem by using const_cast casting.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment