A Small Trick That Turns O(n) Vector Erase Into O(1)

A Small Trick That Turns O(n) Vector Erase Into O(1) In day-to-day C++ work, std::vector is the default container. It is fast, cache-friendly, and good enough for almost everything. Except for one thing: removing elements from the middle. That operation is always O(n) because the vector has to shift all subsequent elements to fill the gap. Every time I erase from the middle, I feel the same irritation: a tiny change, half of the array shuffled. ...

December 3, 2025

Collected Notes

A collection of short notes and links. Algorithms & Math Papers to read - papers we love 2014-09-02T07:51:12+00:00 Repo for good papers to read. https://github.com/papers-we-love What was the last paper within the realm of computing you read and loved? What did it inspire you to build or tinker with? Come share the ideas in an awesome academic/research paper with fellow engineers, programmers, and paper-readers. Lead a session and show off code that you wrote that implements these ideas or just give us the lowdown about the paper (because of HARD MATH!). ...

December 3, 2025

EnumArray - A Practical Mapping Trick Without Paying Hash-Map Tax

EnumArray - A Practical Mapping Trick Without Paying Hash-Map Tax Whenever I work with configuration systems, metadata tables, or low-level processing pipelines, I repeatedly run into the same pattern: I have an enum, and I want a dictionary that maps each enumerator to some piece of data. The naïve solution is universal and convenient: 1 2 3 4 5 6 std::unordered_map<Unit, const char*> unitNames { { Unit::Grams, "g" }, { Unit::Meters, "m" }, { Unit::Liters, "l" }, { Unit::Items, "pcs" }, }; It works. It is readable. It is also wasteful. ...

December 1, 2025

Troubleshooting GoogleTest Linking Issues in Mixed C++/C# Projects

First Part - Compile the code Integrating GoogleTest with mixed C++ and managed C++/CLR projects can lead to unique challenges, especially regarding test detection in Visual Studio’s Test Explorer and linker errors. Recently, I faced precisely these issues. Diagnosing the Issue Tests Not Appearing in Test Explorer Initially, my native C++ GoogleTest unit tests were visible in Visual Studio’s Test Explorer. However, enabling C++/CLR caused them to disappear. It became clear that Visual Studio’s test adapter struggled to detect GoogleTest tests after incorporating managed code. ...

March 20, 2025

Structured Exception Handling (SEH)

Structured Exception Handling (SEH) is a Microsoft-specific extension to C and C++ designed to handle exceptional code situations, particularly hardware faults, in Windows operating systems14. It serves as a generalized error handling mechanism supported by the Windows OS and is part of the Windows Application Binary Interface (ABI)3. Key features of SEH include: Hardware fault handling: SEH can catch CPU exceptions such as access violations, illegal instructions, and divide-by-zero errors4. OS-level mechanism: Unlike C++ exception handling, SEH is an operating system feature not tied to any specific programming language3. Per-thread basis: SEH works on a per-thread basis, with each thread containing its own Structured Exception Handling mechanism3. Untyped exceptions: SEH exceptions are not typed but share a common data structure containing an exception code and additional information about the fault4. First-chance handling: SEH allows for logging or handling exceptions before stack unwinding destroys local variables4. Finally mechanism: SEH includes a “finally” mechanism not present in standard C++ exceptions5. While SEH is supported by Windows and Microsoft C++, it is generally recommended to use ISO-standard C++ exception handling for better portability and flexibility1. However, SEH may still be necessary for maintaining existing code or for specific types of programs that require low-level exception handling capabilities14. ...