Code Snippets

Below are code snippets taken from a small project where I create a random person with a job using templates, inheritance and smart pointers. This pattern allows me to iterate on each person without needing to worry about the underlying implementation while also preserving the ability to extend the job pool.

villager_generator_1
villager-generator-5
villager generator 2
villager_generator_2
villager_generator_3
villager_generator_1 villager-generator-5 villager generator 2 villager_generator_2 villager_generator_3


In this snippet I create a village with people in it and simulate them using the previous snippets setup and using the RVO rule i make sure to avoid triggering atomic increments in the smart pointers.

village-1
village-2
village-1 village-2

Below is a container class that translates a single vector to a fixed size 2D grid.

Header file
Inline file
Header file Inline file

This grid class is meant to be representing a 2D world and have therefore not specified a iterator, which would also lead to confusion of the container in itself. Instead if all the elements need to be iterated upon i provided the option to do so via lambda callback implementation as seen below

image
image