|
Capycore Engine
0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
|
#include <simple_storage.h>
The storage is working with something called an invariant. An invariant is something we can see as a tagged union of sorts but a bit different. An invariant is essentially a type that says "I can be any of the following types". We know this from discriminated unions used in F# or free unions from TypeScript.
The overloaded struct is a trick that basically boils down to the following: "Be a structure that overloads the call type for anything that is inside of you".
In our case, its type may as well just be: struct overloaded { int operator()(int); bool operator()(bool); std::string operator()(std::string); }
We just use templates to generate this type for us based on the shape of the invariant passed, that is all. In C++ 26 we have this type included in the base library. We have to write it manually here.