Author image

C++ Vector Implementation

A C++14/17 ready allocator_traits aware Vector similar to std::vector . I made it to familiarize myself with the internals of containers in the C++ standard library.


  • fix some obscure Iterator problems (perhaps add begin() and end() to it) - we'll see
  • shrinkToFit(#) : if current storage is larger than # Bytes, it shrinks it to # bytes
  • halfSize() shrink

I won't attempt to create a full tutorial on this, because LokiAstari has covered this in excruciating detail already - in a level I can't hope to match (check out acknowledgements section below). If you're overwhelmed with templated code check out this tutorial:

Author image

Neural Network Demo

Following a great tutorial from YouTube by Dave Miller : “Neural Net implementation in C++”. Nothing more to be said other than watch his tutorial. It was the best intro on Neural Networks I had ever seen. I present it here with source code in case anybody wants to save a bit of time or double check with my version. And you can let me know of any errors or improvements. Thank you.

I used Windows 8.1 x86_64, Visual Studio 2017.


Github repository link.


All credits go to Dave Miller's excellent introduction to Neural Networks. I simply implemented his example as I was following along.

Author image

Observer Design Pattern

Observer is an important behavioral software design pattern, that is being extensively utilized in almost every single self-respecting codebase as a means to efficiently communicate between objects in an event-based function. It wouldn't be an understatement to say it is the foundation of event based programming.

In fact, underlying the ubiquitous in network programming, “Model View Controller” (MVC) design pattern, is the observer pattern.

Observers are used in every single game engine - they're known there mostly as “Event dispatchers”.

Alternative terminology for this pattern includes the following: - Subscribe-Publish - Listener-Publisher - Delegate-Model - Sink-Source, where the Subject is the source of events and the Observers are sinks of events

Author image

Command Design Pattern

Encapsulate a request as an object, thereby letting users parameterize clients with different requests, queue or log requests, and support undoable operations.

You are not encapsulating the object that sends the request, or the object that receives the request, but encapsulate the actual request as an object with state. Of course, some commands can be stateless chunks of pure behavior (no data members).
The command pattern also makes undoable/redoable operations a piece of cake (they're considerably harder to implement without it). Derived Commands can leverage CRTP to be statically bound.

Note that the code executing the commands is responsible for freeing their memory.


  • define a base abstract class Command that represents a triggerable command for the program
  • create subclasses...

Author image

Curiously Recurring Template Pattern

Curiously Recurring Template Pattern, or CRTP for short, is essentially a C++ only idiom. It is also known as Static Polymorphism or Simulated polymorphism.

Requirements for dynamic polymorphism:

  1. Is-a relationship between base and derived class.
  2. Base class defines a 'generic' algorithm that is used by derived class.
  3. The 'generic' algorithm is customized by the derived class.

Requirements for static polymorphism:

  1. 'Is-a' relationship between base and derived class.
  2. Base class defines a 'generic' algorithm that is used by derived class.
  3. The 'generic' algorithm is customized by the derived class.
  4. This method is pure virtual. The derived method implements it.

However, to avoid run time costs when the specialized method is invariant of the one in the base method...

Author image

Strategy Design Pattern


Define a family of algorithms, encapsulate each one and make them interchangeable.

It is also known as 'policy' pattern. Instead of implementing a single algorithm directly, code receives run-time instructions as to which in a family of related algorithms to use.

Strategy vs State:

In contrast to the State pattern which favors inheritance, Strategy favors composition. Both of them allow you to change object properties @ runtime. with State the object literally changes its class at runtime (requires inheritance). On the other hand, with Strategy the object itself doesn't change, some of its behaviors though can change (requires composition).

Strategy is a flexible pattern, as it makes combining, adding, changing behaviors of an object easy as pie.


  • create your...

Author image

State Design Pattern

This is a demonstration of the State Design Pattern in C++ with a groovy example that will stick in your memory.

The state pattern allows an object to alter its behavior at runtime when its internal state changes. There is a base State class and various concrete derived state classes. The state class hierarchy makes up a state machine and the desired object can be at any one single state at a point in time. State is an software behavioral design pattern, alternative to the Strategy pattern.

Author image

Visitor Design Pattern

I have to agree that this design pattern confused me for a longer time than I'd want to admit. But fear not! Confusion is now over! The time of Understanding is at hand! This cancer curing project will solve all mysteries for the Visitor pattern.

Definition: Represent an operation to be performed on elements of an object structure. Visitor lets you define a new operation without changing (recompiling) the classes of the elements on which it operates.

Understood? No? I didn't think so; keep on reading. I never understood those definitions either. They only make sense After you delve deep into it and start making sense of it on your terms!

A Visitor is a behavioral software design pattern and a good design decision if you want to perform similar kinds of operations on objects of different types that are grouped inside a...

Author image

Composite Design Pattern

Join me in our quest to decipher the obscure Composite software design Pattern hieroglyphics.

Definition: Compose objects into tree structures to represent part-whole hierarchies.

The Composite pattern is a structural pattern which enables us to iterate over objects, or collection of those objects in a uniform manner, without having to typecheck or differentiate between the concrete objects and their collections. All those objects share a common interface, an abstract base class.

The whole point of the Composite pattern is that the Composite can be treated atomically as if it was a leaf object, without needing to know that there are many objects inside. Leaf objects perform a request directly, and Composite objects forward the request to their child components recursively downwards the tree...

Author image

Proxy Design Pattern

What is a proxy? Dictionary says “The authority to represent someone else”. hmmm… Ponder on that a bit and let's see how the “Name and Conquer” of Proxy applies to software design patterns.

The definition of the Proxy pattern goes like this:

Provides a surrogate or placeholder for another object in order to control access to it.

Let's get the obvious stuff out of the way:

  1. A proxy certainly provides another level of indirection to another “target” object that we basically want to access

That's it. I have nothing else that seems obvious from the definition alone. But after further investigation and coding I realize that a Proxy object is indeed useful when we want to lazy-instantiate an object, or when we want to hide the implementation details of the object. For whatever reason, but this often comes up in software, we represent a back-end highly complicated object with a more...

1 2 3 ... 7