Fading Coder

One Final Commit for the Last Sprint

Advanced C++: Currying and std::bind

Advanced C++: Currying and std::bind
1. Currying Process 1.1. Introduction of operator() Consider a function that returns a different result on each call. For example, two calls should yield different values. 1.1.1. Simple Approach Using a global (or static) variable that is modified and returned each time. #include <iostream> in...

Implementing Linked List Operations: Reversal, Pairwise Swapping, and Nth Node Removal

Implementing Linked List Operations: Reversal, Pairwise Swapping, and Nth Node Removal
LeetCode Problem 206: Reverse Linked List Problem Description: Solution: Using a two-pointer approach with previous and current pointers, iteratively modify pointer directions. Pay atttention to the loop termination condition; return the previous pointer as the new head node. /** * Definition for si...

Understanding C++ Virtual Tables and VTable Hooking

Exploring Virtual Tables (VTables) To understand the lifecycle and structure of virtual tables in C++, let's start with a set of test classes involving virtual functions and multiple inheritance. Virtual Function Classes #include <cstdio> class SampleClass { public: int internalValue; virtual...

Best Practices for Class Member Function Design

A common anti-pattern in class interface design can be seen in the following tree node implementation: class TreeNode { public: void updateParentPtr(TreeNode* newParent) { parent = newParent; } void changeParent(TreeNode* newParent) { // Problematic interface updateParentPtr(newParent); newParent-&g...

Parsing and Evaluating Nested LDAP-Style Filter Expressions Efficiently

Problem Overview Each user is identified by a unique positive integer DN. Users possess a set of attributes, each identified by a positive integer ID and associated with exactly one positive integer value. Attribute IDs are sparse — not all numbers between 1 and the maximum ID necessarily appear for...

Filtering Vowels and Formatting Consonants in Strings

The task requires processing an input string to remove all vowel characters (A, O, Y, E, U, I in both upper and lower case) and then format the remaining consonant characters. The formatting involves prefixing each consonant with a period ('.') and converting the character to its lowercase form. The...

Advanced C++ Template Techniques

Non-Type Template Parameters Template parameters are categorized into type parameters and non-type parameters. A type parameter is preceded by class or typename in the template list, while a non-type parameter is a compile-time constant that functions as a parameter for class or function templates a...

Post-Mortem: Segment Fault from Unchecked Vector Iterator Erasure

class FdMonitor::Internal { public: void unregister(int fd); void registerFd(int fd); std::vector<int> awaitEvents(); private: std::vector<int> watchList_; std::mutex listMutex_; std::pair<int, int> signalPipe_; }; The fault manifested in the unregister() routine: void FdMonitor::I...

C++ Special Member Functions: Object Lifecycle Management

In C++, a class declaration appearing empty to the programmer actually contains implicit machinery. The compiler synthesizes six special member functions to manage object lifecycle, enabling consistent initialization, copying, and cleanup behaviors without explicit boilerplate. Constructors Object i...

Essential Sorting Algorithms Implemented in C++

Bubble Sort Bubble sort operates by repeatedly stepping through the list, comparing adjacent elements, and swapping them if they are in the wrong order. This process causes the largest unsorted elements to migrate to their correct positions at the end of the array. While straightforward, its quadrat...