Fading Coder

One Final Commit for the Last Sprint

C++ Stack and Queue as Container Adapters

Container Adapters The adapter pattern is a widely used, categorized design pattern for reusable code that converts one class's interface into a different interface expected by client code. In the C++ STL standard library, stack and queue can store elements just like native containers, but they are...

C++ Core Programming: Memory Management, References and OOP Fundamentals

Memory Layout in C++ Code Area: Stores binary code of functions managed by the operating system Global Area: Holds global variables, static variables, and constents Stack Area: Automatically allocated and deallocated by compiler for function parameters and local variables Heap Area: Manually managed...

Implementing the Singleton Design Pattern in C++

The Singleton pattern is a creational design pattern intended to ensure that a class has exactly one instance while providing a global point of access to that instance. This pattern is particularly valuable when coordinating actions across a system or managing shared resources where multiple instanc...

Implementing ROS Service Communication in C++

ROS supports three primary communication mechanisms: topics, services, and the parameter server. This article focuses on implementing service-based communication using C++. Service communication follows a request-response model where a client sends a request to a server and waits for a reply. The ke...

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...