Git Product home page Git Product logo

cpp-implementing-iterator-from-scratch's Introduction

Implementing Forward Iterator From Scratch in a Custom Class in C++

Description:

This repository contains an implementation of a fixed-size array with a custom iterator in C++. The FixedSizeArray class is a simple generic data structure that provides a fixed-size container for storing elements of any type.

The real strength of this implementation lies in its custom iterator, which adheres to the forward iterator concept. The iterator is defined as a nested struct inside the FixedSizeArray class and provides functionalities for iterating over the elements of the array.

The iterator includes implementations of:

Pre-increment and post-increment operations: These are used to advance the iterator through the array.

Dereferencing operations (operator* and operator->): These are used to access the value currently pointed at by the iterator.

Equality and inequality comparison operations: These are used to compare two iterators to see if they point to the same location.

In addition, the FixedSizeArray class itself provides methods to get iterators pointing to the start and end of the array (the begin and end methods, respectively), to access elements at specific indexes (using the overloaded operator[]), and to get the total capacity of the array (using the size method).

The class also takes care of allocating and deallocating the memory for the array, throwing exceptions if there are any issues (such as running out of memory or trying to access an element at an invalid index).

Please feel free to browse the code, use it in your own projects, or suggest improvements!

This code is intended as a learning resource for those interested in understanding how to implement their own iterators and generic data structures in C++. Feedback and contributions are welcome.

cpp-implementing-iterator-from-scratch's People

Contributors

samiramhosseini avatar

Watchers

 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.