Month: October 2024

C++ Iterating Scoped Enumerations

requirements Map non-integer values to scoped enum literals Use switch statements to catch missing enum cases in value lookup ( -Wswitch-enum allows default case) Use class template to iterate the enum mapped values Limitations Iterator needs to be given begin/end points, so you have to sync this end limit with the last entry in EncapsulatedEnum::Key…

Read the full article

C++ Singleton Enumerated Map

Features Maps enum type literals to strings (or any type) Singleton pattern ensure only single instance Encapsulation checks if key exists to prevent lookup errors/exceptions. C++17 version --std=c++17 -Wall -Wextra…

Read the full article

C++ Serialize Function

Convert an unsigned integer to a vector of bytes (char) The use of function template and argument deduction means you don't need to specialize the function template, you just call it with the unsigned int type and the compiler will deduce the width of the type. The function uses sizeof() to calculate the bitwise shift…

Read the full article