Giter Club home page Giter Club logo

ft_containers's Introduction

ft_containers

Recreate C++ containers (vector, map, stack) using C++98 (which means, many stuff are deprecated/deleted by now in the current C++)

README: WIP

Steps I took

  1. Copy paste the generic template from vector reference template < class T, class Alloc = allocator<T> > class vector; // generic template (https://www.cplusplus.com/reference/vector/vector/) We will essentially implement one by one the members attributes/functions etc. This of this as your list of TODOs.

  2. What the heck is an allocator: In a nutshell: using new, delete is very handy because it automates the construction process of the memory. With Allocator, the 2 process are seperated. You have to allocate memory (using allocate), and then construct it (using construct) which allows to assign a value to the object you allocated.

All STL container use Allocator class for memory allocation. The allocator will be the object holding the data for our STLs: allocator_type _alloc; the main attribute to hold the data structure (beware that allocator_type is just an typedef of Alloc, which in turn, is the class class Alloc = std::allocator<T>).

Some example here: https://www.geeksforgeeks.org/stdallocator-in-cpp-with-examples/ To check functions/return types etc: https://en.cppreference.com/w/cpp/named_req/Allocator

  1. Implement member functions: All function templates are given, so it's quite straitforward. Just be careful with the order in which you implement the functions, because some of them depend on other member functions. (e.g. resize)

Reverse_iterator

  • First need to finish the base_iterator (random_iterator in our implementation).
  • Using the base_iterator, you can instantiate the reverse_iterator
  • All the TODOs of reverse_iterator [https://www.cplusplus.com/reference/iterator/reverse_iterator]
  • Notes:
    • construtor of rev_iter have an offset of -1, when compared with base_iterator.This means you have to shift the iterator by 1 in the constructor.
    • When calling base, you return the base_iterator. More importantly, you return the iterator + 1 to take into account the offset.

Reference

ft_containers's People

Contributors

chrisduvivier avatar nathancolin27 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.