/ft_containers

Implementation of C++ containers

Primary LanguageC++GNU General Public License v3.0GPL-3.0

๐Ÿ“˜ ft_containers

This project was written as part of 42 curriculum.

The main goal is to implement the following containers from the C++ standard library:

We had to follow the specifications from the C++98 standard.

๐Ÿ’ก See the subject for more details.

๐Ÿ“ฆ Prerequisites

โš ๏ธ These dependencies are only required to run the tests!

  • Clang or GCC
    • ๐Ÿ’ก If you want to use GCC, you will have to change the CXX variable in the Makefile to g++.
  • Cpputest

๐Ÿ“– Usage

The source code is located in the inc directory as a header-only library. All classes and functions are in the ft namespace.

The test suite is located in the test directory. In order to compare the results, a variable named NAMESPACE is defined in the Makefile, to compile tests with the standard library using NAMESPACE=std or with ft_containers using NAMESPACE=ft.

๐Ÿ”ฌ Run tests

make run

๐Ÿงช Example with ft::vector

#include <iostream>
#include "vector.hpp"

int main() {
	// Declare a vector of int
	ft::vector<int> v;

	// Reserve memory for 12 elements
	v.reserve(12);

	// Add 10 elements with value from 0 to 9
	for (int i = 0; i < 10; ++i)
		v.push_back(i);

	// Insert 2 elements with value 42 between the 5th and 6th element
	v.insert(v.begin() + 5, 2, 42);

	// Print all elements
	for (ft::vector<int>::iterator it = v.begin(); it != v.end(); ++it)
		std::cout << ' ' << *it;
	std::cout << std::endl;
}

โš–๏ธ License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.