Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

C++intermediatecliAI generated

Custom Dynamic Array Container Library

Build your own version of std::vector in C++: a template container that stores any type in a dynamically growing array, doubles its capacity when full, gives fast access by index, supports iterators so it works with range-based for loops and STL algorithms, and handles copying and moving correctly. Along the way you'll deal with the parts that make containers tricky: constructing and destroying objects in raw memory, keeping things valid when an exception is thrown, and following the rule of five. A full Google Test suite proves it works, including with types that count their constructions and throw on purpose. You'll learn class templates, RAII, placement new, move semantics, iterator design, and exception safety.

Estimate
~11h
Steps
6
Completed by
0
Proposed by
codeseed.app

Templates · Google Test

Project roadmap

  1. 01

    Create the basic container

    ~2h

    Set up a CMake project with GoogleTest (with FetchContent). Write a class template Vector<T> that manages raw memory (allocated with ::operator new, not new T[], so objects are only constructed when added), with size and capacity, push_back (constructing in place with placement new), operator[] and a checked at() that throws std::out_of_range, and a destructor that destroys the elements then frees the memory. Done when: a Vector<std::string> can be filled and read, and a simple test passes.

  2. 02

    Grow the capacity

    ~1.5h

    When full, allocate double the capacity (starting at 1), move the elements into the new memory (with std::move_if_noexcept, so types whose move may throw are copied instead), destroy the old ones, and free the old memory. Add reserve(), shrink_to_fit(), pop_back(), clear() and emplace_back (with perfect forwarding). Done when: tests show capacity grows by doubling, and elements survive growth.

  3. 03

    Add copy and move

    ~2h

    Implement the rule of five: a copy constructor and copy assignment (using copy-and-swap for exception safety), a move constructor and move assignment that steal the other vector's buffer and leave it empty (marked noexcept), and the destructor. Handle self-assignment. Done when: tests show copies are independent, and moved-from vectors are empty but still usable.

  4. 04

    Add iterators

    ~2h

    Add begin(), end(), cbegin() and cend() returning random-access iterators (plain pointers are enough, or write an iterator class with the right iterator category), plus insert and erase at a position. Make sure std::sort, std::find and range-based for loops work with your Vector. Done when: STL algorithms work on your Vector in tests.

  5. 05

    Test thoroughly

    ~2.5h

    Write a Google Test suite with a helper type that counts constructions, copies, moves and destructions: no leaks or double destructions, moves used when growing, exception safety (a type that throws on the Nth copy must leave the vector unchanged), bounds checking, and iterator correctness. Run the tests with AddressSanitizer. Done when: all tests pass with no sanitizer errors.

  6. 06

    Compare with std::vector

    ~1h

    Write a small benchmark comparing push_back, access and iteration speed with std::vector for ints and strings (with std::chrono or Google Benchmark), and explain any differences in README.md. Done when: README.md shows the comparison and explains it.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~11h · 6 steps

Tech stack

TemplatesGoogle Test